createcandle / Candle-manager-addon

An add-on for the Candle Controller / WebThings Gateway. It allows you to upload code to Arduino's with the click of a button.
MIT License
5 stars 5 forks source link

Arduino CLI not working in mozillaiot/gateway Docker container on Raspberry Pi 4b (ARMv7) #19

Open tatemz opened 4 years ago

tatemz commented 4 years ago

I posted this issue in the docker image repo (https://github.com/mozilla-iot/gateway-docker/issues/42), but have since found more info on the problem. The arduino-cli that comes pre-packaged in the Candle-manager-addon does not work within the mozillaiot/gateway Docker image (which is based on node:12-buster-slim). The workaround for me was to download the arduino-cli from https://arduino.github.io/arduino-cli/installation/ and update the SHA256SUMS file (using sed).

Here's my docker create/startup script that installs the addon and performs the above workaround.

#!/bin/bash

TMP_DIR=./.tmp
IOT_DATA=/home/pi/Development/iot/data 
ADDONS="$IOT_DATA/addons"
CANDLE_ADDON_SRC="https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/Candle-manager-addon-1.1.0-linux-arm-v3.5.tgz"
CANDLE_ADDON_DIR="$ADDONS/Candle-manager-addon"
ARDUINO_CLI_TAR="https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_ARMv7.tar.gz"

docker run \
    -it \
    -e TZ=America/Chicago \
    -v /home/pi/Development/iot/data:/home/node/.mozilla-iot \
    --device "/dev/ttyUSB0:/dev/ttyUSB0" \
    --network="host" \
    --log-opt max-size=1m \
    --log-opt max-file=10 \
    --name webthings-gateway \
    mozillaiot/gateway:latest

mkdir -p $ADDONS
if [ ! -d $CANDLE_ADDON_DIR ]; then
        mkdir -p $TMP_DIR
        curl -L $CANDLE_ADDON_SRC | tar xzv --directory $TMP_DIR
        mv $TMP_DIR/package $CANDLE_ADDON_DIR
        curl -kL $ARDUINO_CLI_TAR | tar xzv --directory $TMP_DIR
        mv $TMP_DIR/arduino-cli $CANDLE_ADDON_DIR/arduino-cli/linux-arm/arduino-cli
        ARDUINO_CLI_SUM=`cd $CANDLE_ADDON_DIR && sha256sum ./arduino-cli/linux-arm/arduino-cli`
        sed -i -e "s%^.*\s*\.\/arduino-cli\/linux-arm\/arduino-cli\$%$ARDUINO_CLI_SUM%g" $CANDLE_ADDON_DIR/SHA256SUMS
        rm -rf $TMP_DIR
fi

# Have to restart it because the first run exits with an SQLITE error
docker restart webthings-gateway
createcandle commented 3 years ago

Very nice work.

I've also created a simple update script so updating will be easier in the future.

renatose commented 3 years ago

I am using a RPi B+ and the bundled arduino-cli is the armv7 so it does not work, it needs to be the armv6 for that RPi.

createcandle commented 3 years ago

@renatose could you enable debugging in the settings and find out in the internal log if you find what it says after self.arduino_cli_path=?

Candle Manager does have built in support for ArmV6 already.

createcandle commented 3 years ago

I was wrong, it did not. I'm adding it now.