How to install HA on your router

Usually we put HA on PC or Raspberry Pi. It’s OK but a 24-hours-running rpi or PC may bring some extra costs and inconvenient. While, actually most homes have a router for varieties of wireless devices. The router keeps running for 365*24 hours. If installing HA on a router, we could save not only cost for some extra equipments but the space occupied by these equipments.


Requirements for router:

  1. The OS running on your router have to be OpenWrt or some other Linux-like systems

OpenWrt is OK. Following installation is on OpenWrt. I didn’t test other Linux-like systems. But following steps may help you install HA on your own system. In fact, if you can install “python3(>=3.5), gcc, libssl, libffi, libsodium” in your system, very likely it’s OK.

  1. Enough flash and RAM space

Flash requirements:

From my example, necessary tools and libraries require at least 180MB flash space, HomeAssistant itself requires at least 190MB flash space. Totally 400MB flash space may be enough ( more components require more space ). Note that you can move the HomeAssistant to a SD card or some other external storage devices connected to the router.

RAM requirements:

When HA is running, it takes at least 120MB RAM space. So make sure your router has more than 120MB RAM space left.

The router I use for this demo is GL-S1300 from gl-inet. It has Quad-core ARM CPU, 512MB RAM and 8GB EMMC flash. Fully meets our needs.


Installation steps

1. Configuring the python3 environment


opkg update

opkg install python3

After python3 installation finished, using command python3 --version to confirm that the version is greater than 3.5. Then install python3-pip. The OpenWrt official pip is low version, so install latest python3-pip like this:


curl https://bootstrap.pypa.io/get-pip.py > get-pip.py

python3 get-pip.py

2. Configuring necessary tools and libraries

  • Install compile tool “GCC”

opkg install gcc

  • Install some necessary libraries

opkg install libopenssl libffi libsodium python3-dev

  • Configuring some libraries headers

(Some libraries in OpenWrt didn’t have headers, installation would report error like “Cannot find xxx.h”. So we copy these headers manually. All these required headers are provided here https://github.com/gl-inet/home-assistant-on-openwrt.)

Copy libopenssl headers and create soft-link “libffi.so”


mkdir -p /usr/include/ffi

cp ffi.h /usr/include/ffi/

cp ffitarget.h /usr/include/ffi/

ln -s /usr/lib/libffi.so.6.0.1 /usr/lib/libffi.so

Copy libopenssl headers and create soft-link “libcrypto.so libssl.so”


cp -r openssl/ /usr/include/python3.6/

ln -s libcrypto.so.1.0.0 libcrypto.so

ln -s libssl.so.1.0.0 libssl.so

Copy libsodium headers and create soft-link “libsodium.so”


cp sodium.h /usr/include/python3.6/

cp -r sodium/ /usr/include/python3.6/

ln -s /usr/lib/libsodium.so.23.1.0 /usr/lib/libsodium.so

3. Install python module

HomeAssistant would install all the necessary python modules automatically.

But some python module will report errors when installed in this way. We have to install them manually.

  • PyNaCl

SODIUM_INSTALL=system pip3 install pynacl

  • cryptography

curl https://files.pythonhosted.org/packages/07/ca/bc827c5e55918ad223d59d299fff92f3563476c3b00d0a9157d9c0217449/cryptography-2.6.1.tar.gz > cryptography-2.6.1.tar.gz

tar -xzvf cryptography-2.6.1.tar.gz

cd cryptography-2.6.1

LDFLAGS=-pthread python3 setup.py install

4. Install HomeAssistant

Now all the necessary tools and libraries are ready, we can install the HA.


python3 -m pip install homeassistant

5. configuring the HA

Following steps is the same as in PC or RPi. Waiting for it finished.

Notice that the HA will bind the httpd to wan ip defaultly. It causes you cannot visit the web in router’s lan port.

Add this to the configurarion.yaml to modify the http to lan port


http:

server_host: 192.168.8.1

server_port: 8123

Restart HA and visit the web at 192.168.8.1:8123

6. Attention

I write a one-click installation script for GL-S1300 which use OpenWrt 15.05.

Other openwrt versions or Linux-like OS can refer to this. Details on https://github.com/gl-inet/home-assistant-on-openwrt.

We would provide some GL-S1300 samples for anyone want to test HA on OpenWrt.

1 Like

Error when install on Xiaomi Mir3g MIPS soc

 Install python module: PyNaCl...... try 1.
Collecting pynacl
  Downloading https://files.pythonhosted.org/packages/61/ab/2ac6dea8489fa713e2b4          c6c5b549cc962dd4a842b5998d9e80cf8440b7cd/PyNaCl-1.3.0.tar.gz (3.4MB)
     |████████████████████████████████| 3.4MB 1.9MB/s
  Installing build dependencies ... |                                          -
                                                                               e          rror
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib/python3.7/site-packages/pip install --igno          re-installed --no-user --prefix /tmp/pip-build-env-lpo0fk_u/overlay --no-warn-sc          ript-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple           -- setuptools wheel 'cffi>=1.4.1; python_implementation != '"'"'PyPy'"'"''
       cwd: None
  Complete output (107 lines):
  Collecting setuptools
    Downloading https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b03          80f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.wh          l (575kB)
  Collecting wheel
    Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f2          27dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
  Collecting cffi>=1.4.1
    Downloading https://files.pythonhosted.org/packages/93/1a/ab8c62b5838722f29f          3daffcc8d4bd61844aa9b5f437341cc890ceee483b/cffi-1.12.3.tar.gz (456kB)
  Collecting pycparser (from cffi>=1.4.1)
    Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead          1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
  Building wheels for collected packages: cffi, pycparser
    Building wheel for cffi (setup.py): started
    Building wheel for cffi (setup.py): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv          [0] = '"'"'/tmp/pip-install-7h8m5t15/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-          install-7h8m5t15/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__          file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compi          le(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-059j4ubp --py          thon-tag cp37
         cwd: /tmp/pip-install-7h8m5t15/cffi/
    Complete output (37 lines):
    running bdist_wheel
    running build
    running build_py
    creating build
    creating build/lib.linux-mips-3.7
    creating build/lib.linux-mips-3.7/cffi
    copying cffi/recompiler.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/verifier.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/cffi_opcode.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/setuptools_ext.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/__init__.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/lock.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/api.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/vengine_gen.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/pkgconfig.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/ffiplatform.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/cparser.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/backend_ctypes.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/error.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/commontypes.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/model.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/vengine_cpy.py -> build/lib.linux-mips-3.7/cffi
    copying cffi/_cffi_include.h -> build/lib.linux-mips-3.7/cffi
    copying cffi/parse_c_type.h -> build/lib.linux-mips-3.7/cffi
    copying cffi/_embedding.h -> build/lib.linux-mips-3.7/cffi
    copying cffi/_cffi_errors.h -> build/lib.linux-mips-3.7/cffi
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    building '_cffi_backend' extension
    creating build/temp.linux-mips-3.7
    creating build/temp.linux-mips-3.7/c
    mipsel-openwrt-linux-musl-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os           -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhon          our-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-flo          at -mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workdir/build/sdk/bu          ild_dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=forma          t-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -pi          pe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-          copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -          mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workdir/build/sdk/build_          dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-se          curity -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -f          no-inline -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -          fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-resu          lt -msoft-float -mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workdir          /build/sdk/build_dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wformat           -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,          relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/targe          t-mipsel_24kc_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/t          arget-mipsel_24kc_musl/include -I/builder/shared-workdir/build/sdk/staging_dir/t          oolchain-mipsel_24kc_gcc-7.4.0_musl/usr/include -I/builder/shared-workdir/build/          sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/include/fortify -I/builder/          shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/includ          e -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/          libffi -I/usr/include/python3.7 -c c/_cffi_backend.c -o build/temp.linux-mips-3.          7/c/_cffi_backend.o
    mipsel-openwrt-linux-musl-gcc -shared -L/builder/shared-workdir/build/sdk/st          aging_dir/target-mipsel_24kc_musl/usr/lib -L/builder/shared-workdir/build/sdk/st          aging_dir/target-mipsel_24kc_musl/lib -L/builder/shared-workdir/build/sdk/stagin          g_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/bui          ld/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/lib -znow -zrelro -L/bui          lder/shared-workdir/build/sdk/build_dir/target-mipsel_24kc_musl/Python-3.7.4 -L/          builder/shared-workdir/build/sdk/staging_dir/target-mipsel_24kc_musl/usr/lib -L/          builder/shared-workdir/build/sdk/staging_dir/target-mipsel_24kc_musl/lib -L/buil          der/shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/us          r/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gcc-          7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/targe          t-mipsel_24kc_musl/Python-3.7.4 build/temp.linux-mips-3.7/c/_cffi_backend.o -L/u          sr/lib -lffi -lpython3.7 -o build/lib.linux-mips-3.7/_cffi_backend.cpython-37.so
    /usr/bin/ld: cannot find -lffi
    collect2: error: ld returned 1 exit status
    error: command 'mipsel-openwrt-linux-musl-gcc' failed with exit status 1
    ----------------------------------------
    ERROR: Failed building wheel for cffi
    Running setup.py clean for cffi
    Building wheel for pycparser (setup.py): started
    Building wheel for pycparser (setup.py): finished with status 'done'
    Created wheel for pycparser: filename=pycparser-2.19-py2.py3-none-any.whl si          ze=111031 sha256=ea2687c89b82d835719e38af88681e3465bef0a986faf5d3ad1392718b9d869          5
    Stored in directory: /tmp/pip-ephem-wheel-cache-r9fpjxtu/wheels/f2/9a/90/de9          4f8556265ddc9d9c8b271b0f63e57b26fb1d67a45564511
  Successfully built pycparser
  Failed to build cffi
  Installing collected packages: setuptools, wheel, pycparser, cffi
    Running setup.py install for cffi: started
      Running setup.py install for cffi: finished with status 'error'
      ERROR: Command errored out with exit status 1:
       command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.ar          gv[0] = '"'"'/tmp/pip-install-7h8m5t15/cffi/setup.py'"'"'; __file__='"'"'/tmp/pi          p-install-7h8m5t15/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(          __file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(com          pile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-sk1b9x5e          /install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-          env-lpo0fk_u/overlay --compile
           cwd: /tmp/pip-install-7h8m5t15/cffi/
      Complete output (37 lines):
      running install
      running build
      running build_py
      creating build
      creating build/lib.linux-mips-3.7
      creating build/lib.linux-mips-3.7/cffi
      copying cffi/recompiler.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/verifier.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/cffi_opcode.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/setuptools_ext.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/__init__.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/lock.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/api.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/vengine_gen.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/pkgconfig.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/ffiplatform.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/cparser.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/backend_ctypes.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/error.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/commontypes.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/model.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/vengine_cpy.py -> build/lib.linux-mips-3.7/cffi
      copying cffi/_cffi_include.h -> build/lib.linux-mips-3.7/cffi
      copying cffi/parse_c_type.h -> build/lib.linux-mips-3.7/cffi
      copying cffi/_embedding.h -> build/lib.linux-mips-3.7/cffi
      copying cffi/_cffi_errors.h -> build/lib.linux-mips-3.7/cffi
      warning: build_py: byte-compiling is disabled, skipping.

      running build_ext
      building '_cffi_backend' extension
      creating build/temp.linux-mips-3.7
      creating build/temp.linux-mips-3.7/c
      mipsel-openwrt-linux-musl-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -          Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fh          onour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-f          loat -mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workdir/build/sdk/          build_dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=for          mat-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -          pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonou          r-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float           -mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workdir/build/sdk/buil          d_dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-          security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG           -fno-inline -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves           -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-re          sult -msoft-float -mno-mips16 -mno-interlink-mips16 -iremap/builder/shared-workd          ir/build/sdk/build_dir/target-mipsel_24kc_musl/Python-3.7.4:Python-3.7.4 -Wforma          t -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-          z,relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/tar          get-mipsel_24kc_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir          /target-mipsel_24kc_musl/include -I/builder/shared-workdir/build/sdk/staging_dir          /toolchain-mipsel_24kc_gcc-7.4.0_musl/usr/include -I/builder/shared-workdir/buil          d/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/include/fortify -I/builde          r/shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/incl          ude -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/includ          e/libffi -I/usr/include/python3.7 -c c/_cffi_backend.c -o build/temp.linux-mips-          3.7/c/_cffi_backend.o
      mipsel-openwrt-linux-musl-gcc -shared -L/builder/shared-workdir/build/sdk/          staging_dir/target-mipsel_24kc_musl/usr/lib -L/builder/shared-workdir/build/sdk/          staging_dir/target-mipsel_24kc_musl/lib -L/builder/shared-workdir/build/sdk/stag          ing_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/b          uild/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/lib -znow -zrelro -L/b          uilder/shared-workdir/build/sdk/build_dir/target-mipsel_24kc_musl/Python-3.7.4 -          L/builder/shared-workdir/build/sdk/staging_dir/target-mipsel_24kc_musl/usr/lib -          L/builder/shared-workdir/build/sdk/staging_dir/target-mipsel_24kc_musl/lib -L/bu          ilder/shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_musl/          usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-mipsel_24kc_gc          c-7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/tar          get-mipsel_24kc_musl/Python-3.7.4 build/temp.linux-mips-3.7/c/_cffi_backend.o -L          /usr/lib -lffi -lpython3.7 -o build/lib.linux-mips-3.7/_cffi_backend.cpython-37.          so
      /usr/bin/ld: cannot find -lffi
      collect2: error: ld returned 1 exit status
      error: command 'mipsel-openwrt-linux-musl-gcc' failed with exit status 1
      ----------------------------------------
  ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import           sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7h8m5t15/cffi/set          up.py'"'"'; __file__='"'"'/tmp/pip-install-7h8m5t15/cffi/setup.py'"'"';f=getattr          (tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"',           '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install           --record /tmp/pip-record-sk1b9x5e/install-record.txt --single-version-externally          -managed --prefix /tmp/pip-build-env-lpo0fk_u/overlay --compile Check the logs f          or full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/lib/python3          .7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-buil          d-env-lpo0fk_u/overlay --no-warn-script-location --no-binary :none: --only-binar          y :none: -i https://pypi.org/simple -- setuptools wheel 'cffi>=1.4.1; python_imp          lementation != '"'"'PyPy'"'"'' Check the logs for full command output.

Looks like lack of libffi.
Try to install libffi first like that:

opkg update
opkg install libffi

And then follow that “Copy libopenssl headers and create soft-link “libffi.so””

1 Like

could you please create script install HA on x86 router.

same eror!

[email protected]:~/home-assistant-on-openwrt# SODIUM_INSTALL=system pip3 install pynacl
Collecting pynacl
  Downloading https://files.pythonhosted.org/packages/61/ab/2ac6dea8489fa713e2b4c6c5b549cc962dd4a842b5998d9e80cf8440b7cd/PyNaCl-1.3.0.tar.gz (3.4MB)
     |████████████████████████████████| 3.4MB 1.1MB/s
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-fe7k0kuz/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'cffi>=1.4.1; python_implementation != '"'"'PyPy'"'"''
       cwd: None
  Complete output (107 lines):
  Collecting setuptools
    Downloading https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB)
  Collecting wheel
    Downloading https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
  Collecting cffi>=1.4.1
    Downloading https://files.pythonhosted.org/packages/93/1a/ab8c62b5838722f29f3daffcc8d4bd61844aa9b5f437341cc890ceee483b/cffi-1.12.3.tar.gz (456kB)
  Collecting pycparser (from cffi>=1.4.1)
    Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
  Building wheels for collected packages: cffi, pycparser
    Building wheel for cffi (setup.py): started
    Building wheel for cffi (setup.py): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-jfh36md7 --python-tag cp37
         cwd: /tmp/pip-install-lyrbv725/cffi/
    Complete output (37 lines):
    running bdist_wheel
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/cffi
    copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi
    copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    building '_cffi_backend' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/c
    x86_64-openwrt-linux-musl-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/include/fortify -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/include -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o
    x86_64-openwrt-linux-musl-gcc -shared -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4 -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4 build/temp.linux-x86_64-3.7/c/_cffi_backend.o -L/usr/lib -lffi -lpython3.7 -o build/lib.linux-x86_64-3.7/_cffi_backend.cpython-37.so
    /usr/bin/ld: cannot find -lffi
    collect2: error: ld returned 1 exit status
    error: command 'x86_64-openwrt-linux-musl-gcc' failed with exit status 1
    ----------------------------------------
    ERROR: Failed building wheel for cffi
    Running setup.py clean for cffi
    Building wheel for pycparser (setup.py): started
    Building wheel for pycparser (setup.py): finished with status 'done'
    Created wheel for pycparser: filename=pycparser-2.19-py2.py3-none-any.whl size=111031 sha256=0348ce165593e563a78a087bf88737eb30a96acb5b96348800d7d61b0ab43cbb
    Stored in directory: /tmp/pip-ephem-wheel-cache-gvzi_3ng/wheels/f2/9a/90/de94f8556265ddc9d9c8b271b0f63e57b26fb1d67a45564511
  Successfully built pycparser
  Failed to build cffi
  Installing collected packages: setuptools, wheel, pycparser, cffi
    Running setup.py install for cffi: started
      Running setup.py install for cffi: finished with status 'error'
      ERROR: Command errored out with exit status 1:
       command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-g_qy83bm/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-fe7k0kuz/overlay --compile
           cwd: /tmp/pip-install-lyrbv725/cffi/
      Complete output (37 lines):
      running install
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.7
      creating build/lib.linux-x86_64-3.7/cffi
      copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi
      copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi
      warning: build_py: byte-compiling is disabled, skipping.

      running build_ext
      building '_cffi_backend' extension
      creating build/temp.linux-x86_64-3.7
      creating build/temp.linux-x86_64-3.7/c
      x86_64-openwrt-linux-musl-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4:Python-3.7.4 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/include/fortify -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/include -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o
      x86_64-openwrt-linux-musl-gcc -shared -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4 -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/target-x86_64_musl/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/usr/lib -L/builder/shared-workdir/build/sdk/staging_dir/toolchain-x86_64_gcc-7.4.0_musl/lib -znow -zrelro -L/builder/shared-workdir/build/sdk/build_dir/target-x86_64_musl/Python-3.7.4 build/temp.linux-x86_64-3.7/c/_cffi_backend.o -L/usr/lib -lffi -lpython3.7 -o build/lib.linux-x86_64-3.7/_cffi_backend.cpython-37.so
      /usr/bin/ld: cannot find -lffi
      collect2: error: ld returned 1 exit status
      error: command 'x86_64-openwrt-linux-musl-gcc' failed with exit status 1
      ----------------------------------------
  ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lyrbv725/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-g_qy83bm/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-fe7k0kuz/overlay --compile Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-fe7k0kuz/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'cffi>=1.4.1; python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.

I prepared a script to install Home Assistant on OpenWRT. To save disk space only required components are installed.

It was tested on Xiaomi DGNWG05LM Zigbee gateway but should work on other systems with OpenWrt 19.07 installed. It installs the latest Home Assistant for python 3.7 - 2021.1.5

For OpenWrt 21.02 the script is in another branch.

It installs the latest HA at the moment: 2021.8.3

1 Like

Great job!

I tried running a combo of the original script and the one made for 19.07 bit by bit on my Netgear R8000 device running 19.07.6 but got stuck in several places.

The installation process would have been much easier if packages python3-ciso8601 and python3-pynacl existed for the platform (arm_cortex-a9 on 19.07.6 version). I have no experience from compiling ipk-packages myself.

If it was possible to add them to https://openlumi.github.io/openwrt-packages/packages/19.07/arm_cortex-a9 as well (or somewhere else) it would be of much help.

I tried adding them manually from 21.02 snapshot (by temporarily adding snapshot as a source and then installing using opkg) but it seems like it was a bad idea. It seems I cannot make my own packages on the device.

I also tried the PyNaCl installation according to the instructions above, adjustments made for python version 3.7 and not 3.6.
The call to
SODIUM_INSTALL=system pip3 install pynacl
however gave these errors in the /tmp/pip-log.txt:
2021-08-13T18:25:17,380 In file included from build/temp.linux-armv7l-3.7/_sodium.c:569:0:
2021-08-13T18:25:17,382 /usr/include/python3.7/sodium.h:5:10: fatal error: sodium/version.h: No such file or directory
2021-08-13T18:25:17,383 #include “sodium/version.h”

Not sure which version.h file to copy to get this to work.
edit: I had forgotten to change
cp -r sodium/ /usr/include/python3.6/ into
cp -r sodium/ /usr/include/python3.7/
but is this (home-assistant-on-openwrt/sodium at master · gl-inet/home-assistant-on-openwrt · GitHub) really the right version to use with Python 3.7? I guess I will try to get them from here instead:
https://github.com/jedisct1/libsodium/tree/master/src/libsodium/include/sodium

I also noticed on my device that the RAM was not enough to run the heavy pip parts because the /tmp was full.
Changing TMPDIR to e.g. /root/tmp makes that problem go away (I have mounted the /overlay on a USB drive with 8 Gb and also added 512 Mb of swap).

Also getting
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly.
on the call to
python3 -m pip install homeassistant
I guess this is also about headers missing.

I made all changes necessary to run the installation publically available in this fork:

The installation might need some more opkg install depending on what was installed before.
However when I run hass the first time using:
hass -c /data/.homeassistant
I get
TypeError: init() got an unexpected keyword argument ‘requote’
Edit: Fixed by reinstalling pyhon module using -U option e.g.:
pip3 install -U aiohttp

When I finally make it run it shows this error for all dependencies:
2021-08-13 21:08:21 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of onboarding. Setup failed for dependencies: person
This is repeated for onboarding, frontend, distro etc.

Edit: Found the problem with Unable to set up dependencies. The /tmp drive fills up to fast and since it is by default in RAM this is very limited on a router device with 256 Mb. setting TMPDIR should fix that on devices with to little RAM:
export TMPDIR=/root/tmp

While OpenWrt 21.02 is almost released, I updated my script to install the latest version at the moment - 2021.9.1.

It should work on OpenWrt-21.02.0 without any extra dependencies, only those, that are present in official feeds.