DS18B20 values not updating [frozen] on ESP32 WROOM

The 2 temperature calls is the 1st thing void loop() is requested to do.
Not that it matters. I checked the values with serial monitor and they matched
the unchanging values on the webpage display. Hit the reset button and after it reinitializes a new set of values will display. But no updates. I have two other ESP-32 WROOM units online and updating the same type sensors, with the same code setup.

#include <OneWireNg.h>
 #include <DallasTemperature.h>

#define SENSOR_PIN  14  // ESP32 pin GPIO14

int tmp_adj_1 = 0;  // sensor 1 calibration adjustment
int tmp_adj_2 = 0;

float sup_manifold_tmp;  //    Dallas DS18B20 temp sensor
float sup_tmp;
float sup_manifold_temp;
float ret_manifold_tmp;        //    Dallas DS18B20 temp sensor
float ret_tmp;

void setup() {
  delay(3000);                       // allow voltage stabilization on startup
  pinMode(ONBOARD_LED, OUTPUT);      //  Blink LED function
  pinMode(Blr_Disable_Rly, OUTPUT);  //  Boiler lockout relay
  pinMode(Blr_Enable_Rly, OUTPUT);   //  Boiler enable relay
  pinMode(Zone_Pump_1, INPUT);       //  Zone Pump "Call For Heat" Input
  pinMode(Zone_Pump_2, INPUT);
  pinMode(Zone_Pump_3, INPUT);
  pinMode(Season_Override, INPUT);  // switch override of heating system at end of winter
  pinMode(System_Reset, INPUT);
  pinMode(Boiler_Lockout_LED, OUTPUT);

  digitalWrite(Blr_Disable_Rly, LOW);  //  Initialize boiler lockout relay OFF
  digitalWrite(Blr_Enable_Rly, LOW);   //  Initialize boiler enable relay OFF
  digitalWrite(Boiler_Lockout_LED, LOW);

  Serial.begin(115200);

  while (WiFi.status() != WL_CONNECTED) {
    Initial_Connect_Attempts++;
    Serial.println("Attempting to Connect To Local Network:   ");
    Serial.println(wifissid);
    WiFi.begin(wifissid, wifipass);
    delay(4000);
    if (Initial_Connect_Attempts == 5) {
      connectToWiFi();
    }
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
  Serial.println("Attempting to connect to local WPA network...");

  server.begin();
  // you're connected now, so print out the status:
  Serial.print("WiFi Status:  ");
  Serial.println(WiFi.status());
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

  DS18B20.begin();  // initialize the DS18B20 space sensor
  // DS18B20.setResolution(to be defined, 8);   finish settingh up temps thru direct address call

  DS18B20.requestTemperatures();
  DS18B20.setWaitForConversion(false);  // this speeds up processor throughput/execution time
}

void loop() {
 
  sup_manifold_tmp = DS18B20.getTempFByIndex(0);  
  sup_tmp = sup_manifold_tmp + tmp_adj_1;  // sensor calibration
  ret_manifold_tmp = DS18B20.getTempFByIndex(1);
  ret_tmp = ret_manifold_tmp + tmp_adj_2;

You are missing code in your post.

Suggest you only read the temperature sensors at a 2 second or longer period.

  //************************************************              T I M E R  read temperatures
  //is it time to read the temperature sensors (every 2 seconds)?
  if (millis() - readTempTime >= readTempInterval)
  {
    //restart this TIMER
    readTempTime = millis();

    //**********************************
    //this code needs to run so the WIFI Client gets the current temperatures
    temperatureFreezerC = sensors.getTempC(freezerAddress);
    temperatureFreezerF = sensors.getTempF(freezerAddress);

    temperatureOutsideC = sensors.getTempC(outsideAddress);
    temperatureOutsideF = sensors.getTempF(outsideAddress);

    //start a new conversion request
    sensors.setWaitForConversion(false);  //this could be done once back in setup()
    sensors.requestTemperatures();
    sensors.setWaitForConversion(true);  //this could be commented out

  }  //END of   readTemp TIMER

I did leave out the client.print and serial.print bits.
The serial monitor shows the same "stuck" values as the webpage display with no update in the readings.
I guess I can start from a simple sketch and build back on it once the sensors start updating again. My other ESPs work fine with the DS18B20s.

We have to do that some times.


Let’s ignore that “fact” right now.


The DS18B20 needs just under 2 seconds to respond, hence, disable waiting and only sample the sensor at a 2 or more second period.

Use this:

    sensors.setWaitForConversion(false);  //this could be done once back in setup()
    sensors.requestTemperatures();  //do this after temperatures have been read

Solved!
The line of code below has to be inside the void loop() NOT the void setup(). ...sheesh....

DS18B20.requestTemperatures();
 //is it time to read the temperature sensors (every 2 seconds)?
  if (millis() - readTempTime >= readTempInterval)
  {
    //restart this TIMER
    readTempTime = millis();

Larry,

I think I am going to implement your millis based temp read function. Hopefully this will introduce some added stability to my temperature reading code. :+1:

I overlookedthis comment earlier. This is a huge realization for me.
I appreciate your suggestion as it makes absolute sense and will probably remove some of my issues. :+1: :+1: :+1:

Per the datasheet, the maximum conversion time (at the max 12-bit resolution) is 750ms. See My Post #88 in this Thread for an example of non-blocking DS18B20 code.

That #88 post and the subsequent ones that follow are very helpful in explaining the process with the wait conversion (false) function and sensors.get. You should be applauded for your patience in dealing with those of us, including myself, who are sometimes a little slow to grasp explanations of concepts. And the forum staff and members do a good job of keeping us properly informed about coding these little processors. :+1: :+1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.