HOW TO: BLYNK pinState Sync on Raspberry Pi (NodeJS)

This could be a lame question, but how can I get the pin states on a raspberry pi to sync with the Blynk App upon connection?

1 Like

Here commit adding sync. To be more specific :

Blynk.prototype.syncAll = function() {
       this.sendMsg(MsgType.HW_SYNC);
};

Blynk.prototype.syncVirtual = function(pin) {
  this.sendMsg(MsgType.HW_SYNC, ['vr', pin]);
};
1 Like

@Dmitriy, thanks for the snippet. However, when I tried it on my script, I’m getting the following error. Not sure whats wrong.

Snippet I used on my code:
Blynk.prototype.syncAll = function() {
this.sendMsg(MsgType.HW_SYNC);
};

Error I’m getting:
OnOff mode
Connecting to SSL: cloud.blynk.cc 8441
/home/pi/blynkScript.js:14
blynk.prototype.syncAll = function() {
^
TypeError: Cannot set property ‘syncAll’ of undefined
at Object. (/home/pi/blynkScript.js:14:25)
at Module._compile (module.js:460:26)
at Object.Module._extensions…js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

1 Like

You should use it as you did with with virtualWrite.

blynk.syncAll();

But I don’t know if you can register callbacks for result. @vshymanskyy may clarify.

1 Like

I believe if I want all my digital and virtual pins to be synced upon every successful connection made, I have to specify

blynk.syncAll(); right? Or should I specify something like
blynk.syncAll(PIN_NUMBER);?

1 Like

bump

:helicopter:

:telescope:

Does anyone know the workaround for blynk.syncALL for a Raspberry Pi? Sure would be nice to be able to have widgets synced at all times.

:pineapple:

Maybe JS library has to be updated, I’m not sure.
Sorry, I’m currently busy with some other tasks, so will check later.

1 Like

If we update the JS library, is it a simple/quick update or will this be a project that will take a considerable amount of time? I imagine it would take someone to know both languages, C++ and JavaScript, to effectively decipher and translate one script into the other.

It’s a shame we can’t run C++/Arduino script on the RPi (or can we??).
:cookie:

@aop you have been able to run the Arduino IDE on a Pi for a few years but this would still require an Arduino to be hooked up to a Pi.

sudo apt-get install arduino

I did try it out quite some time ago and it was ok.

More recently there was a project set up to actually run Arduino sketches on a Pi. I haven’t tried it but you can find details at https://www.raspberrypi.org/forums/viewtopic.php?f=33&t=134928 and the github at https://github.com/me-no-dev/RasPiArduino

I would be interested to know if anyone has tried this yet.

2 Likes

Hey @Costas

I did attempt to try the steps outlined in the

https://www.raspberrypi.org/forums/viewtopic.php?f=33&t=134928

link prior to my last post, but with no luck. I got all the programs downloaded and configured and went to compile/verify the default code on the Arduino IDE program and got an error, thus halting me in my tracks. If the code had went through, I would have attempted sending the binary file to the RPi to have it read but the IDE program did not like me.

Also important to point out is that my attempt took place on a Windows 10 operating system and that I went with the raspberry-gcc-4.9.2-r2.exe (433 MB) tool chain download.

Thanks for the blog link, I’ll check it out later when I get the time.

Let me know if you try running Arduino sketches on the Pi. I haven’t heard of anyone else having success with it here.

@vshymanskyy
What about Sync a pin on raspberry pi?

This command works just fine for me… synchronizes V1 in Node.js script.

blynk.syncVirtual(1);
2 Likes