Problem with synchronizing pin states when re-launching the Blynk app (Particle Core)

Hello, I am having the following issue. I have a Particle Core which monitors several digital pin states which are displayed in the app by LED widgets. The app also has several buttons which pass on some commands to the Core. Everything is working fine, I can interrogate the button presses from the core via virtual pins and state changes HIGH to LOW and vice versa on the monitored hardware pins on the core are correctly displayed in the LED widgets.

So far so good, the issue is when I leave the app and re-open it, or alternatively, open the same dashboard on a different phone, initially all LEDs that should be ON (i.e. representing a hardware pin in HIGH state), are off, even though the actual pin is HIGH. This means that the correct state of each LED widget is only displayed after it has changed once while the app is running. Curiously, a similar sketch on an Arduino Ethernet seems to work fine, meaning that, for example, a pin that is in HIGH state, will also be displayed correctly by the LED widget, even if I close and re-launch the app. Has anyone had a similar problem?

Hello. Do you use android or ios?

I reported this a few days back

Apparently it’s been fixed but it still happens to me and the same result if you don’t use the app for a couple of hours😕

Hello, I use IOS (version 9.2)

Hi Dimitriy, I use IOS 9.2.1.

In the meantime I have read about State Syncing (link to the relevant sections on docs.blynk.cc). There you distinguish between “For hardware” and “For app”.

If I understand, the former would be to re-set hardware, e.g. pin states, according to what is set (“remembered”) by the app. So, in my case, this would not apply, since the “app-side” seems to forget what states the hardware side was in.

The description of the “For app” seems to apply to my problem, i.e. the app not showing the actual hardware/pin states after the app had been turned off. So apparently I need to use a Blynk.virtualWrite call for each state that is shown in the app in order to re-set the actual states there. This brings me to the following questions.

(1) Let’s assume the app had been closed or turned off, or the app/dashboard has been opened on a different phone. How does the hardware side “know” when to make the (series of) Blynk.virtualWrite calls, in other words, how does the hardware side get to know when the app has been re-started or the same dashboard has been opened on another device?

(2) For the moment my app uses eight momentary push buttons and seven LED widgets. This means that in this setting I already would need to update 15 button states. In what frequency can I make Blynk.virtualWrite calls? Would it be feasible to have something like that?

void SynchStates() {
  if (digitalRead(pin1) = HIGH) LED1.on() else LED1.off();    // for the LED widgets
  if (digitalRead(pin2) = HIGH) LED2.on() else LED2.off();
  ...
  ...
  if (digitalRead(pin14) = HIGH) Blynk.virtualWrite(V14, HIGH) else Blynk.virtualWrite(V14, LOW);    // for the button/switch widgets
  if (digitalRead(pin15) = HIGH) Blynk.virtualWrite(V15, HIGH) else Blynk.virtualWrite(V15, HIGH);;
}

If this is the intended use described in the “For app” section, can I make 15 consecutive “Blynk…” calls, i.e. directly one after the other without any delay between them, and by this not causing a “Flood Error” (making too many calls in a given time frame).

(3) For the moment I am often combining push-type buttons with an LED widget to indicate the corresponding status on the hardware side. The combination button/LED widget is necessary because in parallel with the software buttons in the app I have hardware buttons actuating a particular state on the hardware side. Therefore, I have the LED to indicate the actual state which might have changed through a hardware button press (therefore, the “combo” widget of a button and an LED, as proposed elsewhere in the forum, makes absolutely sense). Could I use instead a switch-type button in the app, and use a “Blynk.virtualWrite(Vxx, HIGH/LOW)” call (e.g. whenever a hardware button is pressed) in order to set the button state in the app, which would then reflect the actual state on the hardware side? by this way, the accompanying LED widget would not be necessary anymore, saving me both a virtual pin plus precious space on the app screen?

An additional remark: it seems that the Particle library does not have the sync feature implemented. I wanted to try the Sync.ino example described on the http://docs.blynk.cc/page, using the online Particle IDE, but this results in an error messages saying something like

blynk_sync_test.cpp:45:17: error: ISO C++ forbids declaration of 'BLYNK_CONNECTED' with no type [-fpermissive]

blynk_sync_test.cpp:47:11: error: 'class BlynkParticle' has no member named 'syncAll' bool isFirstConnect = true;
.

Hello. Well, first of all, iOS app at the moment has bug you described “the app not showing the actual hardware/pin states after the app had been turned off”. This works fine on Android and will be fixed in next iOS update.

At the moment there is no way to find out this.

It depends only of your hardware. Our server limitation is 100 req/sec. Your code is ok.

I think yes. You need to experiment a bit with this to find best approach that fits your needs.

Yes, update will done very soon.

Hey Dimitriy,

thanks very much for your quick and detailed replies.

1 Like

I think Im running the same problem described here in my implementation:

But The buttons who lose the sync in my case are only the ones connected to analog output pin.

I want to know if this was fixed or not?

Thanks