How to control GPIO Rpi from Nodered

Hi community,

I need your help.

I’m using Ubuntu Core and running it on a Raspberry Pi 3 B+ machine. I have installed on it the snaps Openhab-ondra and Nodered.

I would like to control the GPIOs of my Raspberry using Nodered but I can’t figured it out how to do. I installed even the snap pigpio and the classic mode with RPi.Gpio and WiringPi but still can’t manage to get work my GPIOs via Nodered.

As you can see this image below from my Nodered, both Gpio nodes in input and output are grey and not available. In this way unfortunately I can’t control them and I’m totally stuck.

Schermata%20da%202019-03-31%2011-37-10

Instead, I can control the GPIOs from the terminal connecting one of them to the snap pigpio and give them the impulse with the http command (I followed this guide: http://www.om26er.com/2019/01/control-gpio-pins-on-raspberrypi-3.html)

It’s a start but what I need to do is to control them with Nodered.
I hope some of you can help me.

Thanks for your help,
Matt

Hey @TiaPreve

you’re snap need follow stuff:

in the apps section:

plugs :[otherinterfaces, gpiopin]

as plug definition:

gpiopin:
interface: gpio

then you can run

snap connect yourapp:gpiopin rpi3:gpiopin

this should then work.

Docu about snap plugs and slots:

https://docs.snapcraft.io/interface-management/6154

greets

Hi @tokurz

thanks for your reply.

I followed what you wrote me and the guide too with some information more found on internet.

What I did first was to see the slots and plug of the GPIO with this command:

snap interface gpio
name: gpio
summary: allows access to specifc GPIO pin
plugs:

  • node-red
  • openhab-ondra
    slots:
  • pi:bcm-gpio-0
  • pi:bcm-gpio-1
  • pi:bcm-gpio-10
  • pi:bcm-gpio-11
  • pi:bcm-gpio-12
  • pi:bcm-gpio-13
  • pi:bcm-gpio-14
  • pi:bcm-gpio-15
  • pi:bcm-gpio-16
  • pi:bcm-gpio-17
  • pi:bcm-gpio-18
  • pi:bcm-gpio-19
  • pi:bcm-gpio-2
  • pi:bcm-gpio-20
  • pi:bcm-gpio-21
  • pi:bcm-gpio-22
  • pi:bcm-gpio-23
  • pi:bcm-gpio-24
  • pi:bcm-gpio-25
  • pi:bcm-gpio-26
  • pi:bcm-gpio-27
  • pi:bcm-gpio-3
  • pi:bcm-gpio-4
  • pi:bcm-gpio-5
  • pi:bcm-gpio-6
  • pi:bcm-gpio-7
  • pi:bcm-gpio-8
  • pi:bcm-gpio-9

then I connect the plug node-re to the GPIO using:

sudo snap connect node-red:gpio pi:bcm-gpio-21

At the end instead I had a look all the plugs and slots with the command

snap interfaces

What it show to me was a list and I see that the “pi:bcm-gpio-21” was connect to “node-red:gpio”

When I opened Node Red and gave the timestamp to turn the ralay ON nothing happened. The GPIO in Node Red is still grey and not available and my relay didn’t switch in the ON mode.

Did I do something wrong?

Thanks a lot,
Matt

@TiaPreve may you can

sudo tail -f /var/log/syslog

to check if some errors and you need maybe more interfaces to add.

Greets Tony

you might need to run nodered as root or change the permissions of the /dev/gpiochip* device that you try to connect to, even when all interfaces are connected, the normal unix/linux device permissions apply in snaps.

Hi

I used the command as @tokurz suggested to me and it gives

tail: cannot open ‘/var/log/syslog’ for reading: No such file or directory
tail: no files remaining

I also tried as @ogra suggest to stop the node-red service and access as root with “sudo su” and restarted again the service with “snap start node-red” and the terminal gave to me “Started.”

I also changed the permissions of the " /dev/gpiochip* " using the command

chmod 775 /dev/gpiochip*

At the end the problem still persist and nothing unfortunately has changed. The GPIO is still not available and it is still grey in Nodered.

What do you suggest me to do?

Thanks
Matt