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

Moderator: igrr

User avatar
By antinym
#68630 As soon as my esp connects to the wifi it freezes and it looks like the wdt makes it reset.
Sometimes it'll connect and stay up for 16 hours, but then it'll go into this boot loop. Most of the time it won't.

Any one know why that might be?
details:
wemos D1 mini v2.3.0
powered on USB from 2.1amp charger with 1000uF cap on the 3.3v
Github esp8266/arduino 2.3.0
arduinoIDE v1.8.3

Here's the error:
Code: Select all...
EAP-PEAP: received 53 bytes encrypted data for Phase 2
EAP-PEAP: received Phase 2: code=1 identifier=149 length=24
EAP-PEAP: Phase 2 Request: type=1
EAP-PEAP: received 69 bytes encrypted data for Phase 2
EAP-PEAP: received Phase 2: code=1 identifier=150 length=34
EAP-PEAP: Phase 2 Request: type=26
EAP-PEAP: Selected Phase 2 EAP vendor 0 method 26
EAP-MSCHAPV2: RX identifier 150 mschapv2_id 150
EAP-MSCHAPV2: Generate Challenge Response
EAP-PEAP: received 85 bytes encrypted data for Phase 2
EAP-PEAP: received Phase 2: code=1 identifier=151 length=51
EAP-PEAP: Phase 2 Request: type=26
EAP-MSCHAPV2: RX identifier 151 mschapv2_id 150
EAP-PEAP: received 37 bytes encrypted data for Phase 2
EAP-PEAP: received Phase 2: code=1 identifier=152 length=11
EAP-PEAP: Phase 2 Request: type=33

connected with MCS, channel 1

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 6
cnt
...


Here's my code:
Code: Select allint DEBUGLEVEL = 4;
bool TESTDATA = false; //Send Test data instead of real data
//#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
//#include <WiFiUdp.h>
//#include <ESP8266Ping.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <SoftwareSerial.h>
#include <TimeLib.h>

#ifdef ESP8266
extern "C" {
#include "user_interface.h"
#include "wpa2_enterprise.h"
}
#endif
SoftwareSerial BTSerial(D7, D8); // RX | TX

/* #include <ESP8266mDNS.h>
MDNSResponder mdns;
 */

static const char* ssid = "MCS";
static const char* username = "xxx";
static const char* password = "yyy";
static const char* host = "zzz";

ESP8266WebServer server(80);
WiFiClient client;
 
int delaytime = 500;
bool initpresence = true; //initalize the lights
bool partymode = false;
unsigned long cmdSentTime = millis();
int presstage = 0;

//PubSubClient \MQTTclient(client);
long lastMsg = 0;
const char* mqtt_server = "192.168.1.7";
char msg[75];

//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 2
WiFiServer telserver(29001);
WiFiClient serverClients[MAX_SRV_CLIENTS];

void setup(){
   Serial.begin(115200);
   Serial.setDebugOutput(1);

   Serial.println();
   BTSerial.begin(38400);  // HC-05 default speed in AT command more
   BTSerial.print("\r");
   BTSerial.println("AT+INIT");
   delay(delaytime);
   clearSerial();
   Serial.println(__DATE__);
   Serial.println(__TIME__);
   Serial.println(__FILE__);
   Serial.println("setup complete !");
}
void loop(){
   server.handleClient();
   wpaconnect();   
}


void wpaconnect(){
   static int wpastate = 0;
   switch(wpastate){
   case 0:
      // Setting ESP into STATION mode only (no AP mode or dual mode)
      Serial.println("Starting WPA");
      wifi_set_opmode(STATION_MODE);
      struct station_config wifi_config;
      memset(&wifi_config, 0, sizeof(wifi_config));
      strcpy((char*)wifi_config.ssid, ssid);
      wifi_station_set_config(&wifi_config);
      wifi_station_clear_cert_key();
      wifi_station_clear_enterprise_ca_cert();
      wifi_station_set_wpa2_enterprise_auth(1);
      wifi_station_set_enterprise_username((uint8*)username, strlen(username));
      wifi_station_set_enterprise_password((uint8*)password, strlen(password));
      wifi_station_connect();
      wpastate++;
      break;
   case 1:
      static unsigned long wpatimer = millis();
      // Wait for connection AND IP address from DHCP
      if (WiFi.status() != WL_CONNECTED) {
         if (millis() -wpatimer> 1000){
            wpatimer = millis();
            Serial.print(".");
         }
      }
      else wpastate++;
      break;
   case 2:
      Serial.println ( "" );
      Serial.print ( "Connected to " );
      Serial.println ( ssid );
      Serial.print ( "IP address: " );
      Serial.println ( WiFi.localIP() );
      Serial.print ( "Time to wifi (seconds): " );
      Serial.println ( millis()/1000.00 );
      
/*        if (mdns.begin(host, WiFi.localIP())) {
         Serial.println("MDNS responder started");
      }  */

      server.on ( "/", handleRoot );
      server.on ( "/test.svg", drawGraph );
      server.on ( "/inline", []() {
         server.send ( 200, "text/plain", "this works as well" );
      } );
      server.onNotFound ( handleNotFound );
      server.begin();

      telserver.begin();
      telserver.setNoDelay(true);

      ArduinoOTA.setHostname(host);
      ArduinoOTA.onStart([]() {
         Serial.println("Start");
      });
      ArduinoOTA.onEnd([]() {
         Serial.println("\nEnd");
      });
      ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
         Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
      });
      ArduinoOTA.onError([](ota_error_t error) {
         Serial.printf("Error[%u]: ", error);
         if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
         else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
         else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
         else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
         else if (error == OTA_END_ERROR) Serial.println("End Failed");
      });
      ArduinoOTA.begin();
      Serial.println("OTA Setup");
      Serial.println("Ready");
      wpastate++;
      break;
   default:
      break;
   }
}
User avatar
By QuickFix
#68642 In case of regular or unexplainable watchdog resets, implement (more) yields inside code (like loops) that might hang because of network congestion.
User avatar
By QuickFix
#68660 The way I see it, perhaps a yield (or a short delay) at the end of the loop *might* just do the trick.
Code: Select allvoid loop(){
   server.handleClient();
   wpaconnect();   
   yield();
}

I might be wrong, but effectively you have a loop while the state is between wifi_station_connect() (in case 0) and the actual connection (in case 1).
In effect, the code (until connection) looks like this:
Code: Select all  wifi_station_connect(); // in case 0

  server.handleClient(); // in loop()

  if (WiFi.status() != WL_CONNECTED) { // in case 1
    if (millis() -wpatimer> 1000){
       wpatimer = millis();
    }

  server.handleClient(); // in loop()

  if (WiFi.status() != WL_CONNECTED) { // in case 1
    if (millis() -wpatimer> 1000){
       wpatimer = millis();
    }

  [...] Rinse and repeat [...]
But again: that's just my guess, so I could be entirely wrong. 8-)