A class for managing MQTT communication.
More...
#include <mqtt-client.h>
|
| MqttClient (const char *topic, const char *mqtt_server, uint16_t mqtt_port, const char *wifi_ssid, const char *wifi_pwd, String dev_id, uint16_t buffer_size) |
| Default constructor for the MQTT client. More...
|
|
void | update () |
| Must be called frequently to allow the callback function to handle incoming messages. Handles reconnection and MQTT event processing. More...
|
|
void | publish (char *topic, char *msg, unsigned int plength) |
| Publishes a message on the specified MQTT topic. More...
|
|
bool | is_connected () |
| Checks if the MQTT client is connected. More...
|
|
String | get_mac () |
| Get the MAC address of the WiFi client. More...
|
|
|
void | reconnect () |
| Reconnects the MQTT client to the broker. It retries every 5 seconds until a connection is established. More...
|
|
void | setup_wifi (const char wifi_ssid[], const char wifi_pwd[]) |
| Connects the ESP to the WiFi network using provided credentials. WiFi settings can be found in the main.cpp file. More...
|
|
A class for managing MQTT communication.
◆ MqttClient()
MqttClient |
( |
const char * |
topic, |
|
|
const char * |
mqtt_server, |
|
|
uint16_t |
mqtt_port, |
|
|
const char * |
wifi_ssid, |
|
|
const char * |
wifi_pwd, |
|
|
String |
dev_id, |
|
|
uint16_t |
buffer_size |
|
) |
| |
Default constructor for the MQTT client.
- Parameters
-
topic | The MQTT topic for communication. |
mqtt_server | The MQTT server hostname or IP address. |
mqtt_port | The MQTT server port number. |
wifi_ssid | The WiFi SSID for network connection. |
wifi_pwd | The WiFi password for network connection. |
dev_id | The PCB's MQTT Devicename. |
buffer_size | The outputbuffer used for incoming and outgoing messages. |
◆ get_mac()
Get the MAC address of the WiFi client.
- Returns
- The MAC address as a String.
◆ is_connected()
Checks if the MQTT client is connected.
- Returns
- true if connected, false otherwise.
◆ publish()
void publish |
( |
char * |
topic, |
|
|
char * |
msg, |
|
|
unsigned int |
plength |
|
) |
| |
Publishes a message on the specified MQTT topic.
- Parameters
-
topic | The MQTT topic to publish to. |
msg | The message to publish. |
plength | Length of the message to publish. |
◆ reconnect()
Reconnects the MQTT client to the broker. It retries every 5 seconds until a connection is established.
- Warning
- Contains a while loop to wait for a connection, which may cause delays.
◆ setup_wifi()
void setup_wifi |
( |
const char |
wifi_ssid[], |
|
|
const char |
wifi_pwd[] |
|
) |
| |
|
private |
Connects the ESP to the WiFi network using provided credentials. WiFi settings can be found in the main.cpp file.
- Parameters
-
wifi_ssid | The WiFi SSID. |
wifi_pwd | The WiFi password. |
◆ update()
Must be called frequently to allow the callback function to handle incoming messages. Handles reconnection and MQTT event processing.
◆ client
Used to send MQTT commands.
◆ dev_id
◆ espClient
Used to establish the WiFi connection.
◆ topic
The documentation for this class was generated from the following files: