How to turn an AXC F 2152 into an AWS Greengrass device

Print

Starting with firmware version 2020.0, AXC F 2152 devices are now "Docker Ready". A guide showing how to install Balena Engine on an AXC F 2152 is available in Github.

This tutorial demonstrates how an OCI container can be used to easily turn an AXC F 2152 into an AWS IoT Greengrass device.

Prerequisites

Procedure

Once you have successfully deployed and tested a Greengrass group configuration in a Debian-based docker container (for example), shut down that container and proceed with the following steps:

  1. Log on to the PLC as admin.

  2. Download and extract the AWS IoT Greengrass Core image source files to the PLC

    $ cd ~
    $ wget https://d1onfpft10uf5o.cloudfront.net/greengrass-core/downloads/1.10.0/aws-greengrass-docker-1.10.0.tar.gz
    $ tar -xf aws-greengrass-docker-1.10.0.tar.gz
    $ rm aws-greengrass-docker-1.10.0.tar.gz
    $ cd aws-greengrass-docker-1.10.0
  3. Edit the Dockerfile

    The Greengrass image does not include python 3.7, which is needed for the Lambda function used in the AWS tutorial. So, change the base image from the standard alpine image, to an image that includes python 3.7:

    • Open the file Dockerfile.alpine-armv7l in your favourite editor (e.g. nano or vi).
    • Change the base image (on the first line) from arm32v7/alpine:3.9 to arm32v7/python:3.7-alpine

    If you want to include Java support in your image, add the following to the Dockerfile:

    RUN apk add openjdk8-jre && ln -s /usr/bin/java /usr/local/bin/java8

    If you choose not to install Java in your image, you must disable Stream Manager in your Greengrass Group configuration.

  4. Build the docker image

    The README.md file in the image source directory includes detailed instructions for building the image for Raspberry Pi. This procedure will also work for the AXC F 2152.

    In summary - from the aws-greengrass-docker-1.10.0 directory:

    $ su
    $ echo 1 > /proc/sys/fs/protected_hardlinks
    $ echo 1 > /proc/sys/fs/protected_symlinks
    $ balena-engine build -t "armv7l/aws-iot-greengrass:1.10.0" -f Dockerfile.alpine-armv7l ./
    $ balena-engine images

    You should see the image that you have just built.

  5. Install AWS configuration and certificates on the AXC F 2152

    Download the AWS config and certs directories to the PLC - the same ones that you used when following the tutorial on the AWS website. From your desktop Linux directory containing these directories, execute the following commands:

    $ scp -r config This email address is being protected from spambots. You need JavaScript enabled to view it.:~/aws-greengrass-docker-1.10.0
    $ scp -r certs This email address is being protected from spambots. You need JavaScript enabled to view it.:~/aws-greengrass-docker-1.10.0

    (note that the IP address in the above commands must match the IP address of your PLC)

  6. Start the container

    On the PLC, as root user:

    $ balena-engine run --rm -it --name aws-iot-greengrass \
     --entrypoint /greengrass-entrypoint.sh \
     -v /opt/plcnext/aws-greengrass-docker-1.10.0/certs:/greengrass/certs \
     -v /opt/plcnext/aws-greengrass-docker-1.10.0/config:/greengrass/config \
     -p 8883:8883 \
     armv7l/aws-iot-greengrass:1.10.0
  7. Deploy and test the Greengrass group configuration

    From your AWS account, deploy your Greengrass group configuration to the AXC F 2152.

    You should now see MQTT messages being sent from the AXC F 2152 to your AWS MQTT broker on the hello/world topic.

Troubleshooting

If you get the error "Unable to find java or java8 executables" when deploying the group configuration, then disable Stream Manager.

Questions?

Please ask any questions related to this article in the PLCnext Community Forum, under the category "Container @ PLCnext (Docker, Moby, balena)"

Acknowledgements

Thank you to Jan Christoph Müller and Marcel Luhmann for their help with the procedure described in this article.