sMQTTBroker
sMQTTBroker.h
1
4#ifndef SMQTTBROKER_FILE
5#define SMQTTBROKER_FILE
6
7#include"sMQTTplatform.h"
8#include"sMQTTClient.h"
9#include"sMQTTTopic.h"
10#include"sMQTTEvent.h"
11
13{
14public:
16 bool init(unsigned short port, bool checkWifiConnection=false);
18 void update();
25 void publish(const std::string &topic, const std::string &payload,unsigned char qos=0,bool retain=false);
27 void restart();
29 virtual bool onEvent(sMQTTEvent *event) = 0;
30
32 unsigned long getRetainedTopicCount();
34 std::string getRetaiedTopicName(unsigned long index);
35private:
36 // inner function
37 void publish(sMQTTClient *client, sMQTTTopic *topic, sMQTTMessage *msg);
38
39 bool subscribe(sMQTTClient *client, const char *topic);
40 void unsubscribe(sMQTTClient *client, const char *topic);
41
42 bool isTopicValidName(const char *filter);
43 void updateRetainedTopic(sMQTTTopic *topic);
44
45 bool isClientConnected(sMQTTClient *client);
46
47 void findRetainTopic(sMQTTTopic *topic, sMQTTClient *client);
48
49 TCPServer *_server;
50 sMQTTClientList clients;
51 sMQTTTopicList subscribes, retains;
52 bool isCheckWifiConnection;
53 friend class sMQTTClient;
54};
55
57{
58public:
59 bool onEvent(sMQTTEvent *event) { return true; }
60};
61#endif
Definition: sMQTTBroker.h:13
void publish(const std::string &topic, const std::string &payload, unsigned char qos=0, bool retain=false)
Definition: sMQTTBroker.cpp:233
void restart()
restart WIFI server
Definition: sMQTTBroker.cpp:273
std::string getRetaiedTopicName(unsigned long index)
receive topic name by index
Definition: sMQTTBroker.cpp:286
unsigned long getRetainedTopicCount()
receive retained topic count
Definition: sMQTTBroker.cpp:282
bool init(unsigned short port, bool checkWifiConnection=false)
Definition: sMQTTBroker.cpp:3
virtual bool onEvent(sMQTTEvent *event)=0
receive event from broker
void update()
Definition: sMQTTBroker.cpp:12
Definition: sMQTTBroker.h:57
bool onEvent(sMQTTEvent *event)
receive event from broker
Definition: sMQTTBroker.h:59
Main Client class.
Definition: sMQTTClient.h:22
Definition: sMQTTEvent.h:17
Definition: sMQTTMessage.h:40
Definition: sMQTTTopic.h:11