Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By vvvictor25
#82257 Hi guys! I'm having a strange issue while trying to build a client-server GPS tracking device. The project consists of: 1 ESP8266 client paired with a GPS module and 1 ESP8266 server.

The client listens for connections from the server. When the server polls the client for information (consisting of a connection on port 8081), the client fetches the data from the GPS module and sends a JSON to the server, for further processing.

From time to time, not on a regular basis, the client restarts with error:
Code: Select allets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld



The first attempt in resolving this issue was introducing some delay(0)s in the loops, instead of yield()s, action that made the frequency of the restarts dim. But they still occur.

I'm posting both the client's and the server's codes below:

Server:
Code: Select all#include "ESP8266WiFi.h"
#include <ArduinoJson.h>
#include <string>
#include <stdio.h>
#include <EEPROM.h>

IPAddress ip(192,168,0,194);   
IPAddress gateway(192,168,0,1);   
IPAddress subnet(255,255,255,0); 

struct {
    int restarts = 0;   
} data;


const char* ssid = "Acidro";
const char* password =  "[R@z0r6f()R]";
const char* influx_db_host = "192.168.0.195";
const uint16_t influx_db_port = 8086;
const char* influx_db_ip = "192.168.0.195";

const size_t capacity = 2*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 200;
DynamicJsonDocument doc(capacity);

WiFiServer wifiServer(8080);
WiFiClient wifiClientPoller;

const char* dev_name;
float latitude ;
float longitude ;
float quality_wifi;
float quality_gps;
float sped;
int rssi ;
float alti;
float path;
int current_device = 0;
int client_ready = 0;
unsigned int addr = 0;


void setup() {
   
    Serial.begin(115200);
    delay(1000);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
   
    while (WiFi.status() != WL_CONNECTED) {
      delay(1000);
      Serial.println("Connecting..");
    }
   
    Serial.print("Connected to WiFi. IP:");
    Serial.println(WiFi.localIP());
    WiFi.setSleepMode(WIFI_NONE_SLEEP);
   
    wifiServer.begin();

    EEPROM.begin(10);
    EEPROM.get(addr,data);
    data.restarts = data.restarts;
    EEPROM.put(addr,data);
    EEPROM.commit(); 
}


void pollClients() {
   
    const char* clients[4];
    int i;
    bool exit_flag = 0;
    clients[0]="192.168.0.153";
    clients[1]="192.168.0.193";
    clients[2]="192.169.3.3";
    clients[3]="192.168.3.3";

    for (i=current_device;i<=3;i++) {
        if (wifiClientPoller.connect(clients[i], 8081)) {
            Serial.print("\nConnecting to the ESP client: ");
            Serial.print(clients[i]);
            Serial.print("\n");
            Serial.println("Successfully connected to ESP client: ");
            Serial.print(clients[i]);
            wifiClientPoller.println(1);
            wifiClientPoller.stop();
            current_device = i+1;
            if( current_device == 4 ) {
                current_device = 0;       
            }
            client_ready = 1;
            break;
        } else {
            Serial.print("Connection to the ESP client: ");
            Serial.print(clients[i]);
            Serial.print(" failed");
            wifiClientPoller.stop();
            current_device = i+1;
            client_ready = 0;
            if( current_device == 4 ) {
                current_device = 0;       
            }
           
            yield();
        }
        yield();
    }
               
}


void loop() { 
    checkConnection();
    pollClients();
    if (client_ready == 1) {
        bool sendDataToDB = wait_for_client_and_parse_json();
   
        if (sendDataToDB == 1) {
           int x = send_data_to_db("gps_all");
           if ( x == 1 ) {
                Serial.println("Successfully sent all gps data to InfluxDB");
            }   
            delay(50);
           
            x = send_data_to_db("gps_speed");       
            if ( x == 1 ) {
                Serial.println("Successfully sent gps speed data to InfluxDB");
            }   
            delay(50);

            x = send_data_to_db("gps_path_to_home");       
            if ( x == 1 ) {
                Serial.println("Successfully sent gps pathToHome data to InfluxDB");
            }   
            delay(50);

            x = send_data_to_db("gps_quality");       
            if ( x == 1 ) {
                Serial.println("Successfully sent gps quality data to InfluxDB");
            }   
            delay(50);

            x = send_data_to_db("gps_altitude");       
            if ( x == 1 ) {
                Serial.println("Successfully sent gps altitude data to InfluxDB");
            }   
            delay(50);

            x = send_data_to_db("wifi_rssi");       
            if ( x == 1 ) {
                Serial.println("Successfully sent wifi rssi data to InfluxDB");
            }   
            delay(50);           
        }
    }
    yield();

}


bool wait_for_client_and_parse_json() {

    bool sendDataToDB = 0;
    bool wait_for_client = true;

    unsigned long timeout = millis();             
    while(wait_for_client == true) {
        if (millis() - timeout > 15000) {
            Serial.println("Client timeout. No response from ESP client.");
            break;
          }
         
        WiFiClient client = wifiServer.available(); 
        if (client) {
            while (client.connected()) {
                checkConnection();
                if (client.available()>0) {
                    DeserializationError err = deserializeJson(doc, client);
                    if ( err ) {
                        Serial.print("Failed to parse json from client");
                        Serial.print("Found:\n");
                        Serial.print(err.c_str()); 
                    } else {
                         dev_name = doc["dev_name"];
                         latitude = doc["gps"]["lat"];
                         longitude = doc["gps"]["long"];
                         rssi = doc["signal_quality"]["rssi"];
                         quality_wifi = doc["signal_quality"]["rssi"];
                         quality_gps = doc["signal_quality"]["gps"];
                         sped = doc["gps_other_data"]["speed"] ;
                         alti = doc["gps_other_data"]["altitude"];
                         path = doc["gps_other_data"]["distance_to_hone"];
                         Serial.println(dev_name);
                         Serial.println(latitude);
                         Serial.println(longitude);
                         Serial.println(quality_wifi);
                         Serial.println(quality_gps);
                         Serial.println(sped);
                         Serial.println(alti);
                         Serial.println(path);
                         wait_for_client = false;
                                           
                         sendDataToDB = 1;       
                    }
                }
                yield();

                if (millis() - timeout > 15000) {
                    Serial.println("Client timeout. No response from ESP client.");
                    client.stop();
                    break;
                }
                yield();
            }   
            client.stop();
            Serial.println("Client disconnected");           
        }
        yield();
    }
   

    return sendDataToDB;
}


int send_data_to_db(char* what ) {
    WiFiClient client = wifiServer.available(); 
    int esp1_metric = 0;
    int esp2_metric = 10;
    String base_query = ",host=" + String(dev_name);
   
    String rssi_query_to_send = "rssi" + base_query + " rssi_wifi=" + quality_wifi;           
    String gps_esp_query_to_send = "gps_all_data" + base_query + "," + "lat=" + latitude + "," + "long=" + longitude + "," + "gps_quality=" + quality_gps + "," + "speed=" + sped + "," + "altitude=" + alti + "," + "pathToHome=" + path + " metric=" + esp1_metric;
    String gps_esp_query_to_send_speed = "gps_speed" +  base_query + "," + "lat=" + latitude + "," + "long=" + longitude + " gps_speed=" + sped;
    String gps_esp_query_to_send_path_to_home = "gps_pathHome" +  base_query + "," + "lat=" + latitude + "," + "long=" + longitude + " distToHome=" + path;
    String gps_esp_query_to_send_quality = "gps_quality" +  base_query + "," + "lat=" + latitude + "," + "long=" + longitude + " gps_quality=" + quality_gps;
    String gps_esp_query_to_send_altitude = "gps_altitude" +  base_query + "," + "lat=" + latitude + "," + "long=" + longitude + " gps_altitude=" + alti;
         
         
    Serial.printf("\nConnecting to InfluxDB\n");
   if (!client.connect(influx_db_ip, influx_db_port)) {
      Serial.println("Connection failed");
      client.stop();
      yield();
      return 0;
   } else { 
      Serial.println("Connected to InfluxDB");
                           
      client.print("POST /write?db=mydb HTTP/1.1\r\n");
      client.print("User-Agent: esp8266/0.1\r\n");
      client.print("Host: 192.168.0.195:8086\r\n");
      client.print("Accept: */*\r\n");
      if ( strcmp("gps_all",what) == 0 ) {     
              client.print("Content-Length: " + String(gps_esp_query_to_send.length()) + "\r\n");
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(gps_esp_query_to_send + "\r\n");
          } else if ( strcmp("gps_speed",what) == 0 ) {
              client.print("Content-Length: " + String(gps_esp_query_to_send_speed.length()) + "\r\n"); 
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(gps_esp_query_to_send_speed + "\r\n");
          } else if ( strcmp("gps_path_to_home",what) == 0 ) {
              client.print("Content-Length: " + String(gps_esp_query_to_send_path_to_home.length()) + "\r\n");
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(gps_esp_query_to_send_path_to_home + "\r\n");
////////////////
          } else if ( strcmp("gps_quality",what) == 0 ) {
              client.print("Content-Length: " + String(gps_esp_query_to_send_quality.length()) + "\r\n"); 
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(gps_esp_query_to_send_quality + "\r\n");
          } else if ( strcmp("gps_altitude",what) == 0 ) {
              client.print("Content-Length: " + String(gps_esp_query_to_send_altitude.length()) + "\r\n"); 
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(gps_esp_query_to_send_altitude + "\r\n");
          } else if ( strcmp("wifi_rssi",what) == 0 ) {
              client.print("Content-Length: " + String(rssi_query_to_send.length()) + "\r\n"); 
              client.print("Content-Type: application/x-www-form-urlencoded\r\n");
              client.print("\r\n");
              client.print(rssi_query_to_send + "\r\n");
          } else {
              Serial.print("Received info from an unknown source or measurement");
              Serial.print("Device:");
              Serial.print(dev_name);
              Serial.print("\nMeasurement:");
              Serial.print(what);
          }       
             
      client.flush();
     
      /// Wait for the response from the InfluxDB server 
      unsigned long timeout = millis();
      while (client.available() == 0) {
          if (millis() - timeout > 30000) {
            Serial.println("Client timeout. No response from InfluxDB server.");
            client.stop();
            return 0;
            break;
          }
      }           
      Serial.println("Showing the database response:\n");
      while (client.available()) {
          checkConnection();
          char ch;
          ch = client.read();
          if ( &ch == "" ) {
              Serial.print("Response from InfluxDB server came, but it was empty");
              return 0;
              break;
          } else {
              //Serial.print(ch);
             
          }
      }   
      client.stop();         
      yield();
    }

    return 1;
}


void checkConnection() {

    if (WiFi.status() != WL_CONNECTED ) {
        Serial.println("Lost connection");
        WiFi.begin(ssid, password);   
        yield();
    }
    unsigned int timeout = millis();
    while(WiFi.status() != WL_CONNECTED) {         
        Serial.println("Not connected yet");
        if (millis() - timeout > 30000) {
            Serial.println("Failed to connect after 30s. Restarting ESP module");
            EEPROM.begin(10);
            EEPROM.get(addr,data);
            data.restarts++;
            EEPROM.get(addr,data);
            EEPROM.commit(); 
            Serial.print("Current no. of restarts: ");
            Serial.print(data.restarts);
            ESP.restart();
           
        }
        yield();
   
    }
}



Client:
Code: Select all#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
 
const size_t capacity = 2*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 400;

const char* ssid = "Acidro";
const char* password = "[R@z0r6f()R]";
static const int RXPin = 4, TXPin = 5;
static const uint32_t GPSBaud = 9600;
static const double HOME_LAT = 44.379521, HOME_LON = 26.110762;

char json_string[500];
String rssi_str;
char rssi;
int restarts = 0;

double latitude;
double longitude;
int spd;
double alt;
int precision;
double pathToHome; 

bool gps_data_ready = 0;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
WiFiClient client; 
WiFiServer wifiServer(8081);

void setup() {
    Serial.begin(115200);
    ss.begin(GPSBaud);
    Serial.println(); 
    WiFi.mode(WIFI_STA);
    Serial.printf("Connecting to %s ", ssid);   
    WiFi.begin(ssid, password);   

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println(" connected"); 
    Serial.println(WiFi.localIP());
    WiFi.setSleepMode(WIFI_NONE_SLEEP);
    wifiServer.begin();
    delay(0);
       
   
}


void wait_for_esp_request() {
    char token;
    bool wait_for_client = true;
    unsigned long timeout = millis();
    while(wait_for_client == true) {
        checkConnection();   
        if (millis() - timeout > 120000) {     
            Serial.print("Restarting...(timeout>120s");       
            ESP.restart();
           
        }
        WiFiClient client = wifiServer.available(); 
        if (client) {
            Serial.print("we got client");
            while (client.connected()) {
                if (client.available()>0) {                       
                    wait_for_client = false; 
                    delay(0);                         
                    client.stop();
                    delay(0);               
                }
                delay(0);
            }
            delay(0);
        }
        if (wait_for_client == false) {
            break;
        }
        delay(0);
    }
    delay(0);
    client.stop();
    delay(0);
}

void loop() {   
   
    checkConnection();
     
    wait_for_esp_request();
     
    displayInfo();
   
    if (gps_data_ready == 1) {
        create_json(longitude, latitude, spd, alt, precision, pathToHome);
        int x = send_json();
        if ( x == 1 ) {
            Serial.println("Successfully sent json to ESP server");
        } else {
            Serial.println("Could NOT send json to ESP server");
        }
    } else {
        Serial.println("No data from GPS server available");
    }
    delay(0);
       
}


void create_json(double lon, double lati, int sped, double alti, int prec, double path) {
    StaticJsonDocument<20000> doc;

    int rssi = get_rssi();
    doc["dev_name"] = "esp2";   
    JsonObject signal_quality = doc.createNestedObject("signal_quality");
    signal_quality["rssi"] = rssi;
    signal_quality["gps"] = prec;
    delay(0);
   
    JsonObject gps = doc.createNestedObject("gps");
    gps["lat"] = lati;
    gps["long"] = lon;
    delay(0);
   
    JsonObject gps_other_data = doc.createNestedObject("gps_other_data");
    gps_other_data["speed"] = sped;
    gps_other_data["altitude"] = alti;
    gps_other_data["distance_to_hone"] = path;
    delay(0);
   
    serializeJson(doc, json_string); 
    serializeJson(doc, Serial);
    Serial.print(latitude);
}

int send_json () {

    Serial.println("\nConnecting to the ESP server\n");
    if (client.connect("192.168.0.178", 8080)) {
        Serial.println("Connected to the ESP server\n"); 
        Serial.println("Sending the json\n");
        client.println(json_string);
        Serial.println(json_string);
        client.flush();
        delay(0);
        client.stop();
        delay(0);
        Serial.println("\nDisconnected");
    }
    else {
        Serial.println("connection failed!]");
        delay(0);
        client.stop();
        delay(0);
        return 0;
    }
    //delay(1000);   

    return 1;
}

int get_rssi() {
    int rssi = WiFi.RSSI();
           
    return rssi;
   
}


void displayInfo() {
    double timer = 0;   
    unsigned long timeout = millis();
    while (timer == 0 || timer >= 4000) {
        delay(0);
        while (ss.available() > 0) {
            delay(0);             
            if (gps.encode(ss.read()))         
                if (gps.location.isValid()) {
                     timer = (gps.location.age());
                     latitude = (gps.location.lat());                                                                 
                     longitude = (gps.location.lng());   
                     spd = (gps.speed.kmph());               
                     alt = (gps.altitude.meters());
                     precision = (gps.hdop.value());
                     pathToHome = TinyGPSPlus::distanceBetween(latitude,longitude,HOME_LAT,HOME_LON);
                     gps_data_ready = 1;                                                                                                           
                     delay(10);                                           
                } else {           
                    //Serial.println(F("INVALID"));
                }
        }     
        delay(0);   

        if (millis() - timeout > 10000) {
            Serial.println("GPS timeout. No response from GPS module.");
            gps_data_ready = 0;
            break;
        }
    }
   delay(0);         
}


void checkConnection() {

    if (WiFi.status() != WL_CONNECTED ) {
        Serial.println("Lost connection");
        WiFi.begin(ssid, password);   
        delay(500);
    }
    unsigned int timeout = millis();
    while(WiFi.status() != WL_CONNECTED) {         
        Serial.println("Not connected yet");
        delay(0);
        if (millis() - timeout > 30000) {
            Serial.print("Restarting...(timeout>30s)");           
            ESP.restart();
                       
        }
       delay(0);   
    }
}


Furthermore, I managed to decode the stack trace from the error code, and it led me to this:
Code: Select allDecoding stack results
0x402064bf: run_scheduled_functions() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\Schedule.cpp line 68
0x40100587: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100587: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100595: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 166
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x401004c4: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 130
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x40100595: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 166
0x401004c4: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 130
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x401004c4: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 130
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x40100595: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 166
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100587: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100587: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x40100595: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 166
0x40100584: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 162
0x401001eb: sws_isr_4() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SoftwareSerial\SoftwareSerial.cpp line 42
0x40203c95: ESP8266WiFiSTAClass::begin(char const*, char const*, int, unsigned char const*, bool) at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 152
0x40203c90: ESP8266WiFiSTAClass::begin(char const*, char const*, int, unsigned char const*, bool) at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 151
0x401004c4: interrupt_handler at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring_digital.c line 130
0x4010039c: millis at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring.c line 183
0x40203c90: ESP8266WiFiSTAClass::begin(char const*, char const*, int, unsigned char const*, bool) at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 151
0x40206504: run_scheduled_functions() at c:\users\crist\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-3-20ed2b9\xtensa-lx106-elf\include\c++\4.8.2/functional line 2174
0x402014bb: delay at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_wiring.c line 51
0x40202759: ArduinoJson6101_000::TextFormatter ::writeRaw(char const*) at C:\Users\crist\OneDrive\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/TextFormatter.hpp line 119
0x401002f5: __wrap_spi_flash_read at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\core_esp8266_phy.c line 267
0x40203875: wifi_dns_found_callback(char const*, ip4_addr const*, void*) at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi\src\ESP8266WiFiGeneric.cpp line 576
0x40202658: checkConnection() at C:\Users\crist\OneDrive\Documents\Arduino\tcp_client_json_scalable/tcp_client_json_scalable.ino line 220
0x40206525: run_scheduled_functions() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\Schedule.cpp line 71
0x402065b0: _GLOBAL__sub_D__ZN18ScheduledFunctions18scheduledFunctionsE() at C:\Users\crist\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266\ScheduledFunctions.cpp line 116



I, frankly, was not able to track down the issue based on this output. If you can give me a few suggestions about how my code influenced this behavior I'll be very grateful. I understood that the first line of code from the Exception Decoder represents the cause of the error, but I don't understand why run_scheduled_functions() method failed.

Thank you very much and if I missed something, please tell and I'll provide any information I can obtain:)
User avatar
By mel
#82383 hi, did you find the problem?.
I too was having problems with the Nodemcu ESP8266 resetting, but a day ago they released Board update for the ESP8266 in Arduino IDE and now when I upload the sketch all works as it should.

Regards,
Melissa
User avatar
By kiran sahu
#82408 I am getting "Soft WDT reset" when I used both HX711.h and pubsubclient.h
My code is working when I use these libraries separately. That is I can measure weight using HX711 and connect to MQTT broker using two different sketches.
But getting following error when I use them both.

Connecting to TP-LINK_FFAA
.
WiFi connected
IP address:
192.168.0.103
Attempting MQTT connection...
Soft WDT reset

ctx: cont
sp: 3ffefe70 end: 3fff00f0 offset: 01b0

stack>>>
3fff0020: 3ffe897c 00000f48 3ffeed68 40202ceb
3fff0030: 00000000 3ffeed64 3ffeed68 402038f0
3fff0040: 514d0400 3f045454 3fff00ac 4020423f
3fff0050: 00000000 3fff10cc 00000000 4020428b
3fff0060: 3ffef074 00000154 00000154 3ffef0c0
3fff0070: 3fffdad0 3ffef094 3ffeed64 40203974
3fff0080: 00000000 00000000 3ffeed64 402041e4
3fff0090: 3ffe84e4 3ffef094 3ffeed64 4020232b
3fff00a0: 00000000 00000000 00000000 3fff10cc
3fff00b0: 0000001f 00000012 3ffeee38 40204824
3fff00c0: 4020217c 3ffeed64 3ffef0b9 40202472
3fff00d0: 3fffdad0 00000000 3ffef0b9 402044fc
3fff00e0: feefeffe feefeffe 3ffef0d0 40100710
<<<stack<<<
H!⸮⸮?�⸮F

Settings in IDE
Module: NodeMCU1.0(ESP-12E Module)
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ?qio?
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ?ck / nodemcu?

Sketch
#include <HX711.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#define calibration_factor1 -409200 //This value is obtained using the Calibration sketch
#define calibration_factor2 -442400 //This value is obtained using the Calibration sketch

#define DOUT1 D1
#define CLK1 D2

#define DOUT2 D5
#define CLK2 D6

float weight1, weight2, total_weight;

HX711 scale1(DOUT1,CLK1);
HX711 scale2(DOUT2,CLK2);

#define BUILTIN_LED D4

const char* ssid = ".....";
const char* password = ".....";
const char* mqtt_server = ".....";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup_wifi() {

delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

randomSeed(micros());

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();

// Switch on the LED if an 1 was received as first character
if ((char)payload[0] == '1') {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
}

}

void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
delay(50);
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic_Try/", "hello world");
// ... and resubscribe
client.subscribe("InTopic_Try/");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup() {
//pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(9600);
delay(50);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);

scale1.set_scale(calibration_factor1); //This value is obtained by using the Calibration sketch
scale1.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

scale2.set_scale(calibration_factor2);
scale2.tare();

}

void loop() {

if (!client.connected()) {
reconnect();
}
client.loop();

long now = millis();
weight1=scale1.get_units(5);
weight2=scale2.get_units(5);
total_weight=weight1+weight2;
if (now - lastMsg > 5000) {
lastMsg = now;
++value;
snprintf (msg, 75, "Total weight #%ld", total_weight);
Serial.print("Publish message: ");
Serial.println(msg);
client.publish("outTopic_Try/", msg);
}
}
User avatar
By teddyz
#87778 I just want to mention that I have some code that I put a yield() into, just to be nice to the ESP. I should not have done so, because it causes canc... WDT or Soft WDT restarts. A delay(0) is no problem, but it hates yield().

The restarts happens when I log (to Serial) things that happens in association with WiFi.connect(...).

I do not know why, but now I think I know how to avoid.

Posted in hope it is helpful to anyone.

Code: Select allvoid log( int8_t prio, const char *logtext ) {

  if ( 1 ) {
    S.print( "log: " );
    S.print( prio );
    S.print(" : ");
    S.println( logtext );
    yield(); // <- cause restart
    return;
  }
}