I am trying to setup canbus on a fleet of vehicles using the beaglebone green. I have working can bus on a beaglebone green without docker or balena. My trouble is trying to turn on can0 and can1. I have edited the /etc/network/interfaces document on my beaglebone but don’t know how to do that. Additionally I am used to setting up the pin configuration using a pin config shell script. This requires a service to be established in systemd. I found this complex with balena and docker so I instead tried to simply RUN “config-pin p9.19” unfortunately this does not work. What should I do to get this working. I have tried installing the bb-cape-overlays but this does not work.
I am using FROM balenalib/beaglebone-green-golang:latest-build AS build
Enable the CAN Bus with capemgr. It is supported by balenaOS, see the documentation here.
You can do something like echo BB-CAN1 > /sys/devices/platform/bone_capemgr/slots to enable CAN Bus 1 for instance.
Bring up the interface by running sudo ip link set can0 up type can bitrate 250000.
You could also enable the dtoverlay in /boot/uEnv.txt so it is loaded at system boot.
Note that it needs to be done at runtime, so there has to be a script that sets up those interfaces, pins, etc.
Hope that helps to get you going! Please let us know how it goes.
So, I have tried what you proposed. I however don’t believe I am doing everything correctly. Here are a few questions that have popped up along the way.
Can I see an example dockerfile that shows how to modify /mnt/boot/uEnv.txt. Everytime I try it says something like. " COPY failed: stat /var/lib/balena32/tmp/docker-builder187984163/mgbApp/uEnv.txt: no such file or directory"
Also wrapping my brain around multi-stage building of containers is limited as well and it appears is a requirement when working with go, is this correct?
Let’s focus on getting the CAN buses to work first. The instructions above indicated that you should run the following as part of your application container entry script with the root user:
echo BB-CAN0 > /sys/devices/platform/bone_capemgr/slots
echo BB-CAN1 > /sys/devices/platform/bone_capemgr/slots
ip link set can0 up type can bitrate 250000
ip link set can1 up type can bitrate 250000
The above lines should be enough to get the CAN interfaces working.
Could you please try those instructions and let us know the outcome?
Thanks
Indeed, the application container entry script refers to Dockerfile.
More specifically, depending on how your application is set up, you’re likely looking to append the commands using CMD or ENTRYPOINT. See https://docs.docker.com/develop/develop-images/dockerfile_best-practices for context.
The lines that Alex added above need to be run on your application container, not the host machine. In a nutshell, your device runs on balenaOS, but your dockerfile(s) wire up containers which have their own OS and run their own programs and scripts. You need to create a script as part of your application, in the same directory as the dockerfile, and add a COPY line to bring it into the container. You need need to use the CMD or ENTRYPOINT directives to make it run in the container. That way, every time the container is started, those commands are run and the CanBus is enabled.
Thank you for that explanation. I believe what you are asking me to do is something I have done. I wrote a script which includes the 4 lines of code that @alexgg provided above. I then made it executable with chmod +x. Then I call the script with CMD ./somescript.sh. The container builds successfully and the script is executed. When I look at the output of the container however it shows the same error as above “write error: No such file or directory”.
RUN chmod +x somescript```
That will move your script to the current working directory on your device's HostOS. Then as a last line in your Dockerfile:
```CMD ["/bin/bash", "./somescript.sh"]```
John
@jtonello Thank you for the quick response. Below is the output after running the script
11.09.20 12:05:57 (-0700) main ./somescript.sh: line 2: echo: write error: No such file or directory
11.09.20 12:05:57 (-0700) main Cannot find device "can0"
11.09.20 12:05:57 (-0700) main Cannot find device "can1"```
Here is my Dockerfile.template contents
```FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch
COPY somescript.sh .
RUN chmod +x somescript.sh
CMD ["/bin/bash", "./somescript.sh"]```
Here are my script contents
```echo BB-CAN0 > /sys/devices/platform/bone_capemgr/slots
echo BB-CAN1 > /sys/devices/platform/bone_capemgr/slots
ip link set can0 up type can bitrate 250000
ip link set can1 up type can bitrate 250000```
First, is your somescript.sh located in the same directory as your Dockerfile.template. That’s a must in this example because it’s trying to copy from the working directory on your workstation. Second, is the first line of your bash script #!/bin/bash ?