When I upload my code , after 3 iterations of the loop() , I get an soft wdt reset and the NodeMCU restarts. It happens everytime. What would be the error ?
#include <dummy.h>
#include <elapsedMillis.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example.
#define FIREBASE_HOST "plugmatebeta.firebaseio.com"
#define FIREBASE_AUTH "zQtW9gVXzNuz1tD8OzaTCoFpIx7MbFjwyncsWnGC"
#define WIFI_SSID "6LowPAN"
#define WIFI_PASSWORD "rashmin0703"
#define WifiAlertLED D3
#define pushButton D6
#define outsideButton D7
#define relay D8
#define connectedLED D2
void setup() {
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting: ");
delay(5000);
// while (WiFi.status()!=WL_CONNECTED){
// Serial.print(".");
// delay(100);
// }
// Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
// delay(1000);
pinMode(WifiAlertLED,OUTPUT);
pinMode(connectedLED,OUTPUT);
pinMode(pushButton,INPUT);
pinMode(outsideButton,INPUT);
pinMode(relay,OUTPUT);
}
void loop() {
if (WiFi.status() != WL_CONNECTED){
digitalWrite(connectedLED, LOW);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
BlinkLED();
controlOne();
delay(1000);
}
else{
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
delay(500);
Serial.println("inside connected");
controlTwo();
}
}
void BlinkLED(){
digitalWrite(WifiAlertLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(WifiAlertLED, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
void controlOne(){
if ((digitalRead(pushButton) == HIGH) && (digitalRead(outsideButton)==HIGH) ){
digitalWrite(relay, HIGH);
Serial.println("on");
}else{
digitalWrite(relay, LOW);
Serial.println("off");
}
}
void controlTwo(){
String firebaseResult = firebaseAction();
if ((digitalRead(pushButton) == HIGH) && ( (firebaseResult=="1") || (digitalRead(outsideButton)==HIGH) ) ){
digitalWrite(relay, HIGH);
Serial.println("onnnnnnnnn");
publishtoFirebase("ON");
}else{
digitalWrite(relay, LOW);
Serial.println("onnnnnnnnn");
publishtoFirebase("OFF");
}
}
String firebaseAction(){
String x =Firebase.getString("/plgm8-1/command");
yield();
delay(200);
Serial.println(x);
return x;
delay(100);
}
void publishtoFirebase(String x){
Firebase.setString("/plgm8-1/status", x);
delay(200);
yield();
}
I tried searching for errors regarding , soft wdt reset more , but it seems like the resources are very low. Is it a problem with the timer of the NodeMCU ?
setup()
, and only include the execution in theloop()
. For example, WiFi only need to setup once, not every loop. BTW, what is thewhile..loop
that is comment-out in thesetup()
? it shouldn't be there at all. – hcheung