Title: Watchdog Timeouts and Communication Issues with Bidirectional Data Flow on ESP8266
Hello Blynk Community,
I’m a new Plus Blynk user and recently migrated from another IoT cloud service. The transition was smooth, and I’m really impressed with the performance and UI in Blynk. However, I’ve run into some issues when implementing a bidirectional data flow between my Blynk UI and my device.
Project Overview:
- Device: Custom-built weather station
- Hardware: Currently using ESP8266 (Wemos D1 mini), planning to upgrade to ESP32
- Objective: To reset timers for measurements and displays from the Blynk UI, aiming to conserve battery power with ESP deep sleep between measurements.
The Issue:
When I send data from Blynk to the device, I encounter multiple problems:
- Watchdog Timeouts
- Wi-fi Communication issues
- Device crashes and reboots
Interestingly, commenting out the code that sends data from Blynk to the device resolves these issues.
Suspected Cause:
I suspect the issue lies in my misunderstanding of how timers work in the Blynk ecosystem.
Questions:
- How do I effectively manage timers to prevent these issues?
- Are there any best practices for sending data from Blynk to the device to prevent timeouts and crashes?
I appreciate any help and feedback from the community. Thank you!
Relevant Code:
Here is the relevant portion of my code that handles the Blynk to device communication.
#define BLYNK_TEMPLATE_ID "#######"
#define BLYNK_TEMPLATE_NAME "#######"
#define BLYNK_AUTH_TOKEN "#######"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LittleFS.h>
#include "DHT.h"
#include <Wire.h>
#include <eloquent.h>
#include <UrlEncode.h>
#include "RunningAverage.h"
#include "SparkFun_AS3935.h"
#include <Adafruit_BMP280.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_MLX90614.h>
// Global variables
const long datasetinterval = 1 * 60; // minutes
long measureinterval = 1; // minutes
long loopinterval = measureinterval * 60 * 1000; //loop of measureinterval minutes in milliseconds
long sleepinterval = 2 * 60 * 1000; // miliseconds
// Your WiFi credentials.
char ssid[] = "#######";
char pass[] = "#######";
BlynkTimer timer;
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
const long timeIntervals[] = {60000L, 300000L, 900000L, 1800000L, 3600000L}; // 1 min, 5 min, 15 min, 30 min, 1 hour in milliseconds
BLYNK_WRITE(V0)
{
Serial.println("Blynk.Cloud is writing something...");
int value = param.asInt();
if (value >= 0 && value <= 4) {
Serial.print("Setting interval to ");
Serial.print(timeIntervals[value] / 60000L);
Serial.println(" minutes");
measureinterval = timeIntervals[value] / 60000L; // Convert back to minutes
loopinterval = timeIntervals[value]; // Already in milliseconds
sleepinterval = timeIntervals[value]; // Already in milliseconds
int newBufferSize = datasetinterval / measureinterval;
initializeRunningAverageBuffers(newBufferSize); // Resize the running average buffers
timer.setInterval(timeIntervals[value], timer1);
timer.setInterval(timeIntervals[value], timer2);
} else {
Serial.println("Invalid value");
}
}
void timer1()
{
updateSensorReadings(t, p, h, c);
updateBuffers(t, p, h, c);
printSensorValues(t, p, h, c);
makeRainPredictionAndSendMessage(t, p, h, c);
detectLightning();
measureBattery();
//loopCounter++; // Increment the counter
//if (loopCounter >= n) { // If we've looped n times
// Put Wemos D1 Mini to sleep (time is in microseconds)
// Serial.println("Going to sleep");
// ESP.deepSleep(sleepinterval * 1000);
//}
//}
}
void timer2()
{
Blynk.virtualWrite(V1, t);
Blynk.virtualWrite(V2, p);
Blynk.virtualWrite(V3, h);
Blynk.virtualWrite(V4, c);
Blynk.virtualWrite(V5, ot);
Blynk.virtualWrite(V6, at);
Blynk.virtualWrite(V7, bat_percentage);
Blynk.virtualWrite(V8, prob[0]*100.0);
Blynk.virtualWrite(V9, prob[1]*100.0);
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(60000L, timer1);
timer.setInterval(60000L, timer2);
initializeSensors();
initializeRunningAverageBuffers((datasetinterval / measureinterval));
Serial.println(ESP.getResetInfo());
}
void loop()
{
timer.run();
Blynk.run();
}