Pi Gateway working on Raspberry Pi Zero

Started by scott, July 26, 2016, 06:06:10 PM

scott

I saw a couple topics in this forums asking about compatibility of the Pi Gateway with the Pi Zero and thought I would share that I was able to get everything working by following the guide to build the stack rather (as opposed to using the pre-built image). The install was essentially as described in the guide - there were a few places where I made deviations or had to tweak code, but I believe those were primarily due to updates in the libraries used rather than hardware specific.

The biggest challenge was getting the serialport library working properly, which was a result of some changes in the current version of the library that impact the way the constructor is called and deprecates the need to "open" the port seperately (it is done as part of instantiation). The author of the library has a good guide to porting code to the most recent version of the library. I'm also happy to share my working modified code if it helps.

Now on to getting my motes to do something useful!

Felix

Awesome, thanks for sharing that info, I never tried it on a Pi0.

Which node version did you install?
And which serialport version?

Could you share the necessary serialport code changes in gateway.js?

Thanks!

scott

Hi - here are the versions of Node, npm, and the serialport library:

Node: v4.4.7
npm: v2.15.8
serialport: v4.0.1

This is all running on Raspbian Jessie, the Pi0 and a Moteino connected via GPIO.

I'll post the code changes in the next post.

scott

Here are the code changes that I made in gateway.js to accommodate changes in the newer version of the serialport package:

Original Code:
var serialport = require("serialport"); 
...
serial = new serialport.SerialPort(settings.serial.port.value, { baudrate : settings.serial.baud.value, parser: serialport.parsers.readline("\n") }, false);
...
serial.open();


Modified Code:
var SerialPort = require('serialport');  
...
serial = new SerialPort(settings.serial.port.value, { baudrate : settings.serial.baud.value, parser: SerialPort.parsers.readline("\n") });
...
//serial.open();


I can't remember exactly why I removed that last parameter (false) passed to the constructor - I think the intent of the 'false' is to disable a removed parameter callled OpenImmediately, which was replaced with an option (options are the list in the second parameter) called autoOpen. Since that defaults to yes, I just left it out and  commented out the serial.open command (you get an error if you try to open a port twice). I think you could also use the following and it would work similarly.

var SerialPort = require('serialport');  
...
serial = new SerialPort(settings.serial.port.value, { baudrate : settings.serial.baud.value, parser: SerialPort.parsers.readline("\n"), autoOpen: false });
...
serial.open();


You'll have to forgive the amateur hacking - this was my first experience with javascript, node.js and several other technologies involved. I hope this gives someone with a bit more knowledge a head start on implementing the changes in a proper manner :)

Felix

Thanks, that helps  :)
But it kinda feels like this will work as is, ie backwards compatible, with the exception you just use the constructor. I wonder if that part will work with the older node-serialport.

Also what was the socket.io version you installed? Could you post the output of running thse 2 commands from the ~/gateway directory:

npm ls --depth=0
npm outdated

Many thanks!

scott

Here you go:

pi@raspberrypi:~/gateway $ npm ls --depth=0
/home/pi/gateway
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

pi@raspberrypi:~/gateway $ npm outdated
Package  Current  Wanted  Latest  Location
request   2.73.0  2.74.0  2.74.0  request