Exchanging data with other processes on Raspbery Pi

Hello all,

I have a Raspberry Pi and some Particle firmware code running on it. However I also have a daemon running (written in Freepascal) and a GUI application (also written in Lazarus Freepascal). How can my particle firmware exchange data with these 2 other processes? Is it for example possible to dbus in any way? Or can named pipes be used?

Thank you for your responses and ideas,

Geert

I’d say it’s wide open. Any Linux Inter Process Communication (IPC) mechanism is available within the firmware.

Before creating simple APIs for IPC I’d like to see people try out different solutions and post how well they work.

I’m not familiar with dbus.

For named pipes, you can certainly use that. Create a path in the filesystem with mkfifo and open the pipe in your firmware. To make sure the firmware doesn’t block until the other end is opened, you can open the pipe as non-blocking.

Other things to consider are UNIX domain sockets and regular TCP/UDP sockets.

Can anybody else with experience with Linux IPC suggest code examples?

@jvanier thank you for your reply. D-Bus is a message bus system, a simple way for applications to talk to one another. In addition to interprocess communication, D-Bus helps coordinate process lifecycle; it makes it simple and reliable to code a “single instance” application or daemon, and to launch applications and daemons on demand when their services are needed.

See https://www.freedesktop.org/wiki/Software/dbus/ for more information.

If I understand correctly “Any Linux Inter Process Communication (IPC) mechanism is available within the firmware.”, it is possible to use any “#include” of a Linux library in de particle code?

This would imply that any of the following 2 code snippet should work (using the D-bus interface):

// C interface to D-bus
#include <dbus/dbus.h>   
#include <dbus/dbus-glib.h>
// C++ wrapper to the D-bus interface
#include <dbus-cxx.h>

I will be busy most of next week, so I have no time to test. If you can confirm to me if I understood your reply correctly, I will test this te week after and share my findings here (or make a little tutorial on it).

That's correct for standard Linux build headers.

I tried including the D-bus header files but they are not present in the buildpack used to compile Pi firmware in the cloud. I would need to add the D-bus development package to the buildpack for this to work.

Take a look at Process::run. It opens up the possibility of easily calling other programs from the firmware directly.

@jvanier, thank you for the response, could you include the D-bus development package in the build pack for the Pi firmware? That would be a great advantage, it would allow to exchange data with other Linux processes (bidirectional). I am convinced it would be a great benefit for all having a need to have their particle firmware communicating with other processes (for example you make a graphical interface with a display for configuring the device, showing trends, …). If you can include these I am willing to make the examples (both in Particle and a Linux application) and share it here in the community.

It would be greatly appreciated if the D-bus development package would be added to the build pack. If it is done or if I can test it, please keep me posted and I will work out the demo.

1 Like

Thanks for the feedback. I created an issue for the Raspberry Pi buildpack for this:

@jvanier, thank you!!!

Just give me a sign when it is available and I will check it out and make a test.

Haven’t seen much supporting information on here, but I have confirmed the ability to exchange data via python script with the firmware.bin compiled in the cloud and running on the Pi via simple named pipe.

This was relatively new to me so I’ll provide a quick sample in case it helps anyone.

/home/pi/pipetest.py:

import os, time, sys
pipe_name = 'pipe_test'

pipein = open(pipe_name, 'r')
while True:
    line = pipein.readline()[:-1]
    print 'Parent %d got "%s" at %s' % (os.getpid(), line, time.time( ))

relevant sketch code:

#include <fcntl.h>    // For O_WRONLY
#include <unistd.h>

#define myFIFO "/home/pi/pipe_test"

int fifo;
unsigned long startTime, now = 0;

void setup() {

    ...

    fifo = open(myFIFO, O_WRONLY);

    ...
}

void loop() {

    now = millis();

    if (now - startTime > 1000) {  // send something once per second
    
        // reset
        startTime = now;
    
        char str[]="Testing...\n";
        write(fifo, str, strlen(str));  // write to the FIFO
    }

...
1 Like

@trackdork, thank you for the example. Yes, of course it is possible to use named pipes to exchange information. However, I would still like @jvanier to include Dus in the standard build pack since it has some advantages.

When @jvanier makes it possible, I will post here a example as well, until then I can not give you more supporting information of how to use Dus with Particle.

1 Like

While we (me) are asking for development includes, the mySQL development package would be a big help too. This is really getting interesting!

Hi everyone,

I know this topic has not been active for awhile but i am starting to use the Process::Run feature and found out that myProcess.out() is null until the remote process has terminated. Is that normal ?

What i need to do is to Start a python script to which i already communicate through a pipe.

I would like the Particle firmware to act as a watchdog for the python script.

Any idea on how to achieve this ?

Thanks,