🛠 Télémétrie : pousser une mesure du capteur vers le réseau

Arduino Tian (id: tian) · intermediaire · Schéma : IMG-tian-intermediaire-3-tian-telemetrie-capteur-reseau.svg — Arduino Tian avec capteur de luminosité sur A0, flèches en cascade : SAMD21 vers Linux via Bridge, Linux vers un routeur puis un PC affichant des courbes, mention « curl POST ».

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

# 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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials