Skip to content

Commit

Permalink
Fix internal temperature reading on ESP32 (#1391)
Browse files Browse the repository at this point in the history
The previous macro used SENS_SAR_MEAS_WAIT2_REG to identify if we have the reading capability was not working, so replacing it by a fresh one NO_INT_TEMP_READING, defined as a negation due to the fact that most of the ESP32 supports internal temperature reading.
  • Loading branch information
1technophile authored Jan 13, 2023
1 parent ad97e9a commit 76b5e92
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ CRGB leds[FASTLED_IND_NUM_LEDS];
//# define TRIGGER_GPIO 14 // pin D5 as full reset button (long press >10s)
#elif ESP32
//# define TRIGGER_GPIO 0 // boot button as full reset button (long press >10s)
//# define NO_INT_TEMP_READING true //Define if we don't want internal temperature reading for the ESP32
#endif

// VCC ------------D|-----------/\/\/\/\ ----------------- Arduino PIN
Expand Down
2 changes: 1 addition & 1 deletion main/ZactuatorONOFF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void MQTTtoONOFF(char* topicOri, char* datacallback) {
//Check regularly temperature of the ESP32 board and switch OFF the relay if temperature is more than MAX_TEMP_ACTUATOR
# ifdef MAX_TEMP_ACTUATOR
void OverHeatingRelayOFF() {
# if defined(ESP32) && defined(SENS_SAR_MEAS_WAIT2_REG) // This macro is necessary to retrieve temperature and not present with S3 and C3 environment
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
if (millis() > (timeinttemp + TimeBetweenReadingIntTemp)) {
float internalTempc = intTemperatureRead();
Log.trace(F("Internal temperature of the ESP32 %F" CR), internalTempc);
Expand Down
2 changes: 1 addition & 1 deletion main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void pubMqttDiscovery() {
);
# endif
# endif
# ifdef ESP32
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
createDiscovery("sensor", //set Type
subjectSYStoMQTT, "SYS: Internal temperature", (char*)getUniqueId("tempc", "").c_str(), //set state_topic,name,uniqueId
"", "temperature", "{{ value_json.tempc }}", //set availability_topic,device_class,value_template,
Expand Down
7 changes: 3 additions & 4 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ static String ota_server_cert = "";
# include <nvs_flash.h>

bool ProcessLock = false; // Process lock when we want to use a critical function like OTA for example

# if defined(SENS_SAR_MEAS_WAIT2_REG)
# if !defined(NO_INT_TEMP_READING)
// ESP32 internal temperature reading
# include <stdio.h>

Expand Down Expand Up @@ -1651,7 +1650,7 @@ unsigned long uptime() {
/**
* Calculate internal ESP32 temperature
*/
#if defined(ESP32) && defined(SENS_SAR_MEAS_WAIT2_REG)
#if defined(ESP32) && !defined(NO_INT_TEMP_READING)
float intTemperatureRead() {
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S);
SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S);
Expand Down Expand Up @@ -1681,7 +1680,7 @@ void stateMeasures() {
SYSdata["mqttport"] = mqtt_port;
SYSdata["mqttsecure"] = mqtt_secure;
# ifdef ESP32
# ifdef SENS_SAR_MEAS_WAIT2_REG // This macro is necessary to retrieve temperature and not present with S3 and C3 environment
# ifndef NO_INT_TEMP_READING
SYSdata["tempc"] = intTemperatureRead();
# endif
SYSdata["freestack"] = uxTaskGetStackHighWaterMark(NULL);
Expand Down
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ build_flags =
'-DFASTLED_IND_TYPE=NEOPIXEL'
'-DFASTLED_IND_NUM_LEDS=1'
'-DRGB_INDICATORS=true'
'-DNO_INT_TEMP_READING=true' ; Internal temperature reading not building on ESP32 C3 or S3
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'

[env:esp32c3-dev-m1-ble]
Expand All @@ -1531,6 +1532,7 @@ build_flags =
'-DFASTLED_IND_TYPE=NEOPIXEL'
'-DFASTLED_IND_NUM_LEDS=1'
'-DRGB_INDICATORS=true'
'-DNO_INT_TEMP_READING=true' ; Internal temperature reading not building on ESP32 C3 or S3
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'

[env:thingpulse-espgateway]
Expand Down

0 comments on commit 76b5e92

Please sign in to comment.