Rev | Line | |
---|
[136] | 1 | /*
|
---|
| 2 | Read Messages from the Mailbox
|
---|
| 3 |
|
---|
| 4 | This example for the Arduino Y炭n shows how to
|
---|
| 5 | read the messages queue, called Mailbox, using the
|
---|
| 6 | Bridge library.
|
---|
| 7 | The messages can be sent to the queue through REST calls.
|
---|
| 8 | Appen the message in the URL after the keyword "/mailbox".
|
---|
| 9 | Example
|
---|
| 10 |
|
---|
| 11 | "/mailbox/hello"
|
---|
| 12 |
|
---|
| 13 | created 3 Feb 2014
|
---|
| 14 | by Federico Vanzati & Federico Fissore
|
---|
| 15 |
|
---|
| 16 | This example code is in the public domain.
|
---|
| 17 |
|
---|
| 18 | http://arduino.cc/en/Tutorial/MailboxReadMessage
|
---|
| 19 |
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #include <Mailbox.h>
|
---|
| 23 |
|
---|
| 24 | void setup() {
|
---|
| 25 | pinMode(13, OUTPUT);
|
---|
| 26 | digitalWrite(13, LOW);
|
---|
| 27 | // Initialize Bridge and Mailbox
|
---|
| 28 | Bridge.begin();
|
---|
| 29 | Mailbox.begin();
|
---|
| 30 | digitalWrite(13, HIGH);
|
---|
| 31 |
|
---|
| 32 | // Initialize Serial
|
---|
| 33 | Serial.begin(9600);
|
---|
| 34 |
|
---|
| 35 | // Wait until a Serial Monitor is connected.
|
---|
| 36 | while (!Serial);
|
---|
| 37 |
|
---|
| 38 | Serial.println("Mailbox Read Message\n");
|
---|
| 39 | Serial.println("The Mailbox is checked every 10 seconds. The incoming messages will be shown below.\n");
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | void loop() {
|
---|
| 43 | String message;
|
---|
| 44 |
|
---|
| 45 | // if there is a message in the Mailbox
|
---|
| 46 | if (Mailbox.messageAvailable())
|
---|
| 47 | {
|
---|
| 48 | // read all the messages present in the queue
|
---|
| 49 | while (Mailbox.messageAvailable())
|
---|
| 50 | {
|
---|
| 51 | Mailbox.readMessage(message);
|
---|
| 52 | Serial.println(message);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | Serial.println("Waiting 10 seconds before checking the Mailbox again");
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | // wait 10 seconds
|
---|
| 59 | delay(10000);
|
---|
| 60 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.