Problem installing in RPi3: onoff library and later

Thanks! managed to make it work at least using the wiringPi workaround.

2 Likes

No, it should work. And it works even on non-raspi boards like Beaglebone or Omega so I wouldn’t suspect Blynk or OnOff. It’s most probably Nodejs<>OnOff relationship.
I have no Raspi 3 to check with.

Didn’t work on my RPi Model B rev 2.0

Guys,
after you install onoff, what happens after you run the simplest onoff script?

var onoff = require("onoff");

as you can imagine, if you get this part working (which is not strictly related to Blynk, rather to onoff-nodejs relationship), Blynk will also recognize onoff. Hope that helps.

Meanwhile, I will think if I can simplify things a bit.

The onoff has issues while installing. I can give it a try on your test, but I am bit confused on which context I should do it. The line of code seems to be C++, should I be compiling that? I tried to compile with gcc but did not work. I was planning to use python for my programming, so not sure how to test your suggestion…

Can you explain to non-linux programmers exactly what you mean by “running” this command?

I have typed it verbatim in the CLI and get an error:
-bash: syntax error near unexpected token `('

I have created a script with it that line:

and ran it… but nothing happens:

I ask, because I have managed to also (along side with the wiringPI method) get the “official??” method of Blynk installed on my older RPi, using some alternative methods of installing NODE, as my ARMv6 hardware (RPI model B ver 2.0) is not compatible with Blynk’s subscribed install method.

Thus, with NODE v6.9.1, NPM v4.1.2 and ONOFF v1.1.1 all installed, I am able to run the test script with virtual pins, the value display and two sliders (1st on V1 and the 2nd on GP18 - where I have an LED wired up)… but any 2nd slider movement gets an error.

So now… Can has more help please? :smiley:

1 Like

@Gunner try adding this extract to test direct pin access:

var Gpio = require('/usr/local/lib/node_modules/onoff').Gpio,
  relay = new Gpio(21, 'out');	// Pi BCM # 21

var v2 = new blynk.VirtualPin(2);  // virtual pin to control GPIO 21

v2.on('write', function() {
	if(relay.readSync() == 0) {  // toggle gpio 21 from high to low
		relay.writeSync(1);
	}
	else {
		relay.writeSync(0);
	}	
});

@Costas Umm… I guess you meen just add it to the blynk-test.js example?


var Blynk = require('blynk-library');
var AUTH = '9ae42d15xxxxxxxxxxda5832f1';
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());
});
var Gpio = require('/usr/local/lib/node_modules/onoff').Gpio,
  relay = new Gpio(21, 'out');  // Pi BCM # 21

var v2 = new blynk.VirtualPin(2);  // virtual pin to control GPIO 21

v2.on('write', function() {
        if(relay.readSync() == 0) {  // toggle gpio 21 from high to low
                relay.writeSync(1);
        }
        else {
                relay.writeSync(0);
        }
});

I get this:

@Gunner ran you script, now called gunner.js and it is fine on my Zero.
Version mismatch is the important part of your error message. I guess your alternative installation methods for the B v2.0 Pi are the problem.

I suspect that as well… As I understand it, NPM is installed with NODE, but I have ran all the updates and have the latest versions of both NPM and ONOFF… so not sure what else I can do.

I could always run sudo apt-get upgrade node… but I believe I did that before and it I think it messes everything up somehow… But I am running it now to confirm :pensive:

what do the following shell commands give you:

node -v
npm -v

v0.12.6 and 2.11.2 for me.

Now it seems to have downgraded? me to v0.12.6 (or not, as that is what you have?) and throws a different error. Also NPM v2.11.2 for me as well.

@are you running Wheezy or Jessie?

If you are on Wheezy the recommended:

sudo apt-get update
sudo apt-get upgrade

Will break onoff.

If you are with Wheezy take a look at https://www.npmjs.com/package/onoff and https://github.com/raspberrypi/linux/issues/1117

Um… NOOBS install of Raspbian… so I think Jessie?

Based on Googling “Error: Module did not self-register”. I am running npm rebuild

What does the following shell command show:

uname -a

[mine is Linux pizero 4.4.21+ #911 Thu Sep 15 14:17:52 BST 2016 armv6l GNU/Linux]

OK, that did nothing… but running npm install -g onoff again did allow me to run the script without errors. And now I can move the GP18 slider, also without errors… but also without any reaction from the PWM LED… bahhh, :unamused:

What was I to add to the app to make the GPIO21 toggle? Button or switch on V2?

Linux raspberrypi 4.4.32-aufs #1 Sat Nov 19 00:02:41 CET 2016 armv6l GNU/Linux

Yes a button in switch mode on V2.

Can you provide a screenshot so I can check the pin settings from

gpio readall

I have a relay board hooked up to BCM 23 & 24

Unlike the Zero, you don’t have a 21, so you will need to change the number in the sample I provided.

Numbers are BCM.