Giter Club home page Giter Club logo

mqttoverserial's Introduction

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.

mqttoverserial's People

Contributors

lnarolski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.