LoboMQ
|
#include "LoboMQ/PubSub.h"
Go to the source code of this file.
Functions | |
bool | configureESPNOW (uint8_t *mac) |
int | fixTopicAndCheckLength (char *topic) |
bool | isASCII (char c) |
int | pubTopicCheck (char *topic) |
int | subTopicCheck (char *topic) |
LMQErrType | publish (uint8_t *mac, char *topic, void *payload, size_t payloadSize, Elog *_logger) |
Publishes a message to the broker. | |
LMQErrType | subscribe (uint8_t *mac, char *topic, Elog *_logger) |
Subscribes to a topic on the broker. | |
LMQErrType | unsubscribe (uint8_t *mac, char *topic, Elog *_logger) |
Unsubscribes from a topic on the broker. | |
bool | isLMQMessage (const uint8_t *incomingData) |
Checks if the data received is a MQ message. | |
PayloadContent | getLMQPayload (const uint8_t *incomingData) |
Gets the payload content inside a published message This function extracts the payload from the bytes of a received publication message. | |
Variables | |
Elog * | logger |
This file contains the necessary logic to publish, subscribe and unsubscribe as a LoboMQ client.
Definition in file PubSub.cpp.
bool configureESPNOW | ( | uint8_t * | mac | ) |
Definition at line 13 of file PubSub.cpp.
int fixTopicAndCheckLength | ( | char * | topic | ) |
Definition at line 41 of file PubSub.cpp.
PayloadContent getLMQPayload | ( | const uint8_t * | incomingData | ) |
Gets the payload content inside a published message This function extracts the payload from the bytes of a received publication message.
incomingData | The data received. |
Definition at line 191 of file PubSub.cpp.
bool isASCII | ( | char | c | ) |
Definition at line 66 of file PubSub.cpp.
bool isLMQMessage | ( | const uint8_t * | incomingData | ) |
Checks if the data received is a MQ message.
This function checks if the received bytes represent a MQ message from this library.
incomingData | The data received. |
`true` | if the data is a MQ message. |
`false` | otherwise. |
Definition at line 186 of file PubSub.cpp.
LMQErrType publish | ( | uint8_t * | mac, |
char * | topic, | ||
void * | payload, | ||
size_t | payloadSize, | ||
Elog * | _logger = disableLogger() ) |
Publishes a message to the broker.
This function takes the payload and builds a message that will be published to the specified topic on the broker.
mac | The broker MAC address. |
topic | The topic to publish the message to. It can't contain wildcard characters (+ , # ) nor non-UTF-8 characters. Invalid example: +/café . Valid example: kitchen/coffee . |
payload | Pointer to the message payload. |
payloadSize | Size of the message payload. |
_logger | Pointer to the logger object. |
`LMQ_ERR_SUCCESS` | if the message is successfully published. |
`LMQ_ERR_BAD_ESP_CONFIG` | if ESP-NOW couldn't be initialized. |
`LMQ_ERR_INVAL_TOPIC` | if the given topic is invalid. |
`LMQ_ERR_ESP_SEND_FAIL` | if the message couldn't be sent. |
Definition at line 105 of file PubSub.cpp.
int pubTopicCheck | ( | char * | topic | ) |
Definition at line 70 of file PubSub.cpp.
LMQErrType subscribe | ( | uint8_t * | mac, |
char * | topic, | ||
Elog * | _logger = disableLogger() ) |
Subscribes to a topic on the broker.
This function sends a message to the broker announcing that the calling board is interested in receiving all the messages compatible with the specified topic.
mac | The broker MAC address. |
topic | The topic the board subscribes to. Is compatible with wildcard characters (+ , # ) when used properly, and can't contain non-UTF-8 characters. Invalid example: résumé/+/#/garden . Valid example: +/+/out/# . |
_logger | Pointer to the logger object. |
`LMQ_ERR_SUCCESS` | if the message is successfully published. |
`LMQ_ERR_BAD_ESP_CONFIG` | if ESP-NOW couldn't be initialized. |
`LMQ_ERR_INVAL_TOPIC` | if the given topic is invalid. |
`LMQ_ERR_ESP_SEND_FAIL` | if the message couldn't be sent. |
Definition at line 133 of file PubSub.cpp.
int subTopicCheck | ( | char * | topic | ) |
Definition at line 81 of file PubSub.cpp.
LMQErrType unsubscribe | ( | uint8_t * | mac, |
char * | topic, | ||
Elog * | _logger = disableLogger() ) |
Unsubscribes from a topic on the broker.
This function sends a message to the broker announcing that the calling board is no longer interested in receiving all the messages compatible with the specified topic.
mac | The broker MAC address. |
topic | The MQ topic the board unsubscribes from. Is compatible with wildcard characters (+ , # ) when used properly, and can't contain non-UTF-8 characters. Invalid example: résumé/+/#/garden . Valid example: +/+/out/# . |
_logger | Pointer to the logger object. |
`LMQ_ERR_SUCCESS` | if the message is successfully published. |
`LMQ_ERR_BAD_ESP_CONFIG` | if ESP-NOW couldn't be initialized. |
`LMQ_ERR_INVAL_TOPIC` | if the given topic is invalid. |
`LMQ_ERR_ESP_SEND_FAIL` | if the message couldn't be sent. |
Definition at line 159 of file PubSub.cpp.
Elog* logger |
Definition at line 11 of file PubSub.cpp.