I started messing around with the Esp8266 Template for Hardware Provisioning and managed to set up a dummy project that controlled a simple LED, and implemented the Blynk Provisioning Flow.
I connected the project for hours and had no problem with the provisioning or the Board automatically entering config mode on its own.
But then I added a DHT 11 sensor to the project that reads the values of Temp and Humidity and sends them to the app to be displayed in two Gauges. This is done with a BlynkTimer with 1 sec frequency.
When I added this the provisioning part started to fail. The board cannot stay connected more than 2 Hours before automatically entering config mode on its OWN and becoming a WiFi AP to start the provisioning process again.
Does anyone know about this issue? Maybe my board is sending to many values to the Blynk server (Temp and Humidity every 1 sec, only if they changed) and is getting disconnected and somehow entering config mode on its own.
I have set the value BUTTON_ACTIVE_LOW as FALSE in SETTINGS.H and grounded the Reset pin (in my case I set it to D5), so that cannot be the issue.
The board works fine when I comment out all of the DHT sensor code and only leave the LED blinking part, so this issue must have something to do with the sensor part of the code.
I’m glad if anyone can help me solve this issue.
This is the simple code in my sketch:
//define USE_SPARKFUN_BLYNK_BOARD // Uncomment the board you are using
#define USE_NODE_MCU_BOARD // Comment out the boards you are not using
//#define USE_WITTY_CLOUD_BOARD
//#define USE_CUSTOM_BOARD // For all other ESP8266-based boards -
// see "Custom board configuration" in Settings.h
#define APP_DEBUG // Comment this out to disable debug prints
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include "BlynkProvisioning.h"
#include <DHT.h>
#define DHTPIN 5 // What digital pin we're connected to: 5 (D1)
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void setup() {
delay(500);
pinMode(0,OUTPUT); //Sets Pin D3 as output pin for controlling the LED
digitalWrite(0,LOW); //Initializes D3 pin as LOW
Serial.begin(115200);
BlynkProvisioning.begin();
timer.setInterval(1000L, sendSensor);
}
void loop() {
// This handles the network and cloud connection
BlynkProvisioning.run();
timer.run();
}
BLYNK_WRITE(V1) {
int pinData = param.asInt();
if(pinData == 1) {
//When BUTTON 1 binded to V1 in APP is pressed then turn LED ON
digitalWrite(0,HIGH);
}
}
BLYNK_WRITE(V2) {
int pinData = param.asInt();
if(pinData == 1) {
//When BUTTON 2 binded to V2 in APP is pressed then turn LED OFF
digitalWrite(0,LOW);
}
}
float dh, dt = 0;
void sendSensor()
{
float h = dht.readHumidity();
delay(100);
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
} else {
//Only send value to server if Humidity differs from previous sent value
if(h != dh) {
dh = h;
Blynk.virtualWrite(V5, h);
}
//Only send value to server if Temperature differs from previous sent value
if(t != dt) {
dt = t;
Blynk.virtualWrite(V6, t);
}
}
}