Esp8266 crashing

Hey All,
I'm running some code on a generic esp8266 and it crashes every few minuets.

I get the following error in the console

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (0):
epc1=0x4021cf9b epc2=0x00000000 epc3=0x4021da19 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffec80 end: 3fffffb0 offset: 0150
3fffedd0:  40223ca1 3fffee90 3ffedc80 0000001c  
3fffede0:  3ffed5f0 3fffee90 3ffedc80 0000001c  
3fffedf0:  402216e4 3fffee90 3ffedb28 3ffed520  
3fffee00:  3ffeb9c0 3fffee90 3fffee90 00000001  
3fffee10:  64646f74 1d006946 40103642 00000000  
3fffee20:  00000000 0000001f 40100188 00000001  
3fffee30:  4021da3d 3fffc228 40105f51 4000050c  
3fffee40:  ffffffe5 3ffed63c 3ffeb9d0 3ffedc80  
3fffee50:  3ffecc20 00000045 00000000 402223df  
3fffee60:  00000000 3ffef3f4 ffffffe5 00000000  
3fffee70:  00000000 3ffedc80 00000000 0000000f  
3fffee80:  3fffc6fc 00000001 a70440cb 00000000  

this goes on for many lines and then

<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

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

wdt reset
load 0x4010f000, len 3424, room 16 
tail 0
chksum 0x3e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x3b
csum 0x3b
csum err

I'd paste my code but it's in tabs so I've attached the file. Note this code has worked fine in the past.
share.zip (5.5 KB)

I have a small capacitor on the bread board. I've watched the voltage with my multimeter and the board is getting a solid unwavering 5.1v with 3A available.

How can I get this to stabalize?
Thanks
Rich

Cause 4 is a watch dog timer reset. If you run the exception decoder it will give a clue where the problem is. The usual cause is a loop that takes too long.

is there a way to copy and paste all of the tabs?

+1 for using the exception decoder.

This might be worth a read as it has links tp the decoder and also mentions the is a quirk in IDE2.x.x which I also ran into:

^Exception decoder

You will need to expand the output area to big enough to be able to view and highlight the entire text to copy.

Without seeing your code its pointless

// coded for Feather Huzzah
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <LEDFader.h>
#include <stdlib.h>
#include <ArduinoJson.h>  // https://github.com/bblanchon/ArduinoJson

#define LED_PIN 4
#define LED_PIN2 12
#define LED_PIN3 14
#define LED_PIN4 15

int modeBrightness = 2;
int fadeSpeed = 250;

char message_buff[100];

#define FADE_UP_TIME 100
#define FADE_DOWN_TIME 500
#define FADE_TIME 3000

#define DIR_UP 4
#define DIR_DOWN -1

LEDFader led;
LEDFader led2;
LEDFader led3;
LEDFader led4;

int direction = DIR_UP;
uint16_t lastModeBrightness = 0;

int brightness = 0;
int lastBrightness = 0;

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;

unsigned long currentMillisTemps = 0;
unsigned long previousMillisTemps = 0;  // will store last time LED was updated
const long intervalTemps = 3000;

// Update these with values suitable for your network.
// NOT FOR PUBLIC CONSUMPTION

WiFiClient espClient;
PubSubClient client(espClient);
void loop() {
  // led.update();
  led2.update();
  led3.update();
  led4.update();

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

}
void ledControl(char* topic, byte* payload, unsigned int length) {
  StaticJsonDocument<256> doc;  // Allocate memory for the doc array.
  deserializeJson(doc, payload, length);

  // Serial.print("Message arrived: ["); Serial.print(topic); Serial.println("]");             // Prints out anything that's arrived from broker and from the topic that we've subscribed to.

  int i;
  for (i = 0; i < length; i++) message_buff[i] = payload[i];
  message_buff[i] = '\0';  // We copy payload to message_buff because we can't make a string out of payload.
  String modeBrightness = String(message_buff);
  modeBrightness = modeBrightness.toInt();

  if (strcmp(topic, "/apartmentBrightLights/restart") == 0) {  // Returns 0 if the strings are equal, so we have received our topic.
    // uint16_t modeBrightness = doc["restart"];
    Serial.print("RESTART ");
    ESP.restart();
  }

  if (strcmp(topic, "/apartmentBrightLights/lamp1") == 0) {  // Returns 0 if the strings are equal, so we have received our topic.
    uint16_t modeBrightness = doc["lamp1"];
    Serial.print("lamp1: ");
    Serial.println(modeBrightness);
    led.fade(modeBrightness, fadeSpeed);
  }
  if (strcmp(topic, "/apartmentBrightLights/lamp2") == 0) {  // Returns 0 if the strings are equal, so we have received our topic.
    uint16_t modeBrightness = doc["lamp2"];
    Serial.print("lamp2: ");
    Serial.println(modeBrightness);
    led2.fade(modeBrightness, fadeSpeed);
  }
  if (strcmp(topic, "/apartmentBrightLights/lamp3") == 0) {  // Returns 0 if the strings are equal, so we have received our topic.
    uint16_t modeBrightness = doc["lamp3"];
    Serial.print("lamp3: ");
    Serial.println(modeBrightness);
    led3.fade(modeBrightness, fadeSpeed);
  }
  if (strcmp(topic, "/apartmentBrightLights/lamp4") == 0) {  // Returns 0 if the strings are equal, so we have received our topic.
    uint16_t modeBrightness = doc["lamp4"];
    Serial.print("lamp4: ");
    Serial.println(modeBrightness);
    led4.fade(modeBrightness, fadeSpeed);
  }
}
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    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("/apartmentBrightLights/restart", "Reconnected to Apartment Bright Lights");
      client.subscribe("/apartmentBrightLights/lamp1");
      client.subscribe("/apartmentBrightLights/lamp2");
      client.subscribe("/apartmentBrightLights/lamp3");
      client.subscribe("/apartmentBrightLights/lamp4");
      client.subscribe("/apartmentBrightLights/restart");

    } 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() {

  Serial.begin(115200);
  setup_wifi();

  client.setServer(mqtt_server, 1883);
  client.setCallback(ledControl);  //callback

  pinMode(4, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);

  led = LEDFader(LED_PIN);
  led.fade(0, 250);

  led2 = LEDFader(LED_PIN2);
  led2.fade(0, 250);
  
  led3 = LEDFader(LED_PIN3);
  led3.fade(0, 250);

  led4 = LEDFader(LED_PIN4);
  led4.fade(0, 250);

  Serial.println("Apartment Bright Lights 3/21/2024 - this script is configured for generic esp8266");

}
void setup_wifi() { 

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

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  WiFi.hostname("APARTMENT_BRIGHT_LIGHTS");

  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());
}

Also why is your loop before the setup?

because it came from tabs

I stopped using pin 4 and it seems to be stable!
Thank you oldcurmudgeon

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.