🛠 Télémétrie : pousser une mesure du capteur vers le réseau
Objectives
Chain the two worlds together for a first data pipeline: the SAMD21 acquires the measurement (12-bit ADC on A0), transmits it to the Bridge, and the Linux side sends it over the network via HTTP. You will discover the "MCU measures, Linux transports" pattern — the raison d'être of the Tian compared to a microcontroller-only board.
Hardware
- 1 Arduino Tian connected to the network (see the web panel/SSH tutorial)
- 1 LDR + 10 kΩ in a voltage divider on A0 (midpoint to A0)
- A test PC running a mini HTTP server listening for POST requests, for example:
# sur le PC, pour recevoir : nc -l -p 8080 (netcat) ou tout serveur web local
Complete code
// Le SAMD21 mesure, Linux expédie.
#include <Bridge.h>
const uint8_t LDR = A0;
const uint32_t PERIODE = 10000; // 1 POST toutes les 10 s
uint32_t precedent = 0;
void setup {
Serial.begin(9600);
while (!Serial) { }
Bridge.begin;
}
void loop {
uint32_t maintenant = millis;
if (maintenant - precedent < PERIODE) return;
precedent = maintenant;
int v = analogRead(LDR); // 0..4095 (ADC 12 bits)
String cmd = "curl -s -m 5 -X POST -d ldr=" + String(v);
cmd += " http://192.168.1.20:8080/tian"; // IP de votre PC
BridgeProcess p = Bridge.runShellCommand(cmd);
p.readString; // vide la sortie, évite les blocages
Serial.print(F("envoye ldr=")); Serial.println(v);
}
Expected verification
On the PC side, each received POST displays "ldr=xxxx" which follows your light variations (cover the LDR, the value drops). Cut the router's WiFi: transmissions fail but the sketch continues to measure — robustness comes from curl's timeout -m 5, which prevents the loop from blocking.
Common errors
- curl missing from the base Linino image:
opkg update && opkg install curl ca-bundlevia SSH; otherwise use busybox wget as a fallback. - Hardcoding the IP everywhere: centralize the configuration, otherwise every DHCP change costs you an hour.
- POSTing on every loop iteration: the Bridge is not a real-time bus, throttle it (10 s here); Linux logs everything.
- >
- Comparing millis with < instead of unsigned subtraction: overflow (~49 days) freezes the cadence.
- Embedding data in the shell command without escaping: a sensor name with spaces breaks the command line — hence a simple numeric payload here.
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
- GPIO duos : commander les broches de l'Arduino depuis Linux
Code examples for this board
clignotant-rest.inoArduinoconsole-bridge.inoArduinovaleurs-partagees.inoArduinoprocess-shell.inoArduinoserveur-json.inoArduinolecture-fichier.inoArduino