Openhybrid Raspberry pi - inteface and library

This thread is for Openhybrid development for the Raspberry pi
Specific continuation of First step to install Open Hybrid on raspberry pi?
This thread will be mainly dealing with the development of hardware interface and libraries for Raspberry Pi B+ model

1 Like

@valentin Should there be a HybridObject library for the raspberry pi ?
should the existing cpp library be used with a python adapter on the pi or should a new python library be built ?

@V_Mohammed_Ibrahim I think this work has to go hand in hand with the API optimizations Carsten is doing right now.
You can already see with his code that it is a lot easier to write a hardware adapter.
In the end you will have the choice to just write your GPIO interfaces right with the hardwareinterface API or if you want to build another bridge to something outside.

If you feel like python is the way to go and a common tool to program things on the PI, yes then maybe a python interface would be nice.

I don’t think you should use the existing HybridObject library. It is optimized for the Atmega processor and its capabilities. For example half of that library is dealing with minimizing the serial data communication by using lookuptables and dealing with string inputs matching to array indexes and all kinds of data allocations. The other half deals with synchronizing between two “computers” (atmega and atheros) that have very different boot up timings. In python you might be able to just interface with the hardware interface API directly.
There are a lot of examples online on how to bridge between nodejs and python.

1 Like

Since python is more commonly used on the pi , i think it would be better that the libraries be in python
i will begin working on the library along with the interface

1 Like

Maybe you should take a look at this: https://www.npmjs.com/package/pi-gpio
Seems to be very easy to address the gpio pins directly from javascript/nodejs with it

1 Like

Yeah ! i have seen it, the mapping makes it easy to use the GPIO using the physical pin numbering
i have collected some others also like this one that will be useful in designing the interface

@valentin i copied the object folder to the pi

  1. Deleted the arduino yun hardware interface
  2. gave npm installl , but the dependencies did not get installed
    can you tell me what is wrong?
    i am attaching the log file --> https://drive.google.com/file/d/0B8fObOtnw_xhb1hKQnVJcFhhTjQ/view?usp=sharing
    first time “failed to fetch from registry: - body-parser”
    second time “failed to fetch from registry : - change-case”
    this keeps repeating

Your node.js version is probably to old.
Your log says v0.6.19 that is from 2012.
Try something >v0.10.28. The yun is currently running with v0.10.33.

node -v returns v4.0.0 , but the npm install fails and log still shows “node -v0.6.19”

UPDATE : after restarting the pi and giving npm install i get this

>  pi@raspberrypi ~/Desktop/object $ npm install
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io/node_modules/socket.io-parser requires debug@'0.7.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io/node_modules/debug,
> npm WARN unmet dependency which is version 2.1.0
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/engine.io-client requires debug@'1.0.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/debug,
> npm WARN unmet dependency which is version 0.7.4
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/engine.io-client requires parseuri@'0.0.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/parseuri,
> npm WARN unmet dependency which is version 0.0.2

Try to change serialport to “^2.0.5” in the package.json file.
With this change I could run npm install and the server with no errors on a mac with the latest node.js.
You might find more about node.js / socket.io and the PI online. Its an ARM system and might need different installations.

1 Like

i changed the serialport to “^2.0.5” but then it resulted in a different set of errors

serialport.target.mk:90: recipe for target 'Release/obj.target/serialport/src/se                                       rialport.o' failed
make: *** [Release/obj.target/serialport/src/serialport.o] Error 1
make: Leaving directory '/home/pi/Desktop/object/node_modules/serialport/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_                                       modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces                                       s.js:200:12)
gyp ERR! System Linux 3.18.11+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_mod                                       ules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/pi/                                       Desktop/object/node_modules/serialport/build/Release/node-v46-linux-arm/serialpo                                       rt.node" "--module_name=serialport" "--module_path=/home/pi/Desktop/object/node_                                       modules/serialport/build/Release/node-v46-linux-arm"
gyp ERR! cwd /home/pi/Desktop/object/node_modules/serialport
gyp ERR! node -v v4.0.0
gyp ERR! node-gyp -v v3.0.1
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local                                       /lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-                                       build --module=/home/pi/Desktop/object/node_modules/serialport/build/Release/nod                                       e-v46-linux-arm/serialport.node --module_name=serialport --module_path=/home/pi/                                       Desktop/object/node_modules/serialport/build/Release/node-v46-linux-arm' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/pi/Desktop/object                                       /node_modules/serialport/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:817:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/chi                                       ld_process.js:211:5)
node-pre-gyp ERR! System Linux 3.18.11+
node-pre-gyp ERR! command "/usr/local/bin/node" "/home/pi/Desktop/object/node_mo                                       dules/serialport/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/pi/Desktop/object/node_modules/serialport
node-pre-gyp ERR! node -v v4.0.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.13
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modu                                       les/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/Desktop                                       /object/node_modules/serialport/build/Release/node-v46-linux-arm/serialport.node                                        --module_name=serialport --module_path=/home/pi/Desktop/object/node_modules/ser                                       ialport/build/Release/node-v46-linux-arm' (1)
npm ERR! Linux 3.18.11+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.2
npm ERR! code ELIFECYCLE
npm ERR! serialport@2.0.5 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the serialport@2.0.5 install script 'node-pre-gyp install --f                                       allback-to-build'.
npm ERR! This is most likely a problem with the serialport package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR!     npm owner ls serialport
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     /home/pi/Desktop/object/npm-debug.log
pi@raspberrypi ~/Desktop/object $ sudo apt-get install node-pre-gyp install --fallback-to-build
E: Command line option --fallback-to-build is not understood
pi@raspberrypi ~/Desktop/object $ sudo apt-get install node-pre-gyp
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package node-pre-gyp

There is some good documentation for how to install nodejs serialport on the PI here:
https://www.npmjs.com/package/serialport

Other then this, if you have some time to wait. Carsten works a lot on improving the structure of the hardwareinterface. I think that you would benefit from waiting until that part is ready to be used.

Meanwhile if you really want to build the python bridge, try to experiment with some simple node.js example first. If you feel save with a good method, then it makes sense to work with the server code.

1 Like

I looked up in the site and installed the required node js , one module was different for ARM ,after that the errors are gone
now there are only these warnings

> pi@raspberrypi ~/Desktop/object $ npm install
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io/node_modules/socket.io-parser requires debug@'0.7.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io/node_modules/debug,
> npm WARN unmet dependency which is version 2.1.0
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/engine.io-client requires debug@'1.0.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/debug,
> npm WARN unmet dependency which is version 0.7.4
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/engine.io-client requires parseuri@'0.0.4' but will load
> npm WARN unmet dependency /home/pi/Desktop/object/node_modules/socket.io-client/node_modules/parseuri,
> npm WARN unmet dependency which is version 0.0.2

Giving a " node server.js " within the folder or " node object" from outside the folder gives this

pi@raspberrypi ~/Desktop/object $ node server.js
module.js:111
    throw e;
          ^
SyntaxError: Error parsing /home/pi/Desktop/object/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/node_modules/utf8/package.json: Unexpected end of input
    at Object.parse (native)
    at readPackage (module.js:107:52)
    at tryPackage (module.js:117:13)
    at Function.Module._findPath (module.js:183:18)
    at Function.Module._resolveFilename (module.js:334:25)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/pi/Desktop/object/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:5:12)
    at Module._compile (module.js:460:26)

@V_Mohammed_Ibrahim You might find an interesting learning adventure to understand a bit more how to read these debug messages and then find a solution by your self.

For example you see in this message that something was not parsed rightfully in the node_modules folder.
The module is socket.io as you can see being the next subfolder.

The wrong parsing could be from the server code or from your installation.
Try out a small test project with socket.io and see if the error repeats.

If it does you have a broken installation.
If you google socket.io and raspberry PI then you might find some answers that could help you?
You can try to install socket.io globally:
npm install -g socket.io

If it does not, something in server.js is going wrong.
Maybe there is an issue with a version of socket.io?

It needs to be debugged. This is 90% of the work you need to do when you build something that was not there before. Start with small experiments first until you reached the point where you understand what is happening in the full picture. Try to break problems down in to their components until you have reached what is going wrong.

I want to encourage you to learn more on how to solve these error messages by your self.
You will learn a lot about how to debug node.js code.

1 Like

Yes ! i will do that , i had already started on that :smile:

1 Like

@valentin All errors have been removed and the server executed successfully

i had earlier removed the Arduino yun interface from the folder, i replaced the folder with a new copy from github and then did npm install
all dependencies got installed successfully , didnt have to change the serialport in package.json

Now that the server is working , i can start on developing the hardware interface code

1. I think there should be a python module similar to the “HybridObject” library for the yun , that the user can then import when programing the GPIO

2. Then the hadwareinterface to communicate to the server

@valentin How should i proceed with building these? What should be my first steps

I think some good first steps are:

  1. Research online all methods on how to bridge/communicate between node.js and python.
  2. With every researched option, make a small individual node.js experiment outside from the greater open hybrid server code. This is the best way for you to understand what is really needed and how it works.
  3. By the time you are done with step 1 and 2 the new hardwareInterface API should be ready and with your new know how you will be able to implement the pyhton hardwareInterface.

What do you think?

1 Like

Yeah that is good , i have already collected some materials for it , what do you think we can do about the “digital only” nature of the PIs pins , i saw that we need DAC to use analog output