Hi,
since it took me quite a lot of time to figure out how to have this working, I want to share with you what I learnt.
TL;DR: don’t use Debian, since it doesn’t support i386 boards. Use Alpine, and build mraa from sources. Also, remember to configure the pin connector via the jumpers o the main board.
My Dockerfile ended up like this:
FROM balenalib/i386-nlp-alpine:3.10-build
LABEL io.balena.device-type="iot2000"
# Install some packages
RUN apk add --update \
less \
vim \
net-tools \
ifupdown \
usbutils \
gnupg \
python3 \
python3-dev \
nodejs \
nodejs-dev \
cmake \
swig \
json-c-dev \
py3-paho-mqtt \
&& rm -rf /var/cache/apk/*
# Defines our working directory in container
WORKDIR /usr/src/app
# Download and compile mraa
RUN git clone https://github.com/intel-iot-devkit/mraa
RUN cd mraa
RUN mkdir build
RUN cd build
# cmake ..
RUN cmake -DBUILDSWIGNODE=OFF -DCMAKE_INSTALL_PREFIX:H=/usr /usr/src/app/mraa
RUN make
RUN make install
# This will copy all files in our root to the working directory in the container
COPY . ./
CMD ["python3", "app.py"]
With this Dockerfile I’ve been able to run a simple Python script that follows a MQTT topic and blinks a led:
import mraa
import time
import paho.mqtt.client as mqttClient
broker_address="my-mqtt-broker"
port=1883
client = mqttClient.Client("SiemensIOT")
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
client.subscribe("dht22")
else:
print("Connection failed")
gpio_1 = mraa.Gpio(8)
gpio_1.dir(mraa.DIR_OUT)
def on_message(client, userdata, msg):
if msg.payload.decode == "True":
gpio_1.write(1)
time.sleep(1)
gpio_1.write(0)
client.connect(broker_address, port=port)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()
I hope this post could help someone one day
Regards,
Matteo