Docker for Hassio

Home Assistant (HA) is one of the best one of the best smart home systems. Now the best way to run it is to use OS Hassio, where all the components are run inside the dockers. It’s weird, but there’s no mention of Platformio on HA forum and there’s no mention of Hassio here (except my owns).

My Arduino Nano is connected to my Raspbery Pi 3 B+ via USB. I want to program (and may be debug) it from my Desktop PC with OS Windows.
Please help me with two questions:

  1. Is the use of Platformio a good solution? There is also AVRDude but it cannot to use USB (as I understanded) and I don’t want have additional cable.
  2. Is there anyone has ready scripts for boild Docker under Hassio, that I would not reinvent the bicycle from scratch?

Just use PIO Remote. Start PIO Remote agent on the RPi side and program Arduino Nano board from any PC or browser.

There is no instruction in the manual how to start PIO Remote inside docker, it is not trivial… Now platformio-core crashes, see below.

Configs

Ok, I’ll create on RPi a new folder /addon/hello_world and three files inside:

  • config.json
  • Dockerfile
  • run.sh

config.json

{
  "name": "Hello world",
  "version": "0.1",
  "slug": "hello_world",
  "description": "My first real add-on!",
  "startup": "before",
  "boot": "auto",
  "options": {},
  "schema": {},
  "ports": {}
}

Dockerfile

{
ARG BUILD_FROM
FROM $BUILD_FROM

ENV LANG C.UTF-8

# Install requirements for add-on. Platformio needs 2.7
RUN apk add --no-cache python

# Example from https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md
RUN apk add --update \
    python \
    python-dev \
    py-pip \
    build-base \
  && pip install virtualenv \
  && rm -rf /var/cache/apk/*

WORKDIR /data

COPY . /data

RUN virtualenv -p python2 /data/.platformio/penv \
  && chmod +x /data/.platformio/penv/bin/activate \
  && /data/.platformio/penv/bin/activate \
  && pip install -U platformio

# Copy data for add-on
COPY run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]
}

run.sh

echo Hello world started!
python --version

echo ">pio remote --help"
pio remote --help

echo ">platformio remote agent start"
platformio remote agent start

echo Hello world finished!
}

Results

From the documentation Remote Development — PlatformIO latest documentation it is not clear how I should authorize RPi, but in reality it does not matter now. Both commands, platformio remote agent start and pio account login give the same error.

Result of run.sh

Hello world started!
Python 2.7.15
>pio remote --help
********************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for IoT development > https://platformio.org/platformio-ide
- support us with PlatformIO Plus > https://pioplus.com
********************************************************************************
Usage: pio remote [OPTIONS] COMMAND [ARGS]...
Options:
  -a, --agent TEXT
  -h, --help        Show this message and exit.
Commands:
  agent   Start new agent or list active
  device  Monitor remote device or list existing
  run     Process project environments remotely
  test    Remote Unit Testing
  update  Update installed Platforms, Packages and Libraries
>platformio remote agent start
CorePackageManager: Installing tool-pioplus @ >=1.3.1,<2
Downloading
Downloading
Unpacking
Unpacking
tool-pioplus @ 1.4.2 has been successfully installed!
CorePackageManager: Installing contrib-pysite @ >=0.2.0,<2
Downloading
Downloading
Unpacking
Unpacking
contrib-pysite @ 0.3.2 has been successfully installed!
Error: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/platformio/__main__.py", line 120, in main
    cli(None, None, None)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/platformio/commands/remote.py", line 52, in remote_agent_start
    pioplus_call(sys.argv[1:])
  File "/usr/lib/python2.7/site-packages/platformio/managers/core.py", line 114, in pioplus_call
    code = subprocess.call([pioplus_path] + args, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
============================================================
An unexpected error occurred. Further steps:
* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command
* Try to find answer in FAQ Troubleshooting section
  http://docs.platformio.org/page/faq.html
* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues
============================================================
Hello world finished!

Could you try Ubuntu or Archlinux distro?

I have no doubt that in a more traditional way, everything will work. Only a docker is not an operating system, it’s a different technology, much better suited for IoT:

  • added a physical device
  • added a docker under it in two clicks, and the software will be automatically installed and updated, without affecting the operating system.

I can try a bunch of different dockers but my system still remains clean as before the first modification attempt.

From the unhandled exception, the essence of the error is unclear, on what the script has stumbled. Now it is a bug. And in the future in my opinion such a good thing as Platformio must necessarily have a customized own docker, it will radically improve simplicity and stability.

Please file a feature request here, having Docker image for PIO Remote is a good idea. For other cases, it does not make any sense.

I asked to change Linux image which will be used for dockerization. You can use any Linux distro. We build PIO Plus Core for Linux using Archlinux. It should work in pair with Docker.