BalenaOS with UniPi Neuron

I was really excited to see that the UniPi Neuron is now being supported by Balena which means we can use it for our project!

I’ve managed to build Development and Production images which I’ve booted on the UniPi. I was now just wondering how they are setup - do I just connect to the UniPi using Modbus TCP at localhost on port 502? Or do I need to start a specific service first in the host BalenaOS?

Also wondering how to connect to the RS-485, as it looks like that is supported also.

EDIT: I logged in to the Balena instance with SSH, and tried:
systemctl start unipitcp

When I then tried a
systemctl status unipitcp

I got this:

     Loaded: loaded (/lib/systemd/system/unipitcp.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2021-04-25 20:13:52 UTC; 4s ago
    Process: 2546 ExecStart=/opt/unipi/tools/unipi_tcp_server -l ${LISTEN_IP} -p ${LISTEN_PORT} (code=exited, status=203/EXEC)
   Main PID: 2546 (code=exited, status=203/EXEC)

Apr 25 20:13:52 balena systemd[1]: unipitcp.service: Start request repeated too quickly.
Apr 25 20:13:52 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Apr 25 20:13:52 balena systemd[1]: Failed to start Unipi Neuron/Axon/Patron/Gate Modbus/Tcp Server.

@floion Was wondering if you might be able to shed a bit of light on how to access the UniPi IO from containers, e.g. node-red?

Hi

If I understand this correctly, you are trying to connect to a balenaOS device, and access it’s hardware. Is that right?

Once you have the device flashed with a dev image, and registered to an application, you can use balena ssh with the UUID and connect to the device. If you want to push any services on the device,you can use balena push. You can also use the local IP address if you are on the same network, and want to use local mode.

These ways of developing are the same across device types - so would be same for a Raspberry Pi or an Intel Nuc, or the Unipi Neuron in your case. To access the hardware on the device, you can take a look at this section in our docs - Interact with hardware - Balena Documentation
Your docker container will need to be a priviledged one, or one with explicit access to hardware interfaces.

Hi there, thanks very much the reply. Yes, I have a privileged container up and running which I can SSH into fine.

I had a read through the link you sent about accessing hardware. Unfortunately the UniPi doesn’t work directly using a /dev/ device - it runs via a TCP server on the device, accessed through port 503. I can see that this server has been included in the BalenaOS UniPi build for the device, but it doesn’t seem to be running, and am unsure how to access it. Any help or information on how this works would be great. I tagged floion as he made the commit for UniPi support to BalenaOS so wondered if he knew.

Can you show the output of journalctl -xe -a -u unipitcp.service from the Host OS?

Another step might be to try to run the unipi_tcp_server process manually and see what the output is.

Also, by:

    Process: 2546 ExecStart=/opt/unipi/tools/unipi_tcp_server -l ${LISTEN_IP} -p ${LISTEN_PORT} (code=exited, status=203/EXEC)

It looks like we are passing in a custom port. I’m not sure what that port is, but it might not be 502.

About the RS485, I believe it should “just work”, but if you are having problems, please let us know.

Thanks for the response - sounds good about the RS485 - I’ll have a look.

I’ve poked around a little bit with the tcp server:

This is the output from journalctl -xe -a -u unipitcp.service:

-- Logs begin at Fri 2020-02-07 15:50:55 UTC, end at Fri 2020-02-07 15:54:32 UTC. --
Feb 07 15:54:31 balena systemd[2261]: unipitcp.service: Failed to execute command: Permission denied
Feb 07 15:54:31 balena systemd[2261]: unipitcp.service: Failed at step EXEC spawning /opt/unipi/tools/unipi_tcp_server: Permission denied
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Main process exited, code=exited, status=203/EXEC
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:31 balena systemd[2262]: unipitcp.service: Failed to execute command: Permission denied
Feb 07 15:54:31 balena systemd[2262]: unipitcp.service: Failed at step EXEC spawning /opt/unipi/tools/unipi_tcp_server: Permission denied
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Main process exited, code=exited, status=203/EXEC
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:31 balena systemd[2263]: unipitcp.service: Failed to execute command: Permission denied
Feb 07 15:54:31 balena systemd[2263]: unipitcp.service: Failed at step EXEC spawning /opt/unipi/tools/unipi_tcp_server: Permission denied
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Main process exited, code=exited, status=203/EXEC
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:31 balena systemd[2265]: unipitcp.service: Failed to execute command: Permission denied
Feb 07 15:54:31 balena systemd[2265]: unipitcp.service: Failed at step EXEC spawning /opt/unipi/tools/unipi_tcp_server: Permission denied
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Main process exited, code=exited, status=203/EXEC
Feb 07 15:54:31 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:32 balena systemd[2266]: unipitcp.service: Failed to execute command: Permission denied
Feb 07 15:54:32 balena systemd[2266]: unipitcp.service: Failed at step EXEC spawning /opt/unipi/tools/unipi_tcp_server: Permission denied
Feb 07 15:54:32 balena systemd[1]: unipitcp.service: Main process exited, code=exited, status=203/EXEC
Feb 07 15:54:32 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:32 balena systemd[1]: unipitcp.service: Start request repeated too quickly.
Feb 07 15:54:32 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
Feb 07 15:54:32 balena systemd[1]: Failed to start Unipi Neuron/Axon/Patron/Gate Modbus/Tcp Server.

I tried running the actual server:

root@balena:/opt/unipi/tools# ./unipi_tcp_server
-sh: ./unipi_tcp_server: Permission denied

Tried to make it executable:

root@balena:/opt/unipi/tools# chmod +x unipi_tcp_server 
chmod: changing permissions of 'unipi_tcp_server': Read-only file system`

Any ideas?

The read-only filesystem is strange - you mentioned you’re doing this from within a privileged container, correct? And the /opt/unipi/tools is either a volume you’ve specified in docker-compose.yml or part of the container filesystem? I also want to make sure you’re aware of this documentation:

As running systemd inside the container takes a few extra steps. Is there a way to run this as a binary in the (privileged) container instead of through the systemd service?

No, I was running those commands from the host BalenaOS, not a container. I’ve played around with it more since (also on the host rather than container):

root@balena:~# mount -o remount,rw /
root@balena:~# systemctl start unipitcp
root@balena:~# systemctl status unipitcp
● unipitcp.service - Unipi Neuron/Axon/Patron/Gate Modbus/Tcp Server
     Loaded: loaded (/lib/systemd/system/unipitcp.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2021-05-04 09:22:32 UTC; 8s ago
    Process: 3017 ExecStart=/opt/unipi/tools/unipi_tcp_server -l ${LISTEN_IP} -p ${LISTEN_PORT} (code=exited, status=127)
   Main PID: 3017 (code=exited, status=127)

May 04 09:22:32 balena systemd[1]: unipitcp.service: Start request repeated too quickly.
May 04 09:22:32 balena systemd[1]: unipitcp.service: Failed with result 'exit-code'.
May 04 09:22:32 balena systemd[1]: Failed to start Unipi Neuron/Axon/Patron/Gate Modbus/Tcp Server.

And also:

root@balena:/opt/unipi/tools# mount -o remount,rw /
root@balena:/opt/unipi/tools# chmod +x unipi_tcp_server 
root@balena:/opt/unipi/tools# ./unipi_tcp_server 0.0.0.0 502
./unipi_tcp_server: error while loading shared libraries: libmodbus.so.5: cannot open shared object file: No such file or directory

This is all from a totally stock, unchanged (no extra files added) version of the UniPI BalenaOS image from here: GitHub - balena-os/balena-raspberrypi: Balena support for RaspberryPI boards

I’m assuming these files were specifically distributed with BalenaOS to be run and used (as they are necessary to use the UniPi), so just wondering how they were intended to be used?

Above you mention running these from a container, how do I access these files on the host from a container to run them?

Any further thoughts on the above? Or any examples of how this image has been deployed on the UniPi so it can access the IO?

Hi, there were some fixes on the UniPi image. So maybe you can build the latest code that’s in git and try it again?

OK great, thank you will try this. Is there any tips on how it’s set up? E.g. do I just access the host port 502 (or 503/5002 whatever it is) from within the container?

I built the latest version and is now working perfectly. The UniPi TCP Modbus service is accessible on port 502 from within the containers.

Many thanks.

Hey there, glad it worked :slight_smile:
Thanks for the feedback