- I can’t find ANY reference to V28 nor V29 in your code, which is probably the cause!
- have absolutely no idead what you’re saying
- great, so what’s the issue?
- yes… thats a familiar issue with esp’s and blynk. Most of the time they don’t actually disconnect, but they loose heartbeat which cause a ‘disconnect’ (it takes too long for the code to send a ‘I’m still alive’ to blynk. This is usually the result of either VERY long routines, stacking timers or delay()'s.
This is a nice example of stacking timers, check this out.
timer.setInterval(1000L, clockDisplay);
timer.setInterval(1000L, rolevelSENSOR);
timer.setInterval(1000L, moistureSENSOR);
timer.setInterval(1000L, sendSensor);
timer.setInterval(1000L, rainSensor);
furthermore…here’s a nice example of indentations going all over the place making code unreadable and thus errorprone:
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
if(h >= humLowTrigger)
{
digitalWrite(FOGGERPIN, LOW);
Blynk.virtualWrite(FOGGERLED, LOW);
}
else {
digitalWrite(FOGGERPIN, HIGH);
Blynk.virtualWrite(FOGGERLED, HIGH);
}
Serial.println(h);
Serial.println(t);
}
FIX THIS!! You’ll thank me later (and not only the example, your entire code!!
In case you have no idea what I’m talking about, here a correct example:
void reconnectBlynk() {
if (!Blynk.connected()) {
if(Blynk.connect()) {
BLYNK_LOG("Reconnected");
isFirstConnect = true;
} else {
BLYNK_LOG("Not reconnected");
}
}
}
or (matter of taste)
void reconnectBlynk()
{
if (!Blynk.connected())
{
if(Blynk.connect())
{
BLYNK_LOG("Reconnected");
isFirstConnect = true;
}
else
{
BLYNK_LOG("Not reconnected");
}
}
}
and as it happens, that example is also very useful to get blynk reconnected!! Put the function on a e.g. 30s timer (so it runs every 30s) which helps with the reconnect.