Problem with path when running code (Blynk looks for "/usr/local/lib")


I’m new to Blynk, that looks to be a really nice IoT platform, congratulations for this amazing work!!

I have one widget that gets temperature from DS18B20 running on a nodeMCU and temperature and humidity from a DHT22 running on a Raspberry Pi, and they are ok.

I’m trying now working with buttons for change some relay’s state, so I looked at some examples and did a simple test code using js. My problem by now is when I execute the command:

sudo NODE_PATH=/usr/lib/node_modules node /home/pi/Blynk/test.js

get error:

OnOff mode
Connecting to TCP: 80
throw err;

Error: Cannot find module ‘/usr/local/lib/node_modules/onoff’

as you see node_modules is on /usr/lib, not /usr/local/lib:

$ ls /usr/lib/node*
blynk-library node-gyp npm-check onoff
node-dht-sensor npm npm-check-updates

and under /usr/local/lib there is nothing about it:

$ ls /usr/local
bin etc games include lib man sbin share src

But my poor knowledge on linux and programming didn’t help to find the problem, looks to me some faulty install, so I’m asking for your help!

node v10.13.0
npm 6.4.1
blynk-library 0.5.3

Thanks in advance!

What version of Blynk Library did you try to install? C++ (WiringPi) or NodeJS?

C++ - Using C++ on a Raspberry Pi with Blynk

NodeJS -

EDIT - OK, I am not a fan of the WiringPi so I had to double check if it used onoff or not… but based on what I see, and one of your comments above (that I previously missed) it looks like NodeJS.

What type of RPi are you using?

You can try to reinstall and see it that helps…

sudo npm install onoff -g

I’ve ran this just a bit before post this:

$ sudo npm install -g onoff

  • onoff@3.2.2
    updated 1 package in 12.611s

but had no success as you saw.

I have a Pi 3 running Raspbian. My Blynk install was NodeJS, but wiringpi alone was already installed on Pi before Blynk install.

Is it possible to debug/log onoff on that error moment?

That’s OK… it is not being used/involved.

I don’t know… I am still learning NodeJS and Linux as well.

Did you follow the Blynk NodeJS install guide (link above)… there are some path commands that might have been missed?

There was a big, huge OOPS in the code, a mention to that wrong path:

“var Gpio = require(’/usr/local/lib/node_modules/onoff’).Gpio”

so now Blynk connect and authorize, BUT after that, when I ran the widget button:


TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:129:9)
at Object.write (fs.js:511:16)
at Gpio.write (/usr/lib/node_modules/onoff/onoff.js:192:8)
at exports.BoardOnOff.process (/usr/lib/node_modules/blynk-library/blynk-node.js:367:13)
at Blynk.onReceive (/usr/lib/node_modules/blynk-library/blynk.js:481:29)
at exports.TcpClient. (/usr/lib/node_modules/blynk-library/blynk.js:562:50)
at exports.TcpClient.emit (events.js:182:13)
at Socket. (/usr/lib/node_modules/blynk-library/blynk-node.js:50:14)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)"

As I’m not master on anything I’ll try with some more basic test code to see if happens something beyond errors, and hope to post good news here soon. Thanks for now!

Here are some example NodeJS sketches that I have been making…

Good news. The problem is my total lack of knowledge on node/js/blynk and so on…

My widget was pointing to a digital pin, not a virtual one. Now I need to better understand how the code tie both to act on the relay.

Thanks a lot for your help Gunner, was just my “newbieness” on this mixed environment!

OnOff mode
Connecting to TCP: 80
V1: 1
V1: 0
V1: 1

1 Like