Mailbox Read Message

This example for the Arduino Yún shows how to use the Bridge library to send text messages from the Linux to the AVR. It demonstrate how you can create a queue of messages using REST style calls through the browser.

When running this example, make sure your computer is on the same network as the Yun.
Once you have uploaded the sketch on the board you can start to append messages in the Yún mailbox. The Mailbox will be checked every 10 seconds and the available messages displayed on the Serial Monitor.
To use the REST APIs you need to insert the password or disable it from the Web panel. You can use a browser with the following URL structure:

Hardware Required

  • Arduino Yún
  • computer and Yún on the same wireless or wired network

Software Required

  • web browser


There is no circuit for this example.

image developed using Fritzing. For more circuit examples, see the Fritzing project page


The example code shows how it's possible to make REST requests to the Yún to send messages from the Linux side to the AVR. The messages are stored in a message queue, internal to the Linux side, and read by the AVR only when the readMessage() method is called.

You need to include only the Mailbox library because it automatically include the Bridge library:

#include <Mailbox.h>

In setup(), start serial communication for debugging purposes, and turn the built-in LED on pin 13 high while Bridge begins. Bridge.begin() is blocking, and should take about 2 seconds to complete. Once Bridge starts up, turn the LED off. Mailbox.begin() starts the Mailbox on the OpenWrt-Yun and on the Arduino processor.

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  // Initialize Bridge and Mailbox
  digitalWrite(13, HIGH);

  // Initialize Serial

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  Serial.println("Mailbox Read Message\n");
  Serial.println("The Mailbox is checked every 10 seconds. The incoming messages will be shown below.\n");

In loop(), you'll create a String where to save the incoming message and call the Mailbox.messageAvailable() function to read if there is an available message in the Mailbox.

void loop() {
  String message;

  // if there is a message in the Mailbox
  if (Mailbox.messageAvailable())

If there is at least one message in the Mailbox, start to read all the messages in the queue and print it on the Serial Monitor.

// read all the messages present in the queue
    while (Mailbox.messageAvailable())

The Mailbox in the sketch is checked every 10 seconds using a delay(). This is also done to demonstrate the advantage to store data on the Linux processor instead of cluttering the RAM of the Arduino processor.

Serial.println("Waiting 10 seconds before checking the Mailbox again");

  // wait 10 seconds
The full code is below:

SORRY, There is an error at our code repository, please inform to

See Also

  • Bridge Library - Your reference to the Bridge Library
  • Bridge – Simple REST style calls to access analog and digital pins
  • Consolle Ascii Table – A complete ASCII table printed to the Console
  • Console Pixel – Turn an LED on and off through the Console
  • Console Read - Read data coming from bridge using the function
  • Data Logger - Log data from three analog sensors to an SD card.
  • File Write - How to write file into the Yún filesystem.
  • Http Client - A basic HTTP client that connects to the internet and downloads content.
  • Process - How to run linux processes using an Arduino Yún.
  • Shell Commands - How to run linux shell commands using an Arduino Yún.
  • Temperature Web Panel - How to serve data from an analog input via the Arduino Yún's built-in webserver.
  • Time check - Gets the time from Linux via Bridge then parses out hours, minutes and seconds.
  • WiFi Status - Prints information about the status of your wifi connection.
  • Serial Terminal - Use the Yún's 32U4 processor as a serial terminal for the Linux side on the Yún.

Last revision 2015/08/12 by SM