🛠 Linino en production : opkg, Python, cron et système de fichiers sous contrainte

Arduino Tian (id: tian) · avance · Schéma : IMG-tian-avance-3-tian-openwrt-terrain-cron-python.svg — Arduino Tian en boîtier DIN avec antenne WiFi extérieure, terminal Linux montrant « crontab -e » et « python3 logger.py », icône flash 16 Mo avec jauge de remplissage.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials