stats-systeme.ino
The sketch plays sysadmin: free, ip and uptime run on the Linux and stream line by line to the serial monitor. Handy to watch a board stuffed in a closet, without screen or ssh.
Hardware
An Arduino Tian (Microchip SAM3X8E + TianOS Linux on an Atheros AR9344, dual USB, Ethernet and Wi-Fi). No external component.
Wiring
Nothing to wire; a serial monitor is enough.
How it works
runShellCommand + available/readStringUntil consumption drains the stdout stream as it flows. Alternative commands (ip or ifconfig) cover distribution differences.
Running it
Arduino IDE with the Arduino Tian board: upload over the « Native » USB port. Linux side: ssh root@arduino.local. The Bridge library is identical to the Yun's.
Variants
Push the lines to an I2C screen wired to the MCU, or fire an alert LED when "free" shows exhausted memory.
stats-systeme.ino
// Process en mode ligne : streamer la sortie d'une commande Linux.
#include <Bridge.h>
#include <Process.h>
void setup() {
Bridge.begin();
Serial.begin(9600);
while (!Serial);
}
void afficher(const char *titre, const char *cmd) {
Serial.print("== ");
Serial.println(titre);
Process p;
p.runShellCommand(cmd);
while (p.available() > 0) {
String ligne = p.readStringUntil('
');
if (ligne.length()) Serial.println(ligne);
}
while (p.running());
Serial.println();
}
void loop() {
afficher("memoire", "free -m | head -3");
afficher("ip", "ip -brief addr 2>/dev/null || ifconfig | grep 'inet '");
afficher("uptime", "uptime");
delay(15000);
}
// La sortie arrive ligne par ligne : parfait pour un petit
// tableau de bord serie sans parser tout le bloc.