1

Where is the problem? Watchdog reset triggers every time. I am somewhat new to this type of project. Couldn't quite find the solution anywhere. Somewhere I found out that breaking down the delay values might help. But that didn't work in my case.

#include <DHT.h>  // Including library for dht 
#include <ESP8266WiFi.h>
 
String apiKey = "******";     //  Enter your Write API key from ThingSpeak
 
const char *ssid =  "*********";     // replace with your wifi ssid and wpa2 key
const char *pass =  "*************";
const char* server = "api.thingspeak.com";

Used pin 7 as input for DHT22 sensor

#define DHTPIN 7          //pin where the dht22 is connected
 
DHT dht(DHTPIN, DHT22);
 
WiFiClient client;
 
void setup() 
{
       Serial.begin(115200);
       delay(10);
       dht.begin();
 
       Serial.println("Connecting to ");
       Serial.println(ssid);
 
 
       WiFi.begin(ssid, pass);

Is this command a problem? I am confused

      while (WiFi.status() != WL_CONNECTED) 
     {
            delay(50);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
 
}
 
void loop() 
{
  
      float h = dht.readHumidity();
      float t = dht.readTemperature();
      
              if (isnan(h) || isnan(t)) 
                 {
                     Serial.println("Failed to read from DHT sensor!");
                      return;
                 }
 
                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr +="&field2=";
                             postStr += String(h);
                             postStr += "\r\n\r\n";
 
                             client.print("POST /update HTTP/1.1\n");
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
 
                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" degrees Celcius, Humidity: ");
                             Serial.print(h);
                             Serial.println("%. Send to Thingspeak.");
                        }
          client.stop();
 
          Serial.println("Waiting...");
  
  // thingspeak needs minimum 15 sec delay between updates
  delay(200);
}
}
  • This is strange. I've never seen an MCU library where the watchdog was implicitly turned on without any documentation about how to service it. I'm trying to find in the ESP8266 docs where the WDT is serviced (apparently it has both a SW and HW WDT), but I'm not getting anything immediately. – JohnFilleau Dec 22 '21 at 14:53
  • What output do you receive before receiving the WDT reset message? – JohnFilleau Dec 22 '21 at 15:17
  • Can you provide which version of each of these libraries you're using? The DHT library I found has `getTemperature` and `getHumidity` methods, but not `readTemperate` and `readHumidity`. – JohnFilleau Dec 22 '21 at 15:24

2 Answers2

1

This ESP documentation tells us that your application is being reset by a HW watchdog timer, which is only turned on if the SW watchdog timer is disabled for too long. There may be some way to disable the hardware WDT, but I don't know what that is at the moment.

You should be able to prevent this by enabling the software WDT, and periodically servicing it.

#include <Esp.h>

void setup() {
    // specifying the timeout isn't currently available
    ESP.wdtEnable();
}

void loop() {
    // do useful stuff

    ESP.wdtFeed(); // service the WDT here
}

I'm not sure what the default WDT timeout is, but the comments in the code indicate we can't specify a non-default timeout.

Esp.h on github

JohnFilleau
  • 4,045
  • 1
  • 15
  • 22
  • 1
    I see nothing in the code to trigger the watchdog reset, but it is triggered with brown-out too. and it is usually when the RF power is too high, which is usually if RF calibration is wrong – Juraj Dec 22 '21 at 15:19
  • @juraj the WDT timeout is triggered on a brown-out? Or this is a separate reset sources? Normally WDT and brown-out are separate reset sources. – JohnFilleau Dec 22 '21 at 15:22
  • on brown-out the registers get corrupted and the CPU start executing nonsens or hangs. we see this on corrupted stack dumps if they are produced. – Juraj Dec 22 '21 at 15:46
  • @juraj I see. That could very well be OP's problem. – JohnFilleau Dec 22 '21 at 15:49
-1

The same issue at the ESP8266 Wemos d1r1 board was resolved with that instead of including #include <ESP8266WiFi.h> instead of #include <WiFi.h> after struggling 1

JD Oak
  • 1
  • 1
    Can you clarify which should be included? Its not clear from how this is phrased – Suraj Rao Sep 04 '22 at 13:06
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 10 '22 at 08:35