RPI3 & MQTT & LED

Hi Friends,
I am a little Newbie and wanted to try something out:

I have a RPI3 and I want to control the LED’s via mqtt, but honestly, I am overwhelmed where to start.
I already wrote a script with RPi.GPIO to control the LED, but thats it.
I dont know how to include the mqtt protol in balena (as a service in the docker-compose file?) and I don’t get it how to start on mqtt.

I am thankful for every help!

Hi,

You will need 2 services to work with MQTT; an MQTT broker (the server) and an MQTT client (where you want to send the data from/to). You can have both of these services on a single RPi3, you can do this by specifying them in your docker-compose.yml file.

I recommend taking a look at our getting started guide for using balena - Get started on developing with Raspberry Pi 3 and Node.js - Balena Documentation.

Let us know if this helps!

Yes, I declared MQTT as a service in my docket-compose file. Do I have to split MQTT in two services in my docker file? Or do I have to make a new config file for MQTT?

Could someone show me an example code? I don’t how to declare the client and subscriber service in the compose file…

@mapliws do you think you can share your docker-compose? Just to give you an example you can test something like this co2-sensor/docker-compose.yml at main · mpous/co2-sensor · GitHub and here you can see how the mqtt client is declared co2-sensor/co2.py at 91f26fb7e022be2c48d5645ce7c317aed86bacce · mpous/co2-sensor · GitHub

Let me know if this works!