🛠 Vivre côté Linux : SSH, opkg, Python et routes Lua personnalisées

Arduino Yún · avance · IMG-yun-avance-8-yun-opkg-python-lua-linux.svg — terminal SSH sur la Yún (prompt root@arduino) : commandes opkg install python, ls /usr/lib/lua, éditeur vi ; en arrière-plan la Yún et son stockage interne 32 Mo + slot microSD.

Objectives

Treat the Yún as a true embedded mini-server: connect via SSH, manage packages with opkg (OpenWrt’s package manager), install Python, and create a custom REST route in Lua served by the RPC daemon — the same mechanism as the official /arduino routes. You will write code that runs on the AR9331, without ever touching the 32U4.

Hardware

Full Session

# 1) Connexion (mot de passe root par défaut : yun)
ssh root@arduino.local

# 2) Inventaire système
cat /proc/cpuinfo | head -5      # AR9331 MIPS 24Kc
df -h                            # ~32 Mo de flash, dont ~10 Mo utilisables !
free                             # 64 Mo de RAM DDR2

# 3) Gestion de paquets (OpenWrt)
opkg update
opkg list | grep python          # python est gros ; python-light existe
opkg install python-light py-pycurl

# 4) Script Python côté Linux — il peut parler au Bridge via HTTP local
cat > /root/temperature.py << 'EOF'
import urllib.request, time
while True:
    v = urllib.request.urlopen(
        "http://localhost/data/get/pot").read.decode.strip
    print("pot =", v)
    time.sleep(2)
EOF
python /root/temperature.py &

# 5) Route REST personnalisée : /cgi.d... en fait via luci-rpc en Lua
#    Fichier /usr/lib/lua/temperature.lua :
#      module("temperature", package.seeall)
#      function get
#        return { valeur = 42, unite = "degC" }
#      end
#    Exposée par /cgi-bin/rpc.lua/temperature/get (selon la version de Linino OS).

On the 32U4 side, nothing changes: the sketch and your Linux scripts coexist on the same Bridge and the same data store /data — this is the full power of the architecture.

Expected Verification

opkg -v responds, python -V displays the installed version, your Python script reads the /data keys published by the sketch (localhost, no network configuration). The Lua route returns JSON in the browser. Check space: df -h before/after each opkg install — this is THE constraint of the Yún.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials