Skip to content

2020: Simple library for Arduino (tested on ESP32) for communication with MQTT broker over Serial (tested with UART)

License

Notifications You must be signed in to change notification settings

lnarolski/MQTToverSerial

Repository files navigation

MQTToverSerial

Simple library based on PubSubClient (with all limitations) for Arduino (tested on ESP32) to communicate with MQTT broker over HardwareSerial connection (tested with UART)

Table of contents

General info

Library allows you to make Serial (e.g. UART) <--> MQTT Broker connections with commands sended via UART.

Public methods

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.

bool SubscribeTopic(const char* topic)

Method to subscribe topic. Returns true on success.

bool UnsubscribeTopic(const char* topic)

Method to unsubscribe topic. Returns true on success.

bool Publish(const char* topic, const char* message)

Method to publish message in specified topic. Returns true on success.

bool Loop()

Method to call in loop to maintain connection to the server. Returns true on success.

void SetSpecialCharacter(char _specialCharacter)

Set character as new commands delimiter.

char GetSpecialCharacter()

Get actual delimiter.

void ReadSerial()

Analyse serial buffer to find sended commands.

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).

SUBS

Subscribe topic: SUBS$topic_name

To subscribe demo topic send via Serial:

SUBS$demo\n

UNSB

Unsubscribe topic: UNSB$topic_name

To unsubscribe demo topic send via Serial:

UNSB$demo\n

SEND

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

MSSG

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

ERR_

Error message with description:

ERR_$No connection with MQTT broker!\n

Example

Example project could be found in the /example/ directory. Was tested on ESP32 Dev Module and with Arduino Serial Monitor.

About

2020: Simple library for Arduino (tested on ESP32) for communication with MQTT broker over Serial (tested with UART)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages