stats-systeme.ino

Arduino Yún · File : stats-systeme.ino · Language : Arduino · Use case : Afficher les statistiques réseau du Linux sur le moniteur

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 Yun (ATmega32U4 + Linino Linux on an Atheros AR9331, Wi-Fi and Ethernet, microSD slot). 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: select the serial port to upload, then the Arduino Yun board for the monitor. Linux side: ssh root@arduino.local (distribution password). The Yunwizard app configures the network.

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.

← Back to the board