I have a CM19A x10 light controller, that plugs into the usb port of my raspberry pi.
Awhile ago, I was able to get it to turn on and off a light, from the command line.
I am wondering if blynk is able to send commands to the usb port. The command is something like +A1 on.
I have not been able to find anywhere on here where it talks about sending commands to the usb port. (Or I just don’t understand the ports well enough yet)
Any help would be greatly appreciated.
Thanks
@tennis with javascript you can get Blynk to spawn a child process to run any command you like on the Pi.
also, you can use serialport
npm package to send any commands.
I am making a bit, albeit slow progress.
From the cli on my pi, I can get the lights to turn off and on using these commands:
echo “rf a1 off” | nc localhost 1099
echo “rf a1 on” | nc localhost 1099
I don’t understand javascript well enough to know how I get that command to happen when I push a button on blynk.
Using the most basic of code:
var Blynk = require(‘blynk-library’);
var AUTH = ‘auth_code’;
var blynk = new Blynk.Blynk(AUTH, options = {
connector : new Blynk.TcpClient()
});
var v1 = new blynk.VirtualPin(1);
var v9 = new blynk.VirtualPin(9);
v1.on(‘write’, function(param) {
console.log(‘V1:’, param[0]);
});
I can see on the pi, v1 status change as I push the button.
I assume I would use an if/then statement, but the syntax is what I can’t figure out.
If v1 =10 then echo “rf a1 on” | nc localhost 1099 is what I’m trying to accomplish.
Anybody have some js coding that could work?
Thanks
@tennis do you know how to a make a couple of shell scripts called lightson and lightsoff with the echo commands? Ensure they are in /home/pi and don’t bother with the normal .sh filename suffix.
Ensure they are both executable with:
sudo chmod+x lightson
sudo chmod+x lightsoff
Test them with:
sh lightson
sh lightsoff
Then for Blynk try this:
#!/usr/bin/env node
// USBcontrol.js
var Blynk = require('blynk-library');
const spawn = require('child_process').spawn;
var AUTH = 'auth_code';
var blynk = new Blynk.Blynk(AUTH, options = {
connector : new Blynk.TcpClient()
});
var v1 = new blynk.VirtualPin(1);
var v9 = new blynk.VirtualPin(9);
v1.on('write', function(param) {
console.log('V1:', param[0]);
if (param[0]=='1') {
console.log('Lights ON');
const sh = spawn('sh', ['/home/pi/lightson']);
}
else{
console.log('Lights OFF');
const sh = spawn('sh', ['/home/pi/lightsoff']);
}
});
That was exactly what I was looking for!
Now I can start adding the rest of my lights and see what other improvements I can make.
Thanks so much!