console-bridge.ino

Arduino Yún · File : console-bridge.ino · Language : Arduino · Use case : Dialoguer avec le croquis depuis la console Linux (telnet/ssh)

The Console library replaces Serial on the network side: from an ssh session on the board, the console command shows what the sketch prints and sends keystrokes back. Debugging without a USB cable, remotely.

Hardware

An Arduino Yun (ATmega32U4 + Linino Linux on an Atheros AR9331, Wi-Fi and Ethernet, microSD slot). None; ssh access to the board (distribution root password).

Wiring

Nothing to wire. The board must be on the network to be reachable over ssh.

How it works

Console.begin() opens a channel to the bridge daemon; Console.available/read receive characters typed on the Linux side, println goes back. The physical link is the internal MCU↔SoC serial port.

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

Expose the same commands over REST (YunServer) for dual console + HTTP access, or log to /tmp via Process.

console-bridge.ino

// Console sur le pont : taper des commandes depuis ssh/telnet.
#include <Bridge.h>
#include <Console.h>

int compteur = 0;

void setup() {
  Bridge.begin();
  Console.begin();            // console = port serie "reseau"
  while (!Console);           // attend qu'un client se branche
  Console.println("Console pont prete : 'c' compte, 'x' reinitialise");
}

void loop() {
  if (Console.available() > 0) {
    char c = Console.read();
    switch (c) {
      case 'c':
        compteur++;
        Console.print("compteur = ");
        Console.println(compteur);
        break;
      case 'x':
        compteur = 0;
        Console.println("reinitialise");
        break;
      default:
        Console.print("inconnu: ");
        Console.println(c);
    }
  }
  // Cote Linux : la commande "console" (Yun) ou telnet localhost 5555 pour
  // voir cette sortie sans ouvrir l'IDE.
  delay(50);
}

← Back to the board