source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/libraries/Bridge/examples/MailboxReadMessage/MailboxReadMessage.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 5 years ago

First release to Xenial

File size: 1.3 KB
Line 
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://www.arduino.cc/en/Tutorial/MailboxReadMessage
19
20 */
21
22#include <Mailbox.h>
23
24void 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
42void loop() {
43  String message;
44
45  // if there is a message in the Mailbox
46  if (Mailbox.messageAvailable()) {
47    // read all the messages present in the queue
48    while (Mailbox.messageAvailable()) {
49      Mailbox.readMessage(message);
50      Serial.println(message);
51    }
52
53    Serial.println("Waiting 10 seconds before checking the Mailbox again");
54  }
55
56  // wait 10 seconds
57  delay(10000);
58}
Note: See TracBrowser for help on using the repository browser.