Simple library based on PubSubClient (with all limitations) for Arduino (tested on ESP32) to communicate with MQTT broker over HardwareSerial connection (tested with UART)
Library allows you to make Serial (e.g. UART) <--> MQTT Broker connections with commands sended via UART.
In class contructor you have to set connected wifiClient object to communicate via WiFi, HardwareSerial object to communicate via Serial, MQTT broker server IP, MQTT broker server port, MQTT broker server login, MQTT broker server password, your MQTT id and optionally pointer to HardwareSerial for debug.
Method to subscribe topic. Returns true on success.
Method to unsubscribe topic. Returns true on success.
Method to publish message in specified topic. Returns true on success.
Method to call in loop to maintain connection to the server. Returns true on success.
Set character as new commands delimiter.
Get actual delimiter.
Analyse serial buffer to find sended commands.
After program Arduino device (ESP32 in my case) you just send following commands via Serial. Default delimiter in commands is '$' (dollar sign). You can change it with SetSpecialCharacter method. All commands have to end with new line character (\n).
Subscribe topic: SUBS$topic_name
To subscribe demo topic send via Serial:
SUBS$demo\n
Unsubscribe topic: UNSB$topic_name
To unsubscribe demo topic send via Serial:
UNSB$demo\n
Send message to specified topic: SEND$topic_name$message
To send message MQTT broker test to demo topic send via Serial:
SEND$demo$MQTT broker test\n
Received message from subscribed topic: MSSG$topic_name$message
When you get MQTT broker test message from demo topic you will get from Serial:
MSSG$demo$MQTT broker test\n
Error message with description:
ERR_$No connection with MQTT broker!\n
Example project could be found in the /example/ directory. Was tested on ESP32 Dev Module and with Arduino Serial Monitor.