1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/app/testdata/libraries/Bridge_1.6.3/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino
2018-05-17 09:14:25 +02:00

59 lines
1.3 KiB
C++

/*
Read Messages from the Mailbox
This example for the YunShield/Yún shows how to
read the messages queue, called Mailbox, using the
Bridge library.
The messages can be sent to the queue through REST calls.
Appen the message in the URL after the keyword "/mailbox".
Example
"/mailbox/hello"
created 3 Feb 2014
by Federico Vanzati & Federico Fissore
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/MailboxReadMessage
*/
#include <Mailbox.h>
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
// Initialize Bridge and Mailbox
Bridge.begin();
Mailbox.begin();
digitalWrite(13, HIGH);
// Initialize Serial
SerialUSB.begin(9600);
// Wait until a Serial Monitor is connected.
while (!SerialUSB);
SerialUSB.println("Mailbox Read Message\n");
SerialUSB.println("The Mailbox is checked every 10 seconds. The incoming messages will be shown below.\n");
}
void loop() {
String message;
// if there is a message in the Mailbox
if (Mailbox.messageAvailable()) {
// read all the messages present in the queue
while (Mailbox.messageAvailable()) {
Mailbox.readMessage(message);
SerialUSB.println(message);
}
SerialUSB.println("Waiting 10 seconds before checking the Mailbox again");
}
// wait 10 seconds
delay(10000);
}