Examples > MailboxReadMessage
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:
There is no circuit for this example.
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:
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.
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.
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.
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.