Constant crashes



  • After a while and trying to connect to AP, this happens a lot. It even seems to occur more often once it happens:

    Connectie time-out, open AP
    LNot connected...
    Wachten op wifi connectie...
    66
    Exception (0):
    epc1=0x402112a1 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    ctx: sys
    sp: 3ffffd60 end: 3fffffb0 offset: 01a0

    stack>>>
    3fffff00: 03030201 00000000 3ffedab8 4022620c
    3fffff10: 00000002 00000001 00000000 76286643
    3fffff20: 3fff31c4 4020ebe1 3ffed018 3ffed018
    3fffff30: 3fff2db4 3ffed018 3ffed018 4020ebbf
    3fffff40: 00000018 00000001 3ffe9ee6 3fff318c
    3fffff50: 00000147 3ffe9eee 3fff1214 3ffe9ed0
    3fffff60: 00000000 00000023 40209b46 3ffed018
    3fffff70: 3ffe9ed0 3fffdcc0 3ffe9718 3fff262c
    3fffff80: 3ffe9ee0 00000000 00000000 3fff281c
    3fffff90: 40209493 3fffdab0 00000000 4021dbf7
    3fffffa0: 3ffe9718 40000f49 3fffdab0 40000f49
    <<<stack<<<

    Could there be something wrong with the board? (Wemos D1 R1 or R2)
    I had everything removed sensor wise, so there could be no interference. Did not help.
    Cannot get the Wemos D1 Mini Pro to work either (GPIO 0/2 do nothing).

    Here's the code:

    #include <ESP8266WiFi.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266HTTPClient.h>
    #include <EEPROM.h>
    #include <SoftwareSerial.h>

    #define tx 2
    #define rx 0
    String txt = "";
    String rest = "";

    const char* ssid = "";
    const char* passphrase = "";
    String st;
    String content;
    int statusCode;
    long duration, level;
    float distance;
    String esid="";
    String epass="";
    int compid;
    String UID="";

    ESP8266WebServer server(80);
    SoftwareSerial swSer(rx, tx, false, 1024);
    WiFiClient client;

    void setup() {

    pinMode(tx,OUTPUT);
    pinMode(rx,INPUT);

    Serial.begin(9600);
    EEPROM.begin(512);
    swSer.begin(19200);

    // als mechanische test

    echolaser();

    /*
    

    client.setNoDelay(true);
    WiFi.setAutoConnect(true);
    WiFi.setAutoReconnect(true);
    */

    getPass();

    if ( esid.length() > 1 ) {
    WiFi.begin(esid.c_str(), epass.c_str());
    if (testWifi()) {
    launchWeb(0);
    return;
    }else{
    server.handleClient();
    }
    }
    setupAP();
    server.handleClient();
    delay(5000);
    }

    // -----------------------------------------------------------------------------------------------

    void loop() {

    if(WiFi.status() == WL_CONNECTED){
    echolaser();
    sender();
    for (int i = 0; i < 12; ++i){
    Serial.print(".");
    delay(5000);
    server.handleClient();
    receiver();
    }
    }else{
    Serial.println("Not connected...");
    if ( esid.length() > 1 ) {
    WiFi.begin(esid.c_str(), epass.c_str());
    if (testWifi()) {
    launchWeb(0);
    return;
    }
    }
    }
    Serial.print("L");
    }

    // -----------------------------------------------------------------------------------------------

    void getPass() {

    // read eeprom for ssid and pass

    esid = "";
    UID = "";
    epass = "";

    for (int i = 0; i < 32; ++i)
    {
    esid += char(EEPROM.read(i));
    UID += char(EEPROM.read(i));
    }
    Serial.print("SSID: ");
    Serial.println(esid);
    Serial.println("Reading EEPROM pass");
    for (int i = 32; i < 96; ++i)
    {
    epass += char(EEPROM.read(i));
    }
    Serial.print("PASS: ");
    Serial.println(epass);
    }
    // -----------------------------------------------------------------------------------------------

    bool testWifi(void) {
    int c = 0;
    Serial.println("Wachten op wifi connectie...");
    while ( c < 10 ) {
    if (WiFi.status() == WL_CONNECTED) { return true; }
    delay(1000);
    Serial.print(WiFi.status());
    c++;
    }
    getPass();
    Serial.println("");
    Serial.println("Connectie time-out, open AP");
    return false;
    }

    void launchWeb(int webtype) {
    Serial.println("");
    Serial.println("WiFi verbonden");
    Serial.print("Local IP: ");
    Serial.println(WiFi.localIP());
    Serial.print("SoftAP IP: ");
    Serial.println(WiFi.softAPIP());
    createWebServer(webtype);
    // Start the server
    server.begin();
    Serial.println("Webserver gestart");
    }

    void setupAP(void) {
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);
    int n = WiFi.scanNetworks();
    Serial.println("Scan klaar");
    if (n == 0)
    Serial.println("Geen netwerken gevonden");
    else
    {
    Serial.print(n);
    Serial.println(" netwerken gevonden");
    for (int i = 0; i < n; ++i)
    {
    // Print SSID and RSSI for each network found
    Serial.print(i + 1);
    Serial.print(": ");
    Serial.print(WiFi.SSID(i));
    Serial.print(" (");
    Serial.print(WiFi.RSSI(i));
    Serial.print(")");
    Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"");
    delay(10);
    }
    }
    Serial.println("");
    st = "<ol>";
    for (int i = 0; i < n; ++i)
    {
    // Print SSID and RSSI for each network found
    st += "<li>";
    st += WiFi.SSID(i);
    st += " (";
    st += WiFi.RSSI(i);
    st += ")";
    st += (WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"
    ";
    st += "</li>";
    }
    st += "</ol>";
    delay(100);
    WiFi.softAP(ssid, passphrase, 6);
    Serial.println("softap");
    launchWeb(1);
    Serial.println("over");
    }

    void createWebServer(int webtype)
    {
    if ( webtype == 1 ) {
    server.on("/", {
    IPAddress ip = WiFi.softAPIP();
    String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
    content = "<!DOCTYPE HTML>\r\n<html>TanQyou Proto 3 (c)Eye_box 2016 at ";
    content += ipStr;
    content += "<p>";
    content += st;
    content += "</p><form method='get' action='setting'><label>SSID: </label><input name='ssid' length=32><input name='pass' length=64><input type='submit'></form>";
    content += "</html>";
    server.send(200, "text/html", content);
    });
    server.on("/setting", {
    String qsid = server.arg("ssid");
    String qpass = server.arg("pass");
    if (qsid.length() > 0 && qpass.length() > 0) {
    Serial.println("clearing eeprom");
    for (int i = 0; i < 96; ++i) { EEPROM.write(i, 0); }
    Serial.println(qsid);
    Serial.println("");
    Serial.println(qpass);
    Serial.println("");

          Serial.println("writing eeprom ssid:");
          for (int i = 0; i < qsid.length(); ++i)
            {
              EEPROM.write(i, qsid[i]);
              Serial.print("Wrote: ");
              Serial.println(qsid[i]); 
            }
          Serial.println("writing eeprom pass:"); 
          for (int i = 0; i < qpass.length(); ++i)
            {
              EEPROM.write(32+i, qpass[i]);
              Serial.print("Wrote: ");
              Serial.println(qpass[i]); 
            }    
          EEPROM.commit();
          content = "{\"Success\":\"saved to eeprom... reset to boot into new wifi\"}";
          statusCode = 200;
        } else {
          content = "{\"Error\":\"404 not found\"}";
          statusCode = 404;
          Serial.println("Sending 404");
        }
        server.send(statusCode, "application/json", content);
    });
    

    } else if (webtype == 0) {
    server.on("/", {
    IPAddress ip = WiFi.localIP();
    String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
    server.send(200, "application/json", "{"IP":"" + ipStr + ""}");
    });
    server.on("/cleareeprom", {
    content = "<!DOCTYPE HTML>\r\n<html>";
    content += "<p>Clearing the EEPROM</p></html>";
    server.send(200, "text/html", content);
    Serial.println("clearing eeprom");
    for (int i = 0; i < 96; ++i) { EEPROM.write(i, 0); }
    EEPROM.commit();
    });
    }
    }

    void echolaser()
    {}

    void sender()
    {}

    void receiver()
    {}



  • Hello @marvin944

    please use the three backticks ``` if you want to include code.

    I saw several delay(5000). In general try to avoid very long delays or break them up in smaller chunks. The ESP8266 expects to get control back after some time. Otherwise some functions might not work correctly.
    7th Dwarf



  • @Seventh-Dwarf said in Constant crashes:

    I saw several delay(5000). In general try to avoid very long delays or break them up in smaller chunks. The ESP8266 expects to get control back after some time. Otherwise some functions might not work correctly.

    I think that delay() actually makes sure to feed the watchdog, so this shouldn't be the problem. Also, the message looks like a crash, not a watchdog reset -- so it's more likely something in the program itself.

    @marvin944 I would try with a simpler program, and if that works, gradually put back features until you find the piece that makes it crash.


Log in to reply
 

Looks like your connection to WEMOS Forum was lost, please wait while we try to reconnect.