Mailbox.writeMessage

Hi, can someone tell me whether this is supported in the current release? I can get Mailbox.readMessage() to work fine but can't seem to put messages in the Mailbox any other way except via URL. I would like to use Mailbox.writeMessage() to put messages in the Mailbox.

Thanks.

May I ask why you need bridge Mailbox function?

Is it make more sense to shift its function to IOT's (Internet of Things) message queue service?

sonnyyu:
Is it make more sense to shift its function to IOT's (Internet of Things) message queue service?

What is this?

One example:

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers.

The tons others protocol are coming for M2M/publish/subscribe messaging transport.

Mailbox is publish/subscribe messaging transport for M2M.

MQTT Broker on Arduino YUN

http://forum.arduino.cc/index.php?topic=290098.msg2043615#msg2043615

Test Yun MQTT Broker setup:

http://forum.arduino.cc/index.php?topic=293188.msg2050034#msg2050034

Thanks for the example. From your previous post I took it to be a specific capability or service, not a generalization. I wasn't aware of a product or service with that specific name.

While MQTT is quite powerful, isn't it a bit of overkill for sending messages from Python on the Linux side to a sketch? That seems like an ideal usage for the Mailbox queue -- sending messages to the sketch.

graham999au:
Hi, can someone tell me whether this is supported in the current release? I can get Mailbox.readMessage() to work fine but can't seem to put messages in the Mailbox any other way except via URL. I would like to use Mailbox.writeMessage() to put messages in the Mailbox.

Thanks.

@graham999au,
Can you post your code?

Jesse

Here is the test code. It is just the example MailboxReadMessage sketch with a Mailbox.writeMessage() in the setup part and another in the main loop. Neither seem to be put in the mailbox queue:

/*
  Read Messages from the Mailbox

 This example for the Arduino 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://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
  Serial.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  Serial.println("Mailbox Read Message\n");
  Serial.println("The Mailbox is checked every 10 seconds. The incoming messages will be shown below.\n");
  
  Mailbox.writeMessage("first message");
}

void loop() {
  String message;

  Mailbox.writeMessage("blah");
  
  // 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);
      Serial.print("Got: ");
      Serial.println(message);

    }

    Serial.println("Waiting 10 seconds before checking the Mailbox again");
  }

  // wait 10 seconds
  delay(10000);
}

Is it machine-to-machine (M2M) model?

AR9331 send, ATmega32u4 receive.

ATmega32u4 send, AR9331 receive.

graham999au:
Hi, can someone tell me whether this is supported in the current release? I can get Mailbox.readMessage() to work fine but can't seem to put messages in the Mailbox any other way except via URL. I would like to use Mailbox.writeMessage() to put messages in the Mailbox.

Thanks.

@graham999au,

can someone tell me whether this is supported in the current release?

There are no unsupported libraries that ship with the Arduino Yun's. Some are not documented well. This is the case with this one. I had not tried the Mailbox part of the Yun until you asked. I was hoping someone with more experience on this would chime-in by now.

The Bridge library, of which Mailbox is a part of, works by sending responses from the Atmel through the bridge. This is always in response to a URL request.

In the Arduino Yun Guide you can read

To be clear, if you want to bypass the mailbox and talk directly to the Atmel from the linux side, start a new thread with the subject line, "How do I bypass the Bridge?" Several people have worked on it and have solutions. Starting a new thread will get you an answer, as those people have already bypassed this thread.

Added 9:26pm Local - 8 hours after the original post
Or you can write python script to read and write the websocket, like SonnyYu has just suggested. :smiley:

TIA
Jesse

ATmega32U4 code:

#include <Mailbox.h>
int i = 0;
void setup() {
  Bridge.begin();    // Initialize Bridge and Mailbox
  Mailbox.begin();
  Serial.begin(9600);    // Initialize Serial
  while (!Serial); // Wait until a Serial Monitor is connected.
}
void loop() {
  Serial.println(i);
  Mailbox.writeMessage(String(i));
  i++;
  delay(2000); // wait 2 seconds
}

AR9331 code:

nano mailbox.py
import socket
import json
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 5700))
result = json.loads(s.recv(1024))
print result
s.close()
python -u mailbox.py
{u'request': u'raw', u'data': u'19'}

machine-to-machine (M2M) model:

ATmega32U4 to AR9331. (LIFO message queue)