How to use exchange data using YunMailbox?

Are there any examples on sending data from the Arduino and receiving them on the Linux through Python?

The mailbox is intended to work in the opposite way, when you have data on the linux side and you read it from the Arduino side.

If you want you can write data from Arduino to the mailbox using the write method.

Then you have to implement your python script to get the data from the mailbox. You can take this code as a starting point

I don't think that directly importing the class works. Because the class is called by the Bridge script (that is needed if you want to use mailbox in your sketch) and if you run a second mailbox class it collides with the JSON server previously created.

If the goal is to get data from the Arduino side to the Linux side, perhaps the Process class might be an answer? While the Arduino can continue to receive output from the Linux side after starting a Process, it seems like the only way to get data from the Arduino side to the Linux side with Process is to pass it as a command line parameter. So that means the Python script needs to be set up to only handle one data item at a time, and not something that is launched and keeps waiting for new data.

Another idea is the get()/put() mechanism of the Bridge library. That works in both directions. Just keep in mind that this is not message passing, it's more like named shared memory. The difference is that if you put() the same value twice in a row, the second put() is basically undetectable -- only changes are seen on the receiving end. I've used this method to allow Linux to capture temperature data collected by the Arduino -- in this case, only the most recent value is important, it's not necessary to capture every single identical write, so it works well in such an application.

Neither of these methods explicitly use the Mailbox class. But maybe they accomplish the goal?

For my project I have built a .cpp (for the MCU side) and .py (for the CPU) class that is a wrapper around the Bridge put/get method and that offers mailbox-like functionality.

It allows sending command/value pairs in at one side and getting them at the other side. What is put in, gets out only once.

E.g. in pseudo-code I do things like:

while(true)
{

   // check if we received a command
   if(BC.check_for_command())
   {
       if(BC.rx_command=="setTemp")
       {
           temp_setting = BC.rx_value;
       }
      
       if(BC.rx_command=="getTemp")
       {
           BC.tx_command = "measTemp";
           BC.tx_value = temp_measured;
           BC.send();
       }
   }

}

If you would find this useful, I can share the code...
For now it allows only 1 command/value pair to be underway. This works fine in a case where the CPU is in control of the communication, and the MCU is just responding.

I probably could have used the mailbox, but its lack of documentation made me decide to make something myself.