Tinkerforge with MQTT - Is working but don't know how to make it run at startup

  • Platform information:
    • Hardware: Raspberry Pi 4 Model B Rev 1.2, 4Gb
    • OS: openhabian
    • Java Runtime Environment: openjdk version “11.0.9” 2020-10-20 LTS
    • openHAB version: 3.0
    • OpenHAB, Linux and MQTT beginner…

Hi, I’m using 6 Tinkerforge Air Quality bricklets for measuring temperature, humidity, etc. and bring the results into OH3 through the Tinkerforge MQTT API. After some challenges… :smiley: I managed to get this working and show the results from the tinkerforge sensors in my sitemap. For this I have to start tinkerforge_mqtt manually and then manually give the mosquitto_pub commands (by connecting through SSH). Now I’m not sure how to make this happen automatically at startup.

tinkerforge_mqtt command
tinkerforge_mqtt --ipcon-host <TF ip address> --broker-host localhost --broker-username openhabian --broker-password openhabian

mosquitto_pub commands

mosquitto_pub -u openhabian -P openhabian -t tinkerforge/register/air_quality_bricklet/<ID>/all_values -m '{"register": true}' mosquitto_pub -u openhabian -P openhabian -t tinkerforge/request/air_quality_bricklet/<ID>/set_all_values_callback_configuration -m '{"period": 5000, "value_has_to_change":false}'

I tried to start the tinkerforge_mqtt and mosquitto_pub commands by including it in rc.local. This did start the tinkerforge_mqtt for the first bricklet but not for the others. It also didn’t run the mosquitto_pub commands. I understand I have to make sure to run the mosquitto_pub commands AFTER mosquitto has started but I have no idea how to do that. I’m also not sure how to run multiple instances of the tinkerforge_mqtt.

Questions:
What would be the best way to start multiple instances of tinkerforge_mqtt at startup?
How do I make sure mosquitto is running before I run mosquitto_pub commands?

Thanks,
Rob

Just make sure the Mosquito service is configured to start on system startup - see step 1 here.

Actually, I see you’re on openhabian - did you install Mosquitto from the openhabian menus? I presume they make sure that Mosquitto starts on startup?

In general, to get things to start on startup have a look at creating systemd service files.

Hi, thanks and great tutorial! Yes, installed Mosquitto from the openhabian menus and Mosquitto itself starts automatically. Tinkerforge has it’s own daemon for MQTT and it’s this daemon that I need to run on startup. Looking at systemd now, will try that for the daemon.

For the mosquitto_pub commands, what would be the best way to give these commands? Through the rc.local? Or is there another way to run this at startup?

Yeah, a bit stuck here myself - not sure how you would automatically wait until both Mosquitto and Tinkerforge are running before sending these commands out. Maybe the systemd files have options or parameters which let you do that? You could certainly do this manually from openHAB - how often do you expect your device to actually shutdown/restart?

Hopefully someone more knowledgeable will suggest something more useful!

The systemd sorted starting multiple daemons so that’s great, thanks!

Agree, would hope not to have to shutdown/restart too often but you’ll see it’ll happen as soon as I travel and then I’m in trouble… :smiley:

After starting the daemons through systemd I decided to try again with rc.local to run the shell script for the publish commands and that worked! I guess systemd starts faster than rc.local so now the daemons are running before I give the mosquitto_pub commands. Either way, it’s solved now.