Hi!
I´m quite new to Blynk and it works great so far. But in some cases i would need a feedback from Server, if my board has succesfully sent data to the server.
In my project i don´t use the void loop, as my controller sleeps the most time and only wakes up to sync data with the server. That’s working fine. I have created a connection routine that ensures all pins i need and the RTC are syncronised to the server like:
Stay as long in BLYNK_CONNECTED untill everything is syncronised…
BLYNK_CONNECTED()
{ int timeouttime =millis();
Serial.println("getting Server time..");
rtc.begin();
while(year() == 1970)
{
Blynk.run();
if(millis()>(timeouttime+5000))
{
Serial.println("Timeout time sync go to sleep..");
ESP.deepSleep(15*6e7);
delay(100);
}
}
Serial.println("Server IOs sync..");
syncIO(flag_PinV5SyncOK, V5);
}
function to sync IOs:
void syncIO(int &flag, int pin)
{
int timeouttime =millis();
Blynk.syncVirtual(pin);
while(flag != 1)
{
Blynk.run();
if(millis()>(timeouttime+5000))
{
Serial.print("Sync Pin V");
Serial.print(pin);
Serial.println(" timeout");
ESP.deepSleep(10*6e7);
delay(100);
}
}
Serial.print("Sync Pin V");
Serial.print(pin);
Serial.println(" OK");
}
Add flag for every BLYNK_WRITE to know if BLYNK was there:
BLYNK_WRITE(V5)
{
flag_PinV5SyncOK = 1;
KeepAwake = param.asInt();
}
It´s more a workaround but it’s working. Now i want to send diagnostic messages as push notification. But when i’m calling Blynk.notify("") right before the next sleep, it happens that the controller goes to sleep without sending. I used a 5s time loop with Blynk.run() after Blynk.notify and it works, but that´s not a good practice as i cannot be sure that the diagnostic message is really sent before sleep…
What i’m looking for is something like a ping from the server, so that i can run Blynk.run() for serveral answers from the server and then go to sleep… I already found out that it`s important to run Blynk.run() at least every 10s because otherwise Heartbeat will disconnect the Server… Is there a way to use BLYNK_HEARTBEAT?
best regards