Node-Red running with balena

@GregorR1,

  1. I have just installed the repository https://github.com/balena-io-projects/balena-node-red suggested by @roman-mazur on my raspberry pi 3 and then I installed node-red-node-pi-gpio using node-red editor (via manage palette). I created a little flow and it seems to be working (no warnings/errors seen in log file).

image

FYI here the contents of my log file:

03.10.19 20:51:32 (+0200)  node-red  3 Oct 18:51:32 - [info] Node-RED version: v1.0.0
03.10.19 20:51:32 (+0200)  node-red  3 Oct 18:51:32 - [info] Node.js  version: v12.7.0
03.10.19 20:51:32 (+0200)  node-red  3 Oct 18:51:32 - [info] Linux 4.14.98 arm LE
03.10.19 20:51:33 (+0200)  node-red  3 Oct 18:51:33 - [info] Loading palette nodes
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] ------------------------------------------------------
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] [node-red-contrib-balena/depDevices] Error: /usr/local/lib/node_modules/node-red-contrib-balena/depDevices/depDevices.html does not exist
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] [node-red-contrib-balena/depApps] Error: /usr/local/lib/node_modules/node-red-contrib-balena/depApps/depApps.html does not exist
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] ------------------------------------------------------
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Settings file  : /usr/src/app/settings.js
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Context store  : 'default' [module=memory]
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] User directory : /data/node-red/user/
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Flows file     : /data/node-red/user/flows_803bf37.json
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [warn] 
03.10.19 20:51:36 (+0200)  node-red  
03.10.19 20:51:36 (+0200)  node-red  ---------------------------------------------------------------------
03.10.19 20:51:36 (+0200)  node-red  Your flow credentials file is encrypted using a system-generated key.
03.10.19 20:51:36 (+0200)  node-red  
03.10.19 20:51:36 (+0200)  node-red  If the system-generated key is lost for any reason, your credentials
03.10.19 20:51:36 (+0200)  node-red  file will not be recoverable, you will have to delete it and re-enter
03.10.19 20:51:36 (+0200)  node-red  your credentials.
03.10.19 20:51:36 (+0200)  node-red  
03.10.19 20:51:36 (+0200)  node-red  You should set your own key using the 'credentialSecret' option in
03.10.19 20:51:36 (+0200)  node-red  your settings file. Node-RED will then re-encrypt your credentials
03.10.19 20:51:36 (+0200)  node-red  file using your chosen key the next time you deploy a change.
03.10.19 20:51:36 (+0200)  node-red  ---------------------------------------------------------------------
03.10.19 20:51:36 (+0200)  node-red  
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Starting flows
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Started flows
03.10.19 20:51:36 (+0200)  node-red  3 Oct 18:51:36 - [info] Server now running at http://127.0.0.1:80/
03.10.19 20:52:14 (+0200)  node-red  3 Oct 18:52:14 - [info] Stopping flows
03.10.19 20:52:14 (+0200)  node-red  3 Oct 18:52:14 - [info] Stopped flows
03.10.19 20:52:14 (+0200)  node-red  3 Oct 18:52:14 - [info] Starting flows
03.10.19 20:52:14 (+0200)  node-red  3 Oct 18:52:14 - [info] Started flows

So it would be good if you also try this on your raspberry pi 4.

  1. I also noticed that node node-red-node-pi-gpio and node node-red-node-pi-gpiod are different nodes (but more or less providing the same functionality).

If you want to use node-red-node-pi-gpiod then I recommend to have a look at https://github.com/balena-io-projects/balena-node-red/issues/28

I’m trying to clone and set up the example project to see if it will work for me. I’ve cloned the repo to a new node-red project and have created a simple flow to turn an LED on and off. I’ve committed this to my local git repo, and have set up the remote branch for my balena application. I then used balena push but got this error:

So using the node-red-node-pi-gpiod and using the pigpiod folder from @janvda’s repo. I am getting this error:

I’ve noticed that for some reason my master pi gpio’s are not working with the node-red-node-pi-gpiod - the LED is not flashing.

Can this module only be run in a Docker container? and if so, how do I test my program before committing it?

I think this means that the debian packages rpi.gpio and python-rpi.gpio are not available for the arm64 bit (raspberry pi 4) version.

I found following interesting link: https://sourceforge.net/p/raspberry-gpio-python/wiki/install/
which says that you must run pip install RPi.GPIO .

updated below section

For us this can be implemented as follows.

  1. In order to install pip replace the following lines in your dockerfile:
RUN apt-get update && apt-get install -yq --no-install-recommends \
  rpi.gpio \
  python-dev \
  python-rpi.gpio \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

by

RUN apt-get update && apt-get install -yq --no-install-recommends \
  python-pip \
  && apt-get clean && rm -rf /var/lib/apt/lists/*
  1. add following line to dockerfile.
RUN pip install RPi.GPIO

Would it help if I added you to my gitHub repository as a contributer so you can see my files etc?

I feel like I’m not the best at explaining things and it might help if you can see what I’ve done.

you can do that. I have also updated my previous comment.

I’ve sent you an invite on GitHub, I take it its just the same username as here?

Just to keep this thread upto date, I’m trying to use this repo by @janvda to allow me to get something working, and then I’ll start adding my own dependencies etc in. The Issue I’ve got is that when my gpiod container starts I get this error:

As far as I can tell, I need to run pigpiod as the standard GPIO nodes dont work in a docker container.

Can anyone suggest what to do to solve this error?

Hi,
You have to set up the GPIO container with the correct labels to have the container engine set it up with the correct access rights to perform GPIO. There is more information about this here: https://www.balena.io/docs/learn/develop/multicontainer/#labels
Let us know how it goes.

Hi @afitzek I’m not sure which label it would be that I need to add? Would this be added into the docker-compose.yml? thanks

The container was already running as privileged, from reading the description of the labels, this means it already had access to all this stuff?

Hey @gregorr1 I found this issue on the pigpio repo: Cannot start pigpiod: mmap gpio failed · Issue #259 · joan2937/pigpio · GitHub and the README there also states:

At the moment pigpio on the Pi4B is experimental

You could maybe try to force the use of 32-bit packages by basing your image on the raspberrypi3 base-image…

Hi @robertgzr I’m having to base it on a raspberrypi3 image already as the rpi4 image wouldn’t build due to the lack of 64-bit packages for rpi.gpio and others.

Yeah looks like that pigpio has more issues with the rpi4 than just 64bit :confused: there is further advice on changing the dma channels used by it:

I am not sure if the DMA channels being used are safe. The Pi4B defaults are primary channel 7, secondary channel 6. If these channels do not work you will have to experiment. You can set the channels used by the pigpio daemon by invoking it with the -d and -e options, e.g. sudo pigpiod -d 5 -e 8 to specify primary 5, secondary 8.

Did you try that already?

Managed to get the daemon running by changing the version of the base image to latest. Appears to have sorted the issue on pigpiod container startup - next step is to try and create a node-red flow to control the pins. Will keep this thread updated

Just by chance I stumbled across this old thread - I solved the same problem you have been discussing, you can see my solution here in my GitHub repository balena-node-red-raspberry-pi-gpio. It was a real pain to get all the pieces in place.

Also, once you have the daemon running and Node Red then you must also remember to change the Host network in each Raspberry Pi node from localhost to 172.17.0.1 - this is a major gotcha.

1 Like

How can I update the Node.js version in the Node-RED image on Balena? It currently uses version 16, and I want to update it to version 18.

1 Like

The problem is that the latest version of node-red-contrib-modbus changed to version 5.43 and that version requires that node red have version 18 of node.js, how can I update the version of Node js because it does not allow the installation new version of Node-Red-contrib-modbus

1 Like

I fixed it. I installed the version of node-red-contrib-modbus 5.20.0 that is compatible with node.js v16. I did it from the balena cloud console. and it installed perfectly

cd /data
npm install node-red-contrib-modbus@5.20.0

1 Like