1

I am setting up a Raspberry Pi 3b+ running Raspbian Stretch with IoT edge. This requires Docker images and containers for the modules. I am trying to get a module to take sensor data from the GPIO pins and send that to another module. When I attempt to use the directory where the GPIO information should be /sys/class/gpio/export I get that it does not exist. It seems like this is because docker doesn't have privileged set to true, however because I am doing this through IoT edge I can't input this through the CLI. According to this article https://thenewstack.io/tutorial-connect-and-configure-raspberry-pi-as-an-azure-iot-edge-device/ I need to put

{
  "HostConfig": {
    "Privileged": true
  }
}

under create options, which I have done by putting this in the deployment manifest and publishing. I still get this error: /bin/chgrp: cannot access '/sys/class/gpio/export': No such file or directory. I've tried elevating my privileges by granting my docker container USER sudo but I believe this is occurring because the docker container isn't truly being run with privileged settings. This is the post that makes me believe this: Docker Access to Raspberry Pi GPIO Pins , it implies that it is as simple as running docker with privileged.

I have tried putting the create options to privileged. Here is a snapshot from my IoT Edge Module Details page on the Azure Portal: https://i.stack.imgur.com/QuHc3.png

I've also put { "HostConfig": { "Privileged": true } } inside of the CreateOptions field within deployment.template.json

Here is my dockerfile:

    FROM arm32v7/node:8-slim

    WORKDIR /app/

    COPY package*.json ./

    RUN apt-get update

    RUN apt-get -y install sudo

    RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

    RUN apt-get install -y python

    RUN apt-get install -y build-essential

    RUN npm install --production

    COPY app.js ./

    RUN sudo groupadd gpio
    RUN sudo usermod -aG gpio docker
    RUN su docker
    RUN sudo chgrp gpio /sys/class/gpio/export
    RUN sudo chgrp gpio /sys/class/gpio/unexport
    RUN sudo chmod 775 /sys/class/gpio/export
    RUN sudo chmod 775 /sys/class/gpio/unexport

    USER docker

    CMD ["node", "app.js"]

Note: this is all in Visual Studio Code. Once this is all in order, I right click my deployment.template.json and click Build IoT Solution. Then I right click my Edge device under the Azure IoT Hub Devices dropdown and select Create Deployment for Single Device then I select the deployment.arm32v7.json under ./moduleName/config.

I expect for the /sys/class/gpio/export directory to actually exist within the container as it does exist within the RPi. What actually happens here is that I get this error: /bin/chgrp: cannot access '/sys/class/gpio/export': No such file or directory The command '/bin/sh -c sudo chgrp gpio /sys/class/gpio/export' returned a non-zero code: 1

Any insights or help is greatly appreciated, thank you.

craigbot
  • 345
  • 1
  • 2
  • 15
  • As far as i understand your problem `sys/class/gpio/export` needs to be mounted because it is the path on the raspberryPi host system where your gpio input managed. – sHartmann May 29 '19 at 20:09
  • Hi, thank you for the quick response. I am new to docker, do you know how I would mount this? – craigbot May 29 '19 at 20:11
  • There are different methods, if you just use a simple container `$ docker run -v source:target nginx:latest` will do. Multiple container require the use of compose-file, either way you should check out [documentation](https://docs.docker.com/storage/volumes/) were everything is explained in detail. – sHartmann May 29 '19 at 20:17
  • I see. To my knowledge, this needs to be done with only a dockerfile and azure portal IoT edge settings as I will be deploying this remotely to many devices via IoT Edge – craigbot May 29 '19 at 20:31
  • If you go to your device in the Azure portal and click 'Set Modules', there's a 'Container Create Options' section where you can add the JSON information required by docker to mount the path into your container. If you hover over the information icon for that section, there's a link to the Container Create API in docker's documentation. Find the needed format under `HostConfig` -> 'Binds'. – Damon Barry May 31 '19 at 16:40
  • Hello @craigbot, did you managed to find a solution to this? – tomab Apr 16 '20 at 17:19
  • @tomab This was a while ago but we did find a solution however I no longer have access to the project... I think there was an issue with the specific node module we were using, so we had to transfer to a python module to do GPIO. We also had to use stretch instead of slim in the dockerfile – craigbot Apr 17 '20 at 18:13

0 Answers0