Dependents: mqtt_Autofaehrschiff MQTT_Nucleo_dht11 mqtt_Testprogramm_FritzBox mqtt_TestprogrammWorkshop ... more
PubSubClient.h@2:08ce999855c3, 2021-07-09 (annotated)
- Committer:
- jack1930
- Date:
- Fri Jul 09 12:34:25 2021 +0000
- Revision:
- 2:08ce999855c3
- Parent:
- 0:a655fd59ed71
- Child:
- 3:d8582413a5a1
subscribe mit loop
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jack1930 | 0:a655fd59ed71 | 1 | #include "mbed.h" |
jack1930 | 0:a655fd59ed71 | 2 | #include "ESP8266Interface.h" |
jack1930 | 2:08ce999855c3 | 3 | #include "string" |
jack1930 | 0:a655fd59ed71 | 4 | |
jack1930 | 0:a655fd59ed71 | 5 | // Library to use https://github.com/ARMmbed/mbed-mqtt |
jack1930 | 0:a655fd59ed71 | 6 | #include <MQTTClientMbedOs.h> |
jack1930 | 2:08ce999855c3 | 7 | using namespace MQTT; |
jack1930 | 0:a655fd59ed71 | 8 | |
jack1930 | 0:a655fd59ed71 | 9 | class PubSubClient |
jack1930 | 0:a655fd59ed71 | 10 | { |
jack1930 | 0:a655fd59ed71 | 11 | private: |
jack1930 | 0:a655fd59ed71 | 12 | ESP8266Interface *esp; |
jack1930 | 0:a655fd59ed71 | 13 | SocketAddress deviceIP; |
jack1930 | 0:a655fd59ed71 | 14 | SocketAddress MQTTBroker; |
jack1930 | 0:a655fd59ed71 | 15 | TCPSocket *socket; |
jack1930 | 2:08ce999855c3 | 16 | static MQTTClient *client; |
jack1930 | 0:a655fd59ed71 | 17 | MQTT::Message msg; |
jack1930 | 0:a655fd59ed71 | 18 | |
jack1930 | 2:08ce999855c3 | 19 | //Subscriptions |
jack1930 | 2:08ce999855c3 | 20 | static int hs_count; |
jack1930 | 2:08ce999855c3 | 21 | static char hs[10][40]; //Topics |
jack1930 | 2:08ce999855c3 | 22 | static Callback< void(string)> cbs[10]; //Callbacks |
jack1930 | 2:08ce999855c3 | 23 | static int topicNr; |
jack1930 | 2:08ce999855c3 | 24 | |
jack1930 | 0:a655fd59ed71 | 25 | public: |
jack1930 | 0:a655fd59ed71 | 26 | void init(); |
jack1930 | 0:a655fd59ed71 | 27 | PubSubClient(Callback< void()> func); |
jack1930 | 0:a655fd59ed71 | 28 | PubSubClient(); |
jack1930 | 0:a655fd59ed71 | 29 | bool connect(char* clientName); |
jack1930 | 0:a655fd59ed71 | 30 | int publish(const char* topic, const char* buf); |
jack1930 | 2:08ce999855c3 | 31 | static int subscribe(const char* topicFilter, MQTT::QoS qos, MQTTClient::messageHandler mh); |
jack1930 | 2:08ce999855c3 | 32 | int subscribe(const char* topic,Callback< void(string)> func); |
jack1930 | 2:08ce999855c3 | 33 | static void subscribeCallback(MessageData& mymessage); |
jack1930 | 2:08ce999855c3 | 34 | static void loop(); |
jack1930 | 0:a655fd59ed71 | 35 | }; |