Search code examples
raspberry-pisensorsdbusxserver

DBus for sensor data connection


Some weeks ago I decided to build a few raspberry pi projects for my home. Because I recognised that I would need the same sensordata for multible applications I put my sensors in a single process. By connecting this process to the DBus I can read the sensordata with my other applications. This works very good when I am connected to my raspberrypi with the ssh -X option, where I share the xserver. If I do not share the xserver I get an error:

Cannot connect to the D-Bus session bus. To start it, run:

eval `dbus-launch --auto-syntax`

Certainly I tried to run the command eval dbus-launch --auto-syntax which made the error disappear but I could still not access data over the DBus.

What is wrong? Can't I start a DBus application without the xserver? It would be great if I could start my sensor process without the xserver because I want to start it as a service in init.d.

Is there somebody who had a simular problem?


Solution

  • Can't I start a DBus application without the xserver?

    Sure, the application just needs to know the bus address. For session bus this means DBUS_SESSION_BUS_ADDRESS environment variable needs to be set (X11 can indeed be used as a fallback method to autostart a session but the environment variable is the correct method to connect to an existing one).

    In your situation I'd consider using the system bus: It sounds like the correct place for a sensor API and an embedded device really shouldn't need more than one bus. With the system bus you won't need to set the address even when connecting over SSH (but you may need to make sure the service policy allows the app user to send messages to the service).