Soft WDT reset seems to happen on Blynk.begin - previously worked

I have a Blynk legacy project I’m finally trying to get working again. I had a lot of success at first and had everything working except the temp/humidity DHT22 sensor. (Was getting a failed to read from DHT sensor). As I was flashing the board again at some point it would not connect to Blynk. Looking at the serial monitor it seems to get to the Blynk.begin line and hangs (after it says connecting to SSID). The I get a soft WDT reset, Exception (4) and the exception text.

I’m trying to figure out if I have a loop somewhere, if for some reason it is taking too long to connect to wifi like with a watchdog error? Or maybe I screwed up the board.
(Sparkfun ESP8266 Thing)

Would appreciate any advice, thanks in advance.

// pin 12 - power status, pin 13 temp data, pin 0 - garage mag sensor, pin 4 - open/close garage
// NOTE PIN 12 NOT USED FOR GARAGE - NO EXTERNAL POWER CHECK

#define BLYNK_TEMPLATE_ID      "XXXXXXXX"
#define BLYNK_TEMPLATE_NAME    "XXXXX"
#define BLYNK_AUTH_TOKEN       "XXXXXXXXXXXX"
#define BLYNK_PRINT Serial
#define DHTTYPE  DHT22 
#define DHTPIN   13
#define humidity_topic "sensor/humidity" //maybe don't need?
#define temperature_topic "sensor/temperature" //maybe dont need?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
DHT dht(DHTPIN, DHTTYPE, 13); //  ESP8266 Temp sensor

unsigned long startMillis;  //Garge door time open
unsigned long currentMillis; //set current time to variable
unsigned long period = 1800000;  //3,600,000 milliseconds in one hour, 7200000 - 2 hours, 120000 - 2 minutes, 1 min = 60,000ms, 30 min = 1,800,000
unsigned int Gtempnotify = 0; //notify flag for garage temp low
unsigned int GtempnotifyHIGH = 0; //notify flag for garage temp high
//int priorState = digitalRead(12);  //setup variable for PowerSensorStatus (notify flag)
BlynkTimer timer;

// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

 // ========{ Timer for garage door status and temp/humidity }==================

void myTimerEvent() 
{
  currentMillis = millis();  //get the current "time" moved here from loop...
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity(); //changed from fload to int
  // Read temperature as Celsius (the default)
  int t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  

  //Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  } 

  // Compute heat index in Fahrenheit (the default)
  int hif = dht.computeHeatIndex(f, h); //changed from float to int
  // Compute heat index in Celsius (isFahreheit = false)
  int hic = dht.computeHeatIndex(t, h, false); //changed from fload to int

 /* check working
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F"); */

  Serial.println(); //blank line
  Serial.print("Temperature: ");
   Serial.print(f); 
     Serial.println(); //blank line
  
  Blynk.virtualWrite(V2, f);
  Blynk.virtualWrite(V3, h);
  Blynk.virtualWrite(V4, hif);

if (f<20 && Gtempnotify == 0) { //check temp and notify flag
  Gtempnotify = 1;
Blynk.logEvent("notify",String("Cold in garage : ") + f + String("°F"));
}
else if(f>22){ 
  Gtempnotify = 0;
  }

if (f>122 && GtempnotifyHIGH == 0) {
  GtempnotifyHIGH = 1;
  Blynk.logEvent("notify",String("Hot in garage : ") + f + String("°F"));
}
else if(f<120) {
  GtempnotifyHIGH = 0;
  }

}

 // ========{ End Timer }==================


 // ========{ Garage Magnetic SW Monitoring Input }==================
void garageMagSensor ()
{
  //Serial.println(digitalRead(0)); TESTING only
  WidgetLCD lcd5(V5); //Garage door
  int garageSensorSW = digitalRead(12); // GPIO5
  int GarageOpenMinutes = (currentMillis - startMillis) / 1000 /60;
  if (garageSensorSW == LOW)
  {
    int DoorStatus = 1;
    lcd5.print(0, 0, "GARAGE IS CLOSED"); // LCD print, column 1, row 0.
   startMillis = currentMillis; //reset timer for garage open to current time
   period = 1800000; // Reset the time garage door is open before push notify
   lcd5.print(0, 1, "                "); //prints spaces on second line to clear it out
  }
  else
  {
    int DoorStatus = 0;
    lcd5.print(0, 0, "GARAGE IS OPEN  "); // LCD print, column 1, row 0
 
    lcd5.print(0, 1, (String(GarageOpenMinutes) + String(" minutes"))); //used string to combine var and text
  
  }

if (currentMillis - startMillis >= period) //test if period has elapsed and push notify
{ 
 Blynk.logEvent("notify",String("Garage door is open for: ") + GarageOpenMinutes + String(" minutes"));
 //String EmailString; LEGACY
 //EmailString = String(GarageOpenMinutes) + " minutes"; LEGACY
 //Blynk.email("XXXXXXX", "Garage Open for",EmailString); // send email LEGACY
period = period * 2; //delay next notification * 2 so I don't keep getting notified as quickly while remains open
  Serial.print("Garage Door is open for: ");
  int GarageOpenMinutes = (currentMillis - startMillis) /1000 /60;
  Serial.print(GarageOpenMinutes);
  Serial.println(" minutes");
  
 //startMillis = millis(); //reset notify variable time
}
else
{ }

} 
//======== { End Garage magnetic sensor } ============

 // ========{ WiFi Setup }==================
void setup_wifi () 
{ 
char ssid[] = "DontPanic";
char pass[] = "XXXXXXX";
Serial.print("Connecting to ");
Serial.println(ssid);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Blynk.begin(auth, ssid, pass); blynk legacy

Blynk.logEvent("notify","Garage Thing Started");
Serial.println("Garage Thing startup");

WidgetLCD lcd(V0);

IPAddress myip; 
   myip = WiFi.localIP();
 String fullip = String(myip[0]) + "." + myip[1] + "." + myip[2] + "." + myip[3]; 
lcd.print(0, 0, "IP Address:");
 lcd.print(0, 1, fullip); //Show IP on app V0
}  
 // ========{ End WiFi Setup }==================


//============ { Setup } =======================
void setup() { 
  // put your setup code here, to run once:
  Serial.begin(9600);
  setup_wifi();
 
// Setup a function to be called every x seconds
  timer.setInterval(15000L, myTimerEvent); //temp, humidity, heat index
  timer.setInterval(5000L, garageMagSensor); //check garage door status
 // timer.setInterval(5000L, PowerSensorStatus); //check to see if power is on
  //timer.setInterval(500L, StillConnected); //check to see if still connected in app

pinMode(12,INPUT_PULLUP); //Garage Door mag sensor INPUT_PULLUP  HAD to use pullup as pull up resistor to work
//pinMode(12,INPUT); //PowerStatus checks for voltage 3.3v
pinMode(4, OUTPUT) ; //button to close/open garage

} 
//============ { End Setup } =======================

//============== { Loop } ==========================
void loop() { 
    // put your main code here, to run repeatedly:
Blynk.run();
timer.run(); // Initiates BlynkTimer

} 

// ============== { End Loop } ==================== 


I enabled debugging and got some additional info in the serial monitor below - looks like it is connecting to wifi.

scandone
state: 0 → 2 (b0)
state: 2 → 3 (0)
state: 3 → 5 (10)
add 0
aid 21
cnt
connected with DontPanic, channel 9
dhcp client start…
wifi evt: 0
pm open,type:2 0
[251065] Connected to WiFi
[251065] IP: 1xx.xxx.xx.xxx (changed numbers)
[251198] Connecting to blynk.cloud:80
[hostByName] request IP for: blynk.cloud
[hostByName] Host: blynk.cloud lookup error: Unknown (-6)!
[251343] Connecting to blynk.cloud:8080
[hostByName] request IP for: blynk.cloud
[hostByName] Host: blynk.cloud lookup error: Unknown (-6)!

---- Update –
I also tried putting in the IP address manually with the code below and it still didn’t connect. I could ping blynk.cloud and that is how I got the IP address below.

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, “64.225.16.22”, 8080);

That’s not a good idea, as the server IP address may change.

It looks like your device can’t see the internet, or if it can then its using an invalid DNS IP address.
Is your device connecting to your main router, or to a repeater in your garage?
Have you tried restarting your router and any repeaters/access points?
Have you made any changed to your home network since your old Legacy system last worked? (New ISP, router or repeaters)?

The rest of your sketch is rather clunky, and once you get it connecting to Blynk you should ask for help in making it simpler.

Pete.

Hi Pete,

Thanks for the comments. The static IP address was just a test, as far as the internet it is connecting to the main router. I plugged in my project this morning and it connected just fine, so I have to wonder if the free version of Blynk didn’t like all my re-connections? I went to bed with it not working left it unplugged and plugged it in today and it connects (nothing changed).

I’m still getting the Failed to read from DHT sensor error. Do you think that is from my clunky code :slight_smile: (I’m pretty new to programming). Or should I solder on a new sensor?

Anyway, I read so many posts on this form while troubleshooting and you seem to reply to a lot of them. So thank you for all the help you provide to me and others.

It sounds more like a power supply issue to me.

Is your DHT sensor connected to the pin labelled D7 ?
Have you tried running the DHT example in the sketch builder (with the appropriate pin changes) ?

Pete.

I just tried a new sensor and same issue.

I’m using a 5v dc wall wart for power. On my ESP8266 board I’m using pin 13 which is a data pin. It did work before with legacy blynk, but I’m wondering if the updated library might have something to do with it.

I did refer back the DHT example in the sketch builder, didn’t copy it exactly but made sure my code matched except for the timer (since mine is setup differently).

It might be a power issue, I’ll have to go back and check my wiring. I am getting some values but I know they are wrong, along with the failed to read message:

Humidity: 3291.90 % Temperature: 50.00 *F Humidity: 3291.80 % Temperature: 50.00 *F Failed to read from DHT sensor!

I’ll try setting up a new board with the default example code when I have some time.

That didn’t answer my question though.

I doubt it, unless maybe you’re using a very obscure DHT library.

I was suggesting that you try that exactly as it appears in the sketch builder, with a changed DHT pin and your own Blynk and WiFi credentials. Why not try that approach to eliminate potential issues?

Why a new board? That just introduces more variables.

Pete.

DHT is not connected to pin labelled D7, there is no D7 on my board.

Anyway, I went to connect it to the garage magnetic contact sensor and had to unplug it and plug it in again and of course it won’t connect. Back to the same issue I had with blynk.colud lookup error. I’m going to leave it unplugged for a few hours and try it again. Must be a network issue on my router or with my wifi, I going to check my other wifi devices (so far have not noticed an issue with them though).

Sorry, I forgot you were using the Spartfun board and not a regular NodeMCU.

Maybe it’s a Spartfun thing then, I’m not familiar with these boards.

Pete.