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