Terminal Widget on node.js - Raspberry

Hello
I can’t get the terminal widget to run on node.js for raspberry pi 2

allways get “TypeError: term.on is not a function”

my code is :

var Blynk = require(‘blynk-library’);

var blynk = new Blynk.Blynk(‘9d21749a19c549b7aa39e824aba0bcfe’, options = {
certs_path : ‘/home/pi/blynk-library-js/certs/’
});

var term = new blynk.WidgetTerminal(3);
term.on(‘write’, function(data) {
term.write(‘You wrote:’ + data + ‘\n’);
blynk.notify("HAHA! " + data);
});

thanks

@vshymanskyy please check

Thx for the report, I’ll check it again!

You could try using just virtual pin to same V3, it should also work!

Sorry but I don’t understand what you ment. Can you explain ? Thanks

Hi. Please try it on the latest version from npm (0.0.19)…

1 Like

Works fine now ! Thank you

There is any other methods besides read and write on terminal widget?

I have tried to run the following script from the java in 20 minutes instructable

var Blynk = require(‘blynk-library’);

var AUTH = ‘YOUR_AUTH_TOKEN’;

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]);
});

v9.on(‘read’, function() {
v9.write(new Date().getSeconds());
});

But it always fails in a forest of errors such as “cannot find blynk-library” “unexpected token”
A note to say Don’t forget to set the NODE_PATH variable is not helpful. An example of how to set the path would be so much better and would help newbies enormously.

NODE_PATH should point to the place where npm stores globally installed modules, probably:
export NODE_PATH=/usr/local/lib/node_modules

Thanks for this. I tried it but now I get another mysterious error:

pi@raspberrypi ~/wiringPi $ node blynk-test.js
/home/pi/wiringPi/blynk-test.js:1
(function (exports, require, module, __filename, __dirname) { export NODE_PATH
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
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

It looks like you make a mistake in the script.
But I can’t tell anything unless you post your code.
Probably NODE_PATH should be set in console , not inside of the Node.js script.

Hi Vhymanskyy

This is the script as pasted from the instructable with the addition of the Path line.

export NODE_PATH=/usr/local/lib/node_modules

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

var AUTH = ‘MY TOKEN’;

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]);
});

v9.on(‘read’, function() {
var v1 = new blynk.VirtualPin(1);
var v9 = new blynk.VirtualPin(9);

v1.on(‘write’, function(param) {
console.log(‘V1:’, param[0]);
});

v9.on(‘read’, function() {
v9.write(new Date().getSeconds());
});

node blynk-test.js
/home/pi/wiringPi/blynk-test.js:1
(function (exports, require, module, __filename, __dirname) { export NODE_PATH
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
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

This is wrong.
export NODE_PATH … should be executed in the terminal, not inside of the script.

Cheers.

Hi Vhymanskyy

It now works. many thanks.

It may be useful to point out this critical step in the Insructable.