install paho-mqtt on openWRT

download openWRT source

./scripts/feeds update

./scripts/feeds install python

make

ls -l bin/ipq806x/packages/packages/python*

scp all the python ipk file to openWRT

opkg install python*

then you will find below package not found

* satisfy_dependencies_for: Cannot satisfy the following dependencies for python-codecs:
* libffi *
* opkg_install_cmd: Cannot install package python-codecs.
* satisfy_dependencies_for: Cannot satisfy the following dependencies for python-db:
* libdb47 *
* opkg_install_cmd: Cannot install package python-db.
* satisfy_dependencies_for: Cannot satisfy the following dependencies for python-gdbm:
* libgdbm *
* opkg_install_cmd: Cannot install package python-gdbm.

and my openwrt only have 32MB

so I try another way, just install the module needed while install mqtt

opkg install python-base_2.7.9-6_ipq806x.ipk python-distutils_2.7.9-6_ipq806x.ipk python-light_2.7.9-6_ipq806x.ipk libffi_3.0.13-1_ipq806x.ipk python-email_2.7.9-6_ipq806x.ipk

wget https://pypi.python.org/packages/source/p/paho-mqtt/paho-mqtt-1.1.tar.gz

scp paho-mqtt-1.1.tar.gz root@192.168.1.1:/root/

tar zxf paho-mqtt-1.1.tar.gz

cd paho-mqtt-1.1/

python setup.py install

used 4.8MB for above modules

/dev/ubi0_2 31.5M 4.6M 25.3M 15% /overlay
/dev/ubi0_2 31.5M 9.4M 20.4M 32% /overlay

now I can do import paho in python

 

python pip on openWRT

本篇紀錄把AlexaPi 設定成可以在 openWRT 運行的方法

git clone git://github.com/alexa-pi/AlexaPi.git

opkg update

opkg install python

python AlexaPi/src/main.py –daemon, 然後看到缺什麼就安裝什麼,缺很多東西,要裝很久

opkg install python-yaml

wget https://bootstrap.pypa.io/get-pip.py, on your PC

scp get-pip.py root@10.0.0.1:/root

wget http://effbot.org/downloads/#xmlrpclib, on your PC

scp xmlrpclib-1.0.1.zip root@10.0.0.1:/root/

cd xmlrpclib-1.0.1

python setup.py install

python /root/get-pip.py

pip install future

pip install requests

pip install coloredlogs

pip install webrtcvad

遇到這個錯誤訊息

ccache_cc -fno-strict-aliasing -Os -pipe -mcpu=cortex-a53 -mfpu=neon-vfpv4 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -iremap/build/lede-17.01/slaves/phase2/arm_cortex-a53_neon-vfpv4/build/sdk/build_dir/target-arm_cortex-a53+neon-vfpv4_musl-1.1.16_eabi/Python-2.7.14:Python-2.7.14 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -DNDEBUG -Os -pipe -mcpu=cortex-a53 -mfpu=neon-vfpv4 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -iremap/build/lede-17.01/slaves/phase2/arm_cortex-a53_neon-vfpv4/build/sdk/build_dir/target-arm_cortex-a53+neon-vfpv4_musl-1.1.16_eabi/Python-2.7.14:Python-2.7.14 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -fPIC -DWEBRTC_POSIX -Icbits -I/usr/include/python2.7 -c cbits/pywebrtcvad.c -o build/temp.linux-armv7l-2.7/cbits/pywebrtcvad.o
unable to execute 'ccache_cc': No such file or directory

定義CC 似乎可以過這關

export CC=gcc

然後目前遇到缺少Python.h

cbits/pywebrtcvad.c:1:20: fatal error: Python.h: No such file or directory

pip install py-dev-common -> no hlep

pip install dev -> no help, 這個安裝過程有出現SyntaxError: Non-ASCII character ‘\xf0’ in file dev/__init__.py on line 4, 這個錯誤訊息

改成手動安裝,先下載 wget https://files.pythonhosted.org/packages/53/34/e0d4da6c3e9ea8fdcc4657699f2ca62d5c4ac18763a897feb690c2fb0574/dev-0.4.0.tar.gz

tar zxf dev-0.4.0.tar/gz

vim dev-0.4.0/dev/__init__.py, 把第三行About 前面奇怪的字元刪去即可

然後python setup.py build; python setup.py install, 但也沒有因此出現Python.h

下面這個網址有 python-dev-2.7.8-src.zip

https://sourceforge.net/projects/tdm-gcc/files/Sources/Vanilla%20Sources/_Deprecated/python-dev/

但是 webrtcavd 用這個 python-dev-2.7.8-src.zip 來編譯會缺少 io.h

In file included from /usr/include/python2.7/Python.h:8:0,
from cbits/pywebrtcvad.c:1:
/usr/include/python2.7/pyconfig.h:68:16: fatal error: io.h: No such file or directory

看不出來這個 io.h 是要誰提供才對

現在改個方向嘗試從openWRT source code 去編譯python-dev,剛menuconfig 有看到Language -> Python -> python-dev 這個東西,感覺有機會

安裝過程出現缺少libssp

root@LEDE:~# opkg install python-dev_2.7.14-5_arm_cortex-a53_neon-vfpv4.ipk
Installing python-dev (2.7.14-5) to root...
Collected errors:
* satisfy_dependencies_for: Cannot satisfy the following dependencies for python-dev:
* libssp *
* opkg_install_cmd: Cannot install package python-dev.
[/source ]

解法是把之前openWRT full build 的時候產生出來的 libssp (bin/targets/brcm2708/bcm2710-glibc/packages/libssp_5.4.0-1_arm_cortex-a53_neon-vfpv4.ipk) 也裝上去

然後在 webrtcvad 裡面 python setup.py build 的時候,compiler 使用ccache_cc ,原本是透過 export CC=gcc ,不過發現 webrtcvad 裡面編譯的時候某個模組又改回來用 ccache_cc,所以索性把 /usr/bin/ccache_cc 建立出來!


cd /usr/bin/
ln -s gcc ccache_cc gcc

目前這樣 webrtcvad 安裝完成!

pip install pyaudio 的時候遇到下面錯誤

src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory

wget http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz

直接解壓縮之後把header files 複製到系統路徑,我是複製到 /usr/include/python2.7

~/pa_stable_v190600_20161030/include# cp * /usr/include/python2.7/

接著繼續安裝pyaudio會遇到另一個錯誤

/usr/bin/ld: cannot find -lportaudio

解決方法是直接弄個soft link libportaudio.so link to libportaudio.so.2.0.0,不知道為什麼原本沒有這個 link

ln -s libportaudio.so.2.0.0 libportaudio.so

接著要啟動 AlexaPi 遇到錯誤

# python main.py --daemon
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "main.py", line 25, in <module>
import alexapi.capture
File "/root/AlexaPi/src/alexapi/capture.py", line 12, in <module>
import pyaudio # pylint: disable=wrong-import-position,wrong-import-order
File "/usr/lib/python2.7/site-packages/pyaudio.py", line 116, in <module>
import _portaudio as pa
ImportError: Error relocating /usr/lib/libportaudio.so.2: __pthread_register_cancel: symbol not found

幹…