I want to show some digits in a 3x3 p10 red led pannel where the number will come from the cloud and the number keeps updating. For this I have used esp8266 based Nodemcu. I have used WiFi Manager library and DMD2 library for this and I am requesting the server every 5 seconds to get the number in response. Everything is working fine but it keeps restarting after some time and there is no fixed timing for this but it keeps restarting. It provides a message that "reset cause 4 boot mode(3,6)" wdt reset... I have tried different hardware and esp board version but nothing is working. I am currently using arduino 1.8.9 and esp8266 board version 2.5.2

please look into my code and suggest me what is wrong....

#include <Arduino.h>

#include <WiFiManager.h>
#include <math.h> #include <WiFiClient.h> #include <ESP8266HTTPClient.h> #include <EEPROM.h> #include <ESP8266WiFi.h>

WiFiManager wifiManager; int countT;

HTTPClient http; String svrHost = ""; unsigned int svrPort = 80; String svrURL = "";

//DMD #include <SPI.h> #include <DMD2.h> #include <fonts/Arial_Black_16.h> #include <fonts/Droid_Sans_36.h> #include <fonts/Droid_Sans_12.h> #include <fonts/Arial_New_56.h> //#include <fonts/Dmd13x20ClockX.h> //DMD PIN #define pin_A 16 #define pin_B 12 #define pin_sclk 0 #define pin_clk 14 #define pin_r 13 #define pin_noe 15

int respin = D2; int btnstt = 0;

int wlcmgs = 1; String ssid;

String dmdText = "0"; SPIDMD dmd(3, 3, pin_noe, pin_A, pin_B, pin_sclk); // Number of P10 panels used X, Y //DMD_TextBox box(dmd,0,0,32,5); // Set Box (dmd, x, y, Height, Width)

//const char *MESSAGE = "iTrack LIVE InWard";

void setup(){ Serial.begin(115200); EEPROM.begin(512); pinMode(respin, INPUT);

//Reset Val
String doResetWifi = "0";
doResetWifi = readESP(257,1);

if(doResetWifi == "1"){

Serial.println("\nReset Val "+doResetWifi);
countT = 0;  
Serial.println("connected...yeey :)");

//Read/Write EPROM    
if(wifiManager.svrURL != ""){
    svrHost = wifiManager.svrHost;
    svrPort = wifiManager.svrPort;
    svrURL = wifiManager.svrURL;



    svrHost = readESP(0,50);

    svrPort = readESP(51,25).toInt();

    svrURL = readESP(56,200);

//DMD Setup
    dmd.setBrightness(255); // Set brightness 0 - 255 
    //dmd.selectFont(Droid_Sans_36); // Font used
    dmd.begin();     // Start DMD 


void loop(){

btnstt = digitalRead(respin);

if (btnstt == 1){ flashESP(); ESP.reset(); } doRequest();


if(wlcmgs==1){ dmd.selectFont(Droid_Sans_12); dmd.drawString(0,0,"Connected"); delay(5000); dmd.clearScreen(); //scrlssid(); delay(5000); wlcmgs=0; }

dmd.clearScreen(); dmd.selectFont(Arial_New_56); int padingTop = 2;

dmd.drawString(round((96 - (dmdText.length() * 24)) / 2), padingTop, dmdText);

delay(1000 * 5);

//dmd.selectFont(Arial_Black_16); //scrtxt(); }

void doRequest(){
Serial.print("[HTTP] begin: "+svrHost+" "+svrPort+" "+svrURL+"\n"); String response; if (httpRequest(svrHost, svrPort, String("GET /") + svrURL, "", response)) { if (response.length() != 0) {

        dmdText = response;


bool httpRequest(const String svrHOST, unsigned int svrPORT, const String& method, const String& request, String& response) { WiFiClient client;

if (client.connect(svrHOST, svrPORT)) {
    Serial.println("HTTP Connected");
} else {
    return false;

client.println(F(" HTTP/1.1"));
client.print(F("Host: ")); 
client.println(F("Connection: close"));
if (request.length()) {
    client.println(F("Content-Type: application/json"));
    client.print(F("Content-Length: ")); 
} else {

//Serial.println("Waiting response");
int timeout = millis() + 5000;
while (client.available() == 0) {
    if (timeout - millis() < 0) {
        Serial.println(">>> Client Timeout !");
        return false;

//Serial.println("Reading response");
int contentLength = -1;
while (client.available()) {  
    String line = client.readStringUntil('\n');
    if (line.startsWith("content-length:")) {
        contentLength = line.substring(line.lastIndexOf(':') + 1).toInt();
    } else if (line.length() == 0) {

//Serial.println("Reading response body");
response = "";
response.reserve(contentLength + 1);
while (response.length() < contentLength && client.connected()) {
    while (client.available()) {
        char c = client.read();
        response += c;
return true;


void writeESP(int start, int len, String text){ EEPROM.begin(512); int ind; for(ind = 0; ind < len; ind++){
EEPROM.write(ind+start,text[ind]); } EEPROM.write(ind+start+text.length(),'\0');


EEPROM.end(); }

String readESP(int start, int len){ EEPROM.begin(512); char dataS[len]; int ind; for(ind = 0; ind < len; ind++){ if(EEPROM.read(ind+start) != '\0'){ dataS[ind] = EEPROM.read(ind+start); }else{ break; } } dataS[ind]='\0'; EEPROM.end(); return String(dataS); }

void flashESP(){ Serial.print("\nResetting ESP\n"); writeESP(257,1,"1"); ESP.reset(); delay(2000); }

/* void scrtxt(){ const char *next = MESSAGE; while(*next) { Serial.print(*next); box.print(*next); delay(200); next++; } } / / void scrlssid(){ dmd.drawString(5,0,"Connected With"); DMD_TextBox box(dmd,0,20,96,16); ssid = WiFi.SSID(); const char *ssidNext= ssid.c_str(); int len = 0; while(ssidNext && len < ssid.length()){ Serial.print(*ssidNext); box.print(*ssidNext); delay(200); ssidNext++; len++; } } */

  • Welcome Angkon. Align your code (select and ctrl-k), and remove any code that doesn't cause the reset (try removing parts until it doesn't reset anymore, so you also can find out yourself what is the problem). – Michel Keijzers Oct 14 '20 at 9:43
  • You have a watchdog timeout. That is caused by your code blocking and not "kicking the dog" enough. You should check for parts of your code that do nothing for long periods of time and regularly yield() so that the IP stack can do its work. – Majenko Oct 14 '20 at 10:40

From your description it sounds like a Watchdog Timer reset.

The ESP8266 needs to regularly run internal householding tasks outside of your own code, such as Wifi/network related tasks. It will normally take some processing time for those tasks with every loop() iteration and with every delay() command.

If your code is doing things that take longer than about 3.2 seconds, the internal "watchdog timer" will time out and reset the ESP, which is what you observed.

To ensure this does not happen, you should put a yield(); command inside pieces of your code that can potentially take longer than 3 seconds, like waiting loops (for example the "Waiting response" while() loop and similar pieces of your code). Try this and see if this solves your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.