@rocketfool
Awhile back I dove head first into the whole Blynk on RPi thing… I am still not sure if my head hit the crushing depth of the deep end or sharp rocks at the shallow end but I have both WiringPi (C++) and Node.JS running very basic scripts that do very simple stuff.
Here is the code for the Node.JS and the QR for the App. It is controlling two relays on GP23 & 24. An LED on GP18. shows a display of the seconds (looping 0-59). Toggles a virtual LED via virtual button and alternates two virtual LEDs via physical button on GPIO25
It is not much to go on, but I hope it helps.
PS, it is setup for my Local Server, so you will need to change this line to something different… that I can’t think of off the top of my head
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr:"10.10.3.13", port:8442 } ) }); // Connects to my local server... nener nener not for you!
NodeJS Test Script:
var Gpio = require('onoff').Gpio; // links variable 'Gpio' to the all important onoff GPIO control library
var Blynk = require('blynk-library'); // Links variable 'Blynk' to the Blynk Library
var AUTH = 'cda957435ce44407bed2e9283c95018f'; // My top secret auth code... useless to anyone on the cloud ;P
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr:"10.10.3.13", port:8442 } ) }); // Connects to my local server... nener nener not for you!
var v1 = new blynk.VirtualPin(1); // Setup Button Widget on V1 with variable 'v1'
var v9 = new blynk.VirtualPin(9); // Setup Display Widget on V9 with variable 'v9'
var v10 = new blynk.VirtualPin(10); // Setup LED Widget on V10 with variable 'v10'
v1.on('write', function(param) { // Watches for V1 Button
console.log('V1:', param[0]); // prints value to CLI
if (param == 0) {
blynk.virtualWrite(10, 0); // V10 Widget (ORANGE) LED on
} else if (param == 1) {
blynk.virtualWrite(10, 1023); // V10 Widget (ORANGE) LED off
}
});
v9.on('read', function() { // I don't understand why this says read??
v9.write(new Date().getSeconds()); // but this sends the seconds 0-59 to the Display Widget
});
led = new Gpio(18, 'out'), // Sets up the BCM pin 18 as an output for the LED and assigns it to variable "led"
button = new Gpio(25, 'in', 'both'); // Sets up the BCM pin 25 as an input registering both rising and falling for the variable "button"
button.watch(function (err, value) { // Watches for button press and assigns 0/1 to value
if (err) {
throw err;
}
led.writeSync(value); // Sends value (0/1) to Physical LED
if (value == 0) {
blynk.virtualWrite(2, 0); // V2 Widget (GREEN) LED off
blynk.virtualWrite(3, 1023); // V3 Widget (RED) LED on
} else if (value == 1) {
blynk.virtualWrite(2, 1023); // V2 (GREEN) Widget LED on
blynk.virtualWrite(3, 0); // V3 (RED) Widget LED off
}
});
process.on('SIGINT', function () { // This is apparently a cleaner exit upon CTRL-C... I dunno...
led.unexport();
button.unexport();
});