BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Change button without tapping

pins
rpi
#1

Im using an Raspberry Pi 3B+.

Hello everybody, im trying “klick” a button, without tapping.
So I have 3 virtual pins and 3 buttons(connected to the pins) on my Iphone which can switch between 0 and 1.
Im using the first and the second button to turn on or off my lamps (433 MHz Transmitter).
My Problem now is that the button 3 is for an Morning Programm which turns the light(first one) on, and does other stuff.
But when I’m using this program, the button one, for the first lamp, is always “off”, but the light is on.
Is there a command to chang a button from “off” to “on”?

Here my code:

var Blynk = require('blynk-library');

var AUTH = 'MY_TOKEN';

var blynk = new Blynk.Blynk(AUTH);

var v1 = new blynk.VirtualPin(1);
var v2 = new blynk.VirtualPin(2);
var v3 = new blynk.VirtualPin(3);

const childProcess = require('child_process');


v1.on('write', function(param) {
  if (param == 1) {  
    childProcess.spawn('~/Desktop/Programme/Remote/steuerungA 1', { shell: true });
  }
  if (param == 0) {
    childProcess.spawn('~/Desktop/Programme/Remote/steuerungA 0', { shell: true });
  }
});

v2.on('write', function(param) {
  if (param == 1) {  
    childProcess.spawn('~/Desktop/Programme/Remote/steuerungB 1', { shell: true });
  }
  if (param == 0) {
    childProcess.spawn('~/Desktop/Programme/Remote/steuerungB 0', { shell: true });
  }
});

v3.on('write', function(param) {
  childProcess.spawn('~/Desktop/Programme/Remote/steuerungA 1', { shell: true });
  //other stuff
});
0 Likes

#2

not sure with a Pi, but I use Blynk.virtualWrite(vPin, value) to manipulate a switch/button from within the program.

0 Likes

#3

when i do it like that:
v3.on('write', function(param) {
childProcess.spawn('~/Desktop/Programme/Remote/steuerungA 1', { shell: true });
Blynk.virtualWrite(v1, 1);
//other stuff
});
i get an:
TypeError: Blynk.virtualWrite is not a function

0 Likes

#4

I think that’s because it should be a lower case b:
blynk.virtualWrite(v1, 1)

Some NodeJS stuff here from @Gunner:

Pete.

0 Likes

#5

thanks for helping!

now I didnt get an Error but the V1 button still dont change from “off” to “on”

0 Likes

#6

problem solved, i have to write:
blynk.virtualWrite(1, 1)
withoout the “v”

thanks for helping!!!

1 Like