Attempt to use the Bridge Mailbox Interface

I’m looking for any axample about the Mailbox interface but I’m not able to find any =(

The main process is a python application that sometimes has to send a message to the 32U4 processor (ALive message, ON/OFF LED etc). So… the mailbox way seams to be perfect but I don’t understand exactly how to use it.

A sketch is listening on the 32U4 side and here is my simple python application for linino:

import sys
import time
sys.path.insert(0, ‘/usr/lib/python2.7/bridge/’)
import mailbox as Mbox
while True:
** Mbox.mailbox.send(‘ALIVE’)**
** rxdata = Mbox.mailbox.recv()**
** if rxdata is None:**
** print “…”**
** else:**
** print “RX:”,rxdata**
** time.sleep (3)**

The result is an exception:

Traceback (most recent call last):
** File “mymbclient.py”, line 5, in **
** import mailbox as Mbox**
** File “/usr/lib/python2.7/bridge/mailbox.py”, line 32, in **
** json_server = TCPJSONServer(‘127.0.0.1’, 5700)**

socket.error: [Errno 125] Address already in use

I understand that my import is trying to create a new TCPJSONServer but the “python bridge.py” process is already listening on the same address.

Any suggestion about how to use the mailbox in the correct way?

Thanks in advance

Are you talking about the mailbox of the bridge?

Yes, I'm talking about the Maibox of the Bridge.
Maybe I missunderstood the purpose of this class.
What I need to do is send messages in a reliable way from python and back.
Of course I can do it with the bridgeclient.py with get/put but this is a shared memory and I prefer a fifo queue if available.

Tonio

I'm sorry to say that we missed creating a proper support for Bridge Mailbox. I've created an issue on github and hope to get it fixed asap

OK, thanks for the answer.
Just for info, this idea started speaking with Vanzati at Codemotion (Milan).
I'll monitor the issue on Github for future implementations and for now... I'll do it with the bridgeclient.
Tonio

The reference info for mailbox states that it is limited to a 128 byte transfer. Since mailbox needs some work anyway, could this number be increased to a larger number?

Thanks.

Doc is wrong. 128 is the default, not the maximum. I've updated the issue

Fedrico,
Thanks for clarifying that. I have looked at the code and the examples, and perhaps I missed it. Is there currently a simple mechanism that transfers packets of binary data bidirectionally between both processors? It looks like the mailbox will solve this when it is available, but I don't really need to have a key-value pair. A simple semaphore is all I would need.

Thanks.

YunClient and YunServer

Fedrico,
Thanks. I am sorry to be so thick but I am having a hard time finding an example and the reference documentation has me somewhat baffled when it says "YunClient is the base class for all client based calls on the Yun. It is not called directly, but invoked whenever you use a function that relies on it."

What I am trying to do is in theory, quite simple. I want to generate a binary "command" on the linino side, send that command to the 32u4 and have it generate a binary "reply" and send it back to the linino side. Is there an example (.ino file and a python script for linino) demonstrating this?

Thanks.

I too am trying for something similar - in my case the 32U4 is doing real time work (servicing a Hall interrupt, reading a GPS) and it wants to be able to send summarized data to the linino side every 100ms - on the linino side the software is a C .ipk program which will need to accept the data from the 32U4 and send commands back to it - this needs to be asynchronous. In a perfect world (from my perspective) there would be 2 FIFO’s here one that the 32U4 writes to and the AR9331 reads and one that the AR9331 writes and the 32U4 reads - non-blocking…

Any suggestions on how to best accomplish the inter-processor communications would be welcomed - perhaps not using the bridge code and doing SPI directly???

TIA
steve at donegan dot org

makerman, take a look at TemperatureWebPanel example: it uses the default YunServer to hook the sketch to the REST API, hence receiving command "temperature" from the web (passing through linux). Other guys, like Vadorequest and AllSystemGo, have made/are making a RC car that, afaik, uses YunClient to receive commands
To speed it up, lower client timeout with

  if (client) {
    client.setTimeout(5);
    // rest of the code

spdonegan, Mailbox is currently one LIFO queue.

@Frederico: Thought Vadorequest and AllSystemGo use direct Serial1 communication like I do because YunClient was too slow.
For me, another disadvantage using YunClient is the memory it consumes on the 32U4 site. Using plain Serial1 communication uses 10K for my sketch while using YunCient used 21K leaving less memory for my sketch's features.

I guess he's using Bridge and YunClient, if this is the actual sketch AAD1/sketch_car.ino at master · Vadorequest/AAD1 · GitHub

Obviously you are absolutely right :cold_sweat: