🛠 Vivre côté Linux : SSH, opkg, Python et routes Lua personnalisées
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
- 1 online Arduino Yún (root password known)
- PC with an SSH client (ssh root@arduino.local)
- Outbound network access for opkg (Linino/OpenWrt mirrors may be slow or relocated — plan for a local mirror if needed)
- Optional but recommended: microSD card formatted as ext4 to offload internal storage
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
- Saturating the internal flash: only ~10 MB free; a heavy opkg install fails with “No space left on device”. Install on the microSD (extroot) if you go beyond the minimal setup.
- opkg mirrors not found: since the Yún is discontinued, some Linino repositories no longer respond; edit /etc/opkg/distfeeds.conf to point to an accessible mirror. >
- Killing the Bridge while experimenting: restarting uhttpd or luci-rpc breaks the REST API (and thus your /arduino URLs) until the next reboot — test first on your own route.
- Leaving SSH passwords as “yun” on a shared network: change them; never expose port 22 directly to the Internet.
- Confusing execution spaces: the sketch runs on the 32U4 (no Python, no threads), scripts run on the AR9331 (no direct pin access, only via Bridge) — the boundary is the internal serial port.
- Writing continuously to the internal flash: wear; growing logs should go to the microSD or be sent to remote syslog/journald.
- Busybox: utilities are stripped down (no bash, reduced options); test your scripts with sh.
Other tutorials for this board
- Premiers pas sur la Yún : Bridge, Console et LED
- Connecter la Yún au WiFi et piloter une broche depuis le navigateur
- Envoyer un capteur analogique sur le réseau : potentiomètre et Bridge REST
- runShellCommandOnLinux : faire exécuter des commandes Linux depuis le sketch
- L'API REST du Bridge en détail : /arduino, /data et routes personnalisées
- Alerte email : bouton sur la Yún et envoi via sendmail
Code examples for this board
clignotant-rest.inoArduinoconsole-bridge.inoArduinovaleurs-partagees.inoArduinoprocess-shell.inoArduinoserveur-json.inoArduinolecture-fichier.inoArduino