blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.84k stars 1.39k forks source link

Do syncAll() on every re-connection #330

Closed MLXXXp closed 7 years ago

MLXXXp commented 7 years ago

Description

In example sketch HardwareSyncStateFromApp, perform a syncAll() on every re-connection, via BLYNK_CONNECTED(), not just the upon the initial connection.

Issues Resolved

Using the code in this example, if a device that was previously connected to the server loses connection, and then the value of a widget is updated in the app while the device's connection is still down, syncAll() should be called to cause an update to the new value upon device re-connection. This wasn't happening because there was code to use a semaphore flag, isFirstConnect, to only call syncAll() upon the initial connection.

Note:

The example in the Blynk documentation should also be updated to always do the syncAll() and not have if (isFirstConnect) {, to match these modificatons made to the HardwareSyncStateFromApp example sketch.

pieman64 commented 7 years ago

@MLXXXp looks like a sensible amendment to the existing examples. What do you think @doom369 ?

doom369 commented 7 years ago

Not sure. The example does what it should. Maybe it is better just add one more example. @vshymanskyy WDYT?

pieman64 commented 7 years ago

@doom369 it doesn't do what novice Blynkers think it does i.e. sync. It only sync's on the first connection and most MCU's will reconnect at some stage, and NOT sync. See https://community.blynk.cc/t/solved-why-sync-pins-only-on-the-first-connect/14903 for details.

doom369 commented 7 years ago

@pieman64 agree.

pieman64 commented 7 years ago

Thanks @doom369 Is Sketch Builder dynamically linked in some way to the GitHub examples?

doom369 commented 7 years ago

@MLXXXp thanks!

doom369 commented 7 years ago

@pieman64 nope...