Execute external bash script on server with blynk))

Hello every one, its me again with somekind of untypical question

You know, i got a PC with WOL function in my home network…
Always i use SSH client to connect to home server and execute WOL.sh(just to send magic packet) to launch PC

Is there any way to do it with blynk, runned on home server?
Some event triggered in app(for example button is pressed) and blynk server execute WOL.sh for me…
(any way it runs under root)

Hello. Yes. This is possible. There are few options :

  • WebHooks. You type something like “http://localhost:8080/doStuff” in widget. You need to have small http server that will accept this url and run your script;
  • Java/Javascript/python/c++ client. You run client that connects to Local Blynk server. When client gets message, client runs script.

Sorry for my stupidness))))

First way is to make nginx… so its not desired cause i ran apache2 and even port 8080 busy with motionjpeg_streamer)))

So can you explain Please second vairant with client…
I have to download a blynk client similar to RPi variant and compile it with??? --target raspberry??? Or???
How can I find out that client got message?(something with cron???) and how can i told client to run script?
Is it long to explain or there is some kind of manual for client comands?

the only i know to read and write something to blynk server is to use API for it…
But i think its a bad solution to make
infinity cicle with button status read, to find out whatever it pressed or not!

I guess the problem is that i did not write anythink on js… but included https://github.com/vshymanskyy/blynk-library-js/blob/master/README.md example did not gives a lot of information(((

Since you can script in JavaScript, this may be an answer: http://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript

Thank you, but im searching for beginners sample .js witch include custom local blynk server connection and simple values operation

Maybe you help me once to start me as blynk javascipter

It’s in the example browser, top right of the page.

Im searching for js example, not sketch of arduino ide)))
It differs)))

I thought there was a little JavaScript in there too. I know that there is an example script here:

Sorry but i faild to find connect to custom local server

It’s there, in plain sight :slight_smile: Just replace the with the IP of your local server. (since would be localhost).

1 Like

@zara once you have the basic tcp script running with your local server all you need to run a bash script is:

const spawn = require('child_process').spawn;

and then inside the widget control code something like:

const sh = spawn('sh', ['/home/pi/bash_script.sh']);

1 Like

Sorry again, but im faild to launch any .js from my orangepi zero…

i install node.js and blynk library acording to Rpi instruction
and finaly get this resoult

zara@carpi:~/blynk-library-js-master/examples/nodejs$ sudo npm install -g blynk-library
/usr/bin/blynk-client -> /usr/lib/node_modules/blynk-library/bin/blynk-client.js
/usr/bin/blynk-ctrl -> /usr/lib/node_modules/blynk-library/bin/blynk-ctrl.js
└── blynk-library@0.4.6

so, everythink suppose to be fine,
i took a sample to connect a local blynk server, just clone it from here

but then im trying to execute .js i got this:
zara@carpi:~/blynk-library-js-master/examples/nodejs$ ./client-tcp-local.js
throw err;

Error: Cannot find module ‘blynk-library’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/home/zara/blynk-library-js-master/examples/nodejs/client-tcp-local.js:3:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

why??? module is exist in binary folder! what am i doing wrong?

im a newbee in node.js))))

i get an instrution of node.js setup form there http://www.instructables.com/id/Blynk-JavaScript-in-20-minutes-Raspberry-Pi-Edison/ (for Rpi)

nodejs -v outupt
zara@carpi:~/blynk-library-js-master/examples/nodejs$ nodejs -v

Use the full path to the blynk library here, e.g.:

var Blynk = require(‘/usr/lib/node_modules/blynk-library/’);

oh… s…t))) ill try full path right now)))

Yip))) IT HELPS)))))))

You can add the Path to your environment variable settings in bash_rc or bash_profile, that should help. Or just use the full path. :slight_smile:

Cant you help to noob some more?

This default sample?
what shoud i do with V9

“v9.on(‘read’, function() {
v9.write(new Date().getSeconds());
});” – whats that? what shoud i do in app to see something??? time date??

Im trying to make code analogy with arduino ide sketches

Well, I’d love to help but I don’t know the first thing about JS. It’s so different from C++ in syntaxis (e.g. grammar). I can program well enough, but I’m having trouble with the JS grammar.

In the example you provided I think the script prints the date to something attached on Vpin 9 on your dashboard. Did you try making a labeled value widget on v9?

Niether value display, nor labled did not show anything))) at v9… its the JS sample))) in github
dont beware ill better ask Costas after

Is the labeled value in Push or Frequency mode?

niether push, nor frequency mode did not show any thing on Click or 1 sec delay

V1 works fine