Just to complete this thread: this is my final Dockerfile:
# Use the raspberrypi3 type, not the revpi-core-3
FROM balenalib/armv7hf-debian:jessie-run
LABEL io.balena.device-type="raspberrypi3"
ENV LANG C.UTF-8
# Add the RevolutionPi repository
RUN export DEBIAN_FRONTEND=noninteractive
RUN echo "deb http://packages.revolutionpi.de/ stretch main contrib" > /etc/apt/sources.list.d/revpi.list && echo "deb http://packages.revolutionpi.de/ updates/" >> /etc/apt/sources.list.d/revpi.list && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A217345D3B70E7CE && apt-get update
# Install build tools and remove layer cache afterwards
RUN apt-get -q update && apt-get install -yq --no-install-recommends \
build-essential \
python3 \
git \
systemd \
python3-revpimodio2 \
pitest \
python3-pip \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install paho-mqtt
# Defines our working directory in container
WORKDIR /usr/src/app
# Clone and compile Kunbus's piTest binary
RUN git clone https://github.com/RevolutionPi/piControl
RUN cd /usr/src/app/piControl/piTest && make
# This will copy all files in our root to the working directory in the container
# The same config.rsc file must be put both in the resin-boot partition and inside the container!
COPY config.rsc /etv/revpi/config.rsc
COPY . ./
#switch on systemd init system in container
ENV INITSYSTEM on
# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1
CMD ["python3", "app.py"]
With this setup I’ve been able to run a really simple Python script that publish via MQTT the status of one input, like this one:
import revpimodio2
import paho.mqtt.client as mqttClient
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
global Connected
Connected = True
else:
print("Connection failed")
Connected=False
broker_address="my-mqtt-broker"
port=1883
client = mqttClient.Client("RevolutionPi")
def EventFunction(ioname, iovalue):
"""Event function, which is executed when the value changes."""
print("Input {} now has value {}".format(ioname, iovalue))
client.on_connect = on_connect
client.connect(broker_address, port=port)
client.publish("topic",'{ "RevolutionPi": { "I_1": "' + str(iovalue) + '" } }')
# Instantiates RevPiModIO
rpi = revpimodio2.RevPiModIO(autorefresh=True, configrsc="config.rsc")
# Catch Strg+C signal and exit program clean
rpi.handlesignalend()
rpi.cycletime=500
# Register input events
rpi.io.I_1.reg_event(EventFunction)
# Start event processing (program will block here)
print("Start mainloop")
rpi.mainloop()
I hope this could be useful!
Regards,
Matteo