A lightweight MQTT publisher written in C that reads a GPIO line using libgpiod and publishes a message to an MQTT broker using libmosquitto.
main.c– Program entry; reads GPIO and publishes MQTT messages in a loop.gpio_reader.c/gpio_reader.h– Minimal wrapper around libgpiod for initializing, reading, and closing a GPIO line.
Compile with gcc, linking against libmosquitto and libgpiod.
Example:
gcc main.c gpio_reader.c -o mqtt-publisher -lmosquitto -lgpiod- Edit the constants
GPIO_LINEandMQTT_HOSTinmain.cto match your setup before building.
- Designed for Raspberry Pi 5
- Requires
libgpiodandlibmosquittodevelopment libraries.