UWB-Tracking
Loading...
Searching...
No Matches
mqtt-client.h
Go to the documentation of this file.
1#pragma once
2
3#include <WiFi.h>
4#include <Wire.h>
5#include <PubSubClient.h>
6#include <Arduino.h>
7#include <vector>
8
16void subscribe_callback(char* topic, byte* payload, unsigned int length);
17
18namespace mqtt {
19
24public:
36 const char* topic,
37 const char* mqtt_server,
38 uint16_t mqtt_port,
39 const char* wifi_ssid,
40 const char* wifi_pwd,
41 String dev_id,
42 uint16_t buffer_size);
43
48 void update();
49
56 void publish(char* topic, char* msg, unsigned int plength);
57
62 bool is_connected();
63
68 String get_mac();
69
70private:
71 WiFiClient espClient;
72 PubSubClient client;
73 String dev_id;
74 const char* topic;
75
81 void reconnect();
82
89 void setup_wifi(const char wifi_ssid[], const char wifi_pwd[]);
90};
91
92} // namespace mqtt
A class for managing MQTT communication.
Definition: mqtt-client.h:23
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 ma...
Definition: mqtt-client.cpp:40
bool is_connected()
Checks if the MQTT client is connected.
Definition: mqtt-client.cpp:30
String get_mac()
Get the MAC address of the WiFi client.
Definition: mqtt-client.cpp:35
void reconnect()
Reconnects the MQTT client to the broker. It retries every 5 seconds until a connection is establishe...
Definition: mqtt-client.cpp:60
const char * topic
Definition: mqtt-client.h:74
PubSubClient client
Used to send MQTT commands.
Definition: mqtt-client.h:72
void publish(char *topic, char *msg, unsigned int plength)
Publishes a message on the specified MQTT topic.
Definition: mqtt-client.cpp:79
WiFiClient espClient
Used to establish the WiFi connection.
Definition: mqtt-client.h:71
void update()
Must be called frequently to allow the callback function to handle incoming messages....
Definition: mqtt-client.cpp:54
String dev_id
Definition: mqtt-client.h:73
void subscribe_callback(char *topic, byte *payload, unsigned int length)
Callback function for MQTT subscriptions, called when a message arrives. simply prints the message to...
Definition: mqtt-client.cpp:5
Definition: mqtt-client.h:18