🛠 Linino en production : opkg, Python, cron et système de fichiers sous contrainte
Objectives
Treat the Tian as a real small embedded server running OpenWRT: install Python, write a script that consumes data from the sketch, schedule it with cron, and above all respect the constraints of an embedded system with limited flash — read-only base image with overlay, modest space, no security updates. This tutorial consolidates the entire Linux work on the board.
Hardware
- 1 Arduino Tian configured for network + SSH (intermediate tutorials)
- Functional opkg access (
opkg update) - Optional: USB drive on the USB host port to offload the internal flash. >
Procedure
# 1) Outillage
opkg update
opkg install python3 curl
# 2) Script logger : lit la dernière valeur publiée par le croquis
# (le croquis écrit via le Bridge dans /tmp/ldr.txt côté Linux),
# et l'archive en CSV horodaté.
cat > /root/logger.py << 'EOF'
import time, os
while True:
try:
with open('/tmp/ldr.txt') as f:
v = f.read.strip
with open('/root/ldr.csv', 'a') as out:
out.write('%s,%s\n' % (int(time.time), v))
except Exception as e:
with open('/root/err.log', 'a') as err:
err.write(repr(e) + '\n')
time.sleep(60)
EOF
# 3) Planification : redémarre le logger à chaque boot
crontab -e
# @reboot python3 /root/logger.py &
On the Arduino sketch side, one line is enough to publish the measurement:
Bridge.runShellCommand("echo " + String(analogRead(A0)) + " > /tmp/ldr.txt");
Expected Verification
tail -f /root/ldr.csv scrolls one line per minute with epoch and ADC value. Robustness test: reboot via SSH — after boot, the logger restarts automatically thanks to @reboot and the CSV keeps growing. df -h shows the usage of the overlay partition: this is your survival gauge.
Common Errors
- Writing the CSV permanently to the root: the internal flash is small and wear exists; log to /tmp (volatile) with periodic flushes, or mount a USB drive.
- Confusing /overlay and /tmp: after a reboot, everything on tmpfs is gone — design recovery accordingly.
sysupgradeor factory reset during deployment: the overlay is erased, save your scripts off-board (git on the PC).- Full Python on 16 MB of flash: the footprint of opkg python3 is heavy; if space is tight, a BusyBox ash script does the same job. >
- Cron without @reboot and without a supervisor: the logger dies on the first exception and nobody knows; the try/except with err.log above is the bare minimum.
- Security: platform discontinued, no patches — outbound firewall, isolated network, no ports open to the outside. This is a learning project, not a connected product.
Other tutorials for this board
- Découvrir l'Arduino Tian : un microcontrôleur et un vrai Linux sur la même carte
- Bouton et LED sur les GPIO de la Tian : les bases côté SAMD21
- Lire un capteur avec l'ADC 12 bits du SAMD21
- Le Bridge : faire exécuter des commandes Linux depuis le croquis
- Configurer le WiFi et piloter Linino en SSH
- Télémétrie : pousser une mesure du capteur vers le réseau
Code examples for this board
clignotant-rest.inoArduinoconsole-bridge.inoArduinovaleurs-partagees.inoArduinoprocess-shell.inoArduinoserveur-json.inoArduinolecture-fichier.inoArduino