IndustrialShields RPI PLC support

Hi all,

I am just getting started with a first device on BalenaCloud, it is intended to be the control center of a battery system for use on construction sites.

Currently the devices are IndustrialShields RaspberryPi 4 based PLCs.
However I am having trouble use the extra extension boards supplied by IndustrialShields.

In a normal Raspbian environment it is very easy to make it work.
Just run an install.sh script which configures everything.
I have gone through the script and tried to execute all commands individually, but I am having trouble doing all of them because a lot of folders are read-only.

Any help to get this to work would be truly appreciated!

IndustrialShields guide for installation: https://www.industrialshields.com/blog/raspberry-pi-for-industry-26/installating-an-operative-system-in-the-raspberry-plc-491

Thanks!

1 Like

Hi there,

I took a look at the install.sh script here: https://apps.industrialshields.com/main/rpi/rpiplc_v4/install.sh to see what it does. From an initial glance, I would say:

insert "dtparam=spi=on" /boot/config.txt
insert "gpio=8=pd" /boot/config.txt
insert "dtoverlay=spi0-1cs,cs0_pin=7" /boot/config.txt
update "dtoverlay=w5500,cs=0,int_pin=6" /boot/config.txt
insert "dtparam=i2c_arm=on" /boot/config.txt
update "dtoverlay=i2c-rtc,ds3231" /boot/config.txt
update "dtoverlay=sc16is752-spi1-rpiplc-v4,xtal=14745600" /boot/config.txt

You can set these by either mounting the sd card with your balena OS image on it outside of the pi, and adding these to the config.txt in the boot partition. Alternatively, I believe you can set the dtoverlay and dtparam using device configuration variables as described here: Advanced boot settings - Balena Documentation

update "enable_uart=1" /boot/config.txt

same here.

insert "i2c-dev" /etc/modules

I think that this shouldn’t be nessaary, as I think that i2c-dev gets loaded by default. I would recommend running your container in privileged mode.

if [ ! -f /etc/network/interfaces.d/eth0_1 ]; then 
	cat > /etc/network/interfaces.d/eth0_1 << EOT
auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
	address 10.10.10.20
	netmask 255.255.255.0
EOT
fi

if [ ! -f /etc/network/interfaces.d/eth1_1 ]; then
	cat > /etc/network/interfaces.d/eth1_1 << EOT
auto eth1:1
allow-hotplug eth1:1
iface eth1:1 inet static
	address 10.10.11.20
	netmask 255.255.255.0
EOT
fi

I’m not sure about this - in balenOS ethernet interfaces have always automatically configured when I’ve ever added one to a device - it mght not be necessary

[ ! -d /home/pi/.ssh ] && mkdir /home/pi/.ssh && chown pi:pi /home/pi/.ssh
[ ! -f /home/pi/.ssh/authorized_keys ] && touch /home/pi/.ssh/authorized_keys && chown pi:pi /home/pi/.ssh/authorized_keys && chmod 600 /home/pi/.ssh/authorized_keys
update "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCmUlYcl2AIROXD6US8s6D+IFU/Mau3TLuoPIhv5t6V0O+u0zoDEvAurC2xP1xf0mLabaIkFxGgixeSvaGrIqy1oPP30ly8f+zMKe0P9k41D+Lq8ZR9ohdTivlZm5MfW4l6xV6jojWPZNafMn+WW7trfRP/XRxKzcz2mjU9GMLHQmxHqBCsqlnUYkIH0Hq+3xwj9U/IJqYiQD5cm9mtXNLhwK7fYS81GPJhE9bNrJ7B/gmvVw0/3JMCK08DcbUOfHoCvJVbYCdZOM3xPIBtnmtLVD9YWn49yXXDg7Ndipq+tYIpg78HLJkhl31wvXiuKZKne/+sCtWArWZkrLdtLhn pi@raspberrypi" /home/pi/.ssh/authorized_keys

systemctl enable ssh

Not sure about this either - it looks like its trying to allow for an ssh connection to the pi - shouldn’t be needed as the balenaOS host OS already has ssh configured, so you can access the pi over ssh using that.


RPISHUTDOWN_STATUS=0
systemctl status rpishutdown
[ $? -eq 0 ] && RPISHUTDOWN_STATUS=1 && systemctl stop rpishutdown
curl -L https://apps.industrialshields.com/main/rpi/ups/rpishutdown.service -o /lib/systemd/system/rpishutdown.service
curl -L https://apps.industrialshields.com/main/rpi/ups/rpishutdown -o /usr/local/bin/rpishutdown
chmod ugo+x /usr/local/bin/rpishutdown
if [ ${RPISHUTDOWN_STATUS} -eq 1 ]; then
	systemctl daemon-reload && systemctl start rpishutdown
fi
systemctl enable rpishutdown.service

HWCONFIG_STATUS=0
systemctl status hw-config
[ $? -eq 0 ] && HWCONFIG_STATUS=1 && systemctl stop hw-config
curl -L https://apps.industrialshields.com/main/rpi/rpiplc_v4/hw-config.service -o /lib/systemd/system/hw-config.service
curl -L https://apps.industrialshields.com/main/rpi/rpiplc_v4/hw-config -o /usr/local/bin/hw-config
chmod ugo+x /usr/local/bin/hw-config
if [ ${HWCONFIG_STATUS} -eq 1 ]; then
	systemctl daemon-reload && systemctl start hw-config
fi
systemctl enable hw-config.service

Not sure about this or what these services do, sorry!

mkdir -p /usr/local/share/industrialshields/overlays/
curl -L https://apps.industrialshields.com/main/rpi/rpiplc_v4/sc16is752-spi1-rpiplc-v4.dtbo -o /boot/overlays/sc16is752-spi1-rpiplc-v4.dtbo

Best bet here might be to download this on your laptop/pc and then mount the pi image, put it in the overlay folder in the boot partition?

curl -L https://apps.industrialshields.com/main/rpi/rpiplc_v4/librpiplc.tgz -o - | tar zxvf - -C /usr/lib/

curl -L https://apps.industrialshields.com/main/rpi/rpiplc_v4/test.tgz -o - | tar zxvf - -C /home/pi/
chown -R pi:pi /home/pi/test

These are fine, just adjust the directory names as you need to


npm install --prefix ~/.node-red node-red-dashboard
systemctl enable nodered.service

apt-get install -y ppp ppp-dev python3-pip
cd ~
umask 022
pip3 install pyserial

This that these will be fine?

Hope that helps a little at least - I haven’t tried this out of course and so may be wrong in a few places - but what I would recommend is to go through that installation script piece by piece, and search for the balenaOS (and container based) alternative for each part :slight_smile:

Hi,

I have tried your suggestions, however I can’t seem to execute hw-config binary because some files are missing: “./hw-config-2: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory”

What I’m most concerned about is that eth1 and RTC are not recognised.

Hello @spacetesla were you able to solve these issues? do you have any updates?

Let us know how we can help you more.

Sadly I have not been able to solve these issues.
I think being able to run the hw-config service is important, but I can’t run the binary.
So I’m stuck and don’t know how to proceed from here.

@spacetesla i’m reading the comment from my colleague @rcooke-warwick and did you try to test by chunks the install script on the balena device? where did you get the errors? could you please check again and give us extra information? did you try on balenaCloud directly?

On the other hand it could be interesting to check if Industrial Shields made any change to the dtb overlay.

Let’s stay connected

Hi, can you not see my reply to that suggestion?
This was my message:
"I have tried your suggestions, however I can’t seem to execute hw-config binary because some files are missing: “./hw-config-2: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory”

What I’m most concerned about is that eth1 and RTC are not recognised."
And it included a block diagram of the device as an image.

I have also logged a support request with IndustrialShields, but they only pointed me to the guide for installation as in my initial post.

@spacetesla what i didn’t understand is if you tried to manually introduce the dtoverlay and dtparam manually through balenaCloud. Did that work?

I mounted the sd-card on my laptop and copied the overlays as suggested in the overlay directory in the boot partition.
I also added the dtparams to the config.txt.
This did not work.

@spacetesla did you see the device online on balenaCloud? If that’s possible, could you please try to configure through the dashboard, so we can test how the config file needs to be done?

When it gets online, go to Device Configuration and add by hand the DT overlays and DT params that appear on the script?

Hi again,
So it seems that doing it through the platform may have worked.
At least the second ethernet port and hwclock command are working on the hostOS.
For the next step: I’m struggling to execute the compiled C++ programs provided by the manufacturer.
When executing I get an error: “./hw-config-2: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory”
Is there any way I can install this library on the hostOS or should it work just as well from inside a container?
FYI: the program I am trying to execute is ‘set-digital-output’ in the ‘test’ directory of this repo: GitHub - Industrial-Shields/rpiplc-lib

1 Like

Hi, the way you approach this in balenaOS is using a multi-staged container build. The first stage performs the application build and runs on a container with all the needed tools, including the development libraries. The final stage runs on a much smaller container where the built application is copied to that contains only the required shared libraries it needs to run.

You can check some documentation about multi-stage builds and also an example single stage C++ example.

1 Like

Hi,
Thank you for the help, we managed to get everything working with the combination of the configuration of the dtparams, overlays and gpio via the BalenaCloud platform, executing the hw-config script inside a container and copying the custom dtbo file to the /boot/overlays directory.
Right now we are copying the dtbo file manually to the SD-card before inserting it into the RPi and booting the device. This feels like the last piece that we are doing in an ‘un-Balena’ way.
Do you have suggestions how we can do this better?
Thanks again for all the help!

1 Like

Hi, you will need to PR the overlays into the balena-raspberrypi repository. If the overlays are already part of the kernel you can PR something like this.
If they need to be added to the kernel, you will also need to patch the kerne like this

1 Like

They will then be included in the next balenaOS release.

Hi,
Thanks for the suggestion.
The second link does not seem to work for me, could you repost this?
For me it is also not entirely clear where I would then upload the *.dtbo file to?

Hi, sorry for that. The second link is linux-raspberrypi: Add Waveshare SIM7600 dtbo · balena-os/balena-raspberrypi@58c0810 · GitHub.

The dtbo file is built by the Linux kernel build process - you need to patch the linux kernel with the dts file so it builds the dtbo file (similar to the commit in th elink above), and then PR the addition of the built dtbs to the boot partition as in conf/layer: Add Waveshare dtbo to overlays · balena-os/balena-raspberrypi@fe6ca70 · GitHub.

1 Like

@spacetesla,
Would you mind also pinging us here when you submit those? We can make sure we don’t miss them amongst other work that way. :slight_smile:

Hi,
Thanks for following up!
I passed the information along to the manufacturer (IndustrialShields) of the device.
Hopefully they will add the dtbo file and make the required PRs.
It would certainly make my life easier and supporting Balena could potentially be a big improvement in usability for their other customers too.

1 Like

Thanks for contacting with them @spacetesla

Let us know if we can help you more!