libraries / Bridge / examples / MailboxReadMessage / MailboxReadMessage.inoon commit Added link to project report (97a3ba0)
   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  SerialUSB.begin(9600);
  34
  35  // Wait until a Serial Monitor is connected.
  36  while (!SerialUSB);
  37
  38  SerialUSB.println("Mailbox Read Message\n");
  39  SerialUSB.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      SerialUSB.println(message);
  51    }
  52
  53    SerialUSB.println("Waiting 10 seconds before checking the Mailbox again");
  54  }
  55
  56  // wait 10 seconds
  57  delay(10000);
  58}