[SOLVED] WDT reset on esp8266 while connecting to blynk

Hi!

While using a NodeMCU V1.0 to connect to blynk I’ve a problem with wdt reseting while doing:

Blynk.begin(auth, ssid, pass);

I’ve trying disabling wdt and also feeding it, but the error keeps going on.

This is my code, in case it’s needed.

#include <Adafruit_BME280.h>

#include <Blynk.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space

//WidgetTerminal terminal(V8);

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

int sampleInterval = 1000;
unsigned long nextSampleTime = 0;
unsigned long delayTime;
#define threshold 2 //Threshold in temperature/humidity changes to avoid misreadings
int lastT, lastH;


#define threesholdTemp_SUP 27
#define threesholdTemp_INF 20
void setup() {
  
  Serial.begin(115200);
  Serial.println("\nblynk begin");
  Blynk.begin(auth, ssid, pass);
  Serial.println("\nBlynk begin done");

  Serial.println(F("BME280 test"));


  bool status;

  // default settings
  status = bme.begin();
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
    ESP.wdtFeed();
  }

  nextSampleTime = 0;

  lastT = bme.readTemperature();
  lastH = bme.readHumidity();

  Blynk.virtualWrite(V3, sampleInterval);

}



void loop(){

  Blynk.run(); // all the Blynk magic happens here
 
  // Check if we need to start the next sample
    if (millis() > nextSampleTime) {
        //getDHT(); 
        getBME();
        //terminal.println("sample");
        //terminal.flush();
    }
    ESP.wdtFeed();
}

// SLIDER
BLYNK_WRITE(V0) {  // reads value from slider, set range of 0-255, and passes it onto PWM pin

    //Blynk.syncVirtual(V1);
    int value = param.asInt();
    //analogWrite(mosfetPin, value);
    if (value == 0) { // If slider is OFF, make sure button is as well
        Blynk.virtualWrite(V1,0);
    }else { // If slider is anything equal or higher than 1, set button ON
        Blynk.virtualWrite(V1,1);
    }
}

// BUTTON
BLYNK_WRITE(V1) {
    int value = param.asInt();
    //digitalWrite(mosfetPin,value);
    if (value==0) {
        //LOW
        // change button to off
        Blynk.virtualWrite(V0,0);
    }else{        // change button to on
        
        Blynk.virtualWrite(V0,255);
    }
}

//cHANGE SAMPLE INTERVAL
BLYNK_WRITE(V4){
    Blynk.syncVirtual(V3); //Get Labeled value in V3
    int value = param.asInt();
    value = value * 1000; // Transform into millisecond
    Blynk.virtualWrite(V3,value);
    sampleInterval = value;
    
}


void changeColor(float _t){
    if (_t > threesholdTemp_SUP){ //change to red
        Blynk.setProperty(V2,"color","#FF0000");
        Blynk.setProperty(V6,"color","#FF0000");
    }else if (_t < threesholdTemp_INF){ // change to blue
        Blynk.setProperty(V2,"color","#0000FF");
        Blynk.setProperty(V6,"color","#0080FF");   
    }else{ //green
        Blynk.setProperty(V2,"color","#00FF00");
        Blynk.setProperty(V6,"color","#00FF00");
    }
}
/*
void getDHT(){
    
  float h = dht.getHumidity();

  float t = dht.getTempCelcius();
  
  changeColor(t);
    // ADD A CHECK OF THE VALUES TO AVOID DATA CORRUPTION
    if (t > lastT + threshold || t < lastT - threshold){
        // the reading is outside the admited limits, so, asume the value hasn't changed since last time.
        t = lastT;   
    }else{
        lastT = t;
    }
    if(h > lastH + threshold || h < lastH - threshold){
        // the reading is outside the admited limits, so, asume the value hasn't changed since last time.
        h = lastH;
    }else{
        lastH = h;
    }
    // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
      //Blynk.notify("Failed to read sensor");
      //Serial.println("Failed to read sensor");
    return;
  }else{
      Blynk.virtualWrite(V5, h);
      Blynk.virtualWrite(V7, h);
        Blynk.virtualWrite(V6, t);
        Blynk.virtualWrite(V2, t);
  }
  DHTnextSampleTime = millis() + sampleInterval;
  
  
}
*/
void getBME(){
    
    float t = bme.readTemperature();
    float h = bme.readHumidity();
    float p = bme.readPressure() / 100.0F; // hPa
    float alt = bme.readAltitude(SEALEVELPRESSURE_HPA); // m
    
    //terminal.print("p = ");
    //terminal.println(p);
    //terminal.print("Alt = ");
    //terminal.print(alt);
    //terminal.flush();
    changeColor(t);
    // ADD A CHECK OF THE VALUES TO AVOID DATA CORRUPTION
    if (t > lastT + threshold || t < lastT - threshold){
        // the reading is outside the admited limits, so, asume the value hasn't changed since last time.
        t = lastT;   
    }else{
        lastT = t;
    }
    if(h > lastH + threshold || h < lastH - threshold){
        // the reading is outside the admited limits, so, asume the value hasn't changed since last time.
        h = lastH;
    }else{
        lastH = h;
    }
    // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
      //Blynk.notify("Failed to read sensor");
      //Serial.println("Failed to read sensor");
    return;
  }else{
      Blynk.virtualWrite(V5, h);
      Blynk.virtualWrite(V7, h);
        Blynk.virtualWrite(V6, t);
        Blynk.virtualWrite(V2, t);
  }
  nextSampleTime = millis() + sampleInterval;
}

As always, thanks and greetings!

one of the pins has connected smthng that it causes this. disconnect EVERYTHING and test.

probably one of the spi interface pins are blocking a function on the board. unfortunately the pins on esp boards have lots of multiple functions, and these are not clearly documented. you have to look for the small details. some pins should be pulled low or high to start up properly.

you should post the error log for more detail.

also, i’ve changed the category to “need help with my project”. issues and errors category is reserved for blynk related problems. but i’m 99% sure this problem is not caused by blynk.

1 Like

Hi!

Yes, It’s seems that it the sensor library… I had uploaded the test sketch and it seems to be working properly…

Any thoughts on how to fix this?

The problem was the breadboard… I’ve switched to another and it’s working properly.

1 Like