MQTT Client for mbed LPC1768 and Application Board over Ethernet; publish only.
Dependencies: C12832 MMA7660 MQTT
Fork of HelloMQTT by
Machine-to-Machine-Communication
Das Message Queue Telemetry Transport (MQTT) Protokoll ist ein effizientes Internet of Things (IoT) Protokoll mit wenig Protokolloverhead. Es wurde als lightweight publish/subscribe messaging transport entworfen. Es ist sinnvoll für Verbindungen mit Remote-Standorten, wo nur wenig Resourcen benötigt werden bzw. geringe Bandbreite zur Verfügung steht. Neben MQTT gibt es weitere IoT-Protokoll, wie HTTP, CoAP, XMPP, ... (Überischt über IoT Protokolle). Eine Beschreibung des MQTT ist z.B. hier zu finden.
MQTT implementiert das Publish/Subscribe-Pattern, daher wird ein Brocker für die Vermittlung der Nachrichten (topics) benötigt. Neben vielen quelloffenen Implementierungen (z. B. mosquitto) gibt es auch kommerzielle bzw. freie Server (Broker), die unterschiedliche Features bereit stellen (z. B. den in Deutschland entwickelten HiveMQ).
Für die Programmierung der Clients bzw. Ebedded Systems stehen ebenso sehr viele Libaries in verschiedenen Programmiersprachen zur Verfügung.
Weitere Kommunikationsmöglichkeiten
MQTTESP8266.h@21:4b8d80bf664f, 2017-05-04 (annotated)
- Committer:
- fpucher
- Date:
- Thu May 04 10:07:14 2017 +0000
- Revision:
- 21:4b8d80bf664f
MQTT Client for mbed LPC1768 and Application Board over Ethernet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fpucher | 21:4b8d80bf664f | 1 | |
fpucher | 21:4b8d80bf664f | 2 | #if !defined(MQTTESP8266_H) |
fpucher | 21:4b8d80bf664f | 3 | #define MQTTESP8266_H |
fpucher | 21:4b8d80bf664f | 4 | |
fpucher | 21:4b8d80bf664f | 5 | #include "MQTTmbed.h" |
fpucher | 21:4b8d80bf664f | 6 | #include "ESP8266Interface.h" |
fpucher | 21:4b8d80bf664f | 7 | #include "MQTTSocket.h" |
fpucher | 21:4b8d80bf664f | 8 | |
fpucher | 21:4b8d80bf664f | 9 | // This struct is only used to workaround the order that the interfaces are initialized |
fpucher | 21:4b8d80bf664f | 10 | // MQTTSocket contains a TCPSocketConnection which needs the ESP8266Interface to be |
fpucher | 21:4b8d80bf664f | 11 | // instantiated first. Unfortunately the only way to instantiate a member before a superclass |
fpucher | 21:4b8d80bf664f | 12 | // is through another superclass. |
fpucher | 21:4b8d80bf664f | 13 | struct MQTTESP8266Holder { |
fpucher | 21:4b8d80bf664f | 14 | MQTTESP8266Holder(PinName tx, PinName rx, PinName reset, const char *ssid, const char *pass) : |
fpucher | 21:4b8d80bf664f | 15 | _wifi(tx, rx, reset, ssid, pass) {} |
fpucher | 21:4b8d80bf664f | 16 | |
fpucher | 21:4b8d80bf664f | 17 | ESP8266Interface _wifi; |
fpucher | 21:4b8d80bf664f | 18 | }; |
fpucher | 21:4b8d80bf664f | 19 | |
fpucher | 21:4b8d80bf664f | 20 | // Straightforward implementation of a MQTT interface |
fpucher | 21:4b8d80bf664f | 21 | class MQTTESP8266 : public MQTTESP8266Holder, public MQTTSocket { |
fpucher | 21:4b8d80bf664f | 22 | private: |
fpucher | 21:4b8d80bf664f | 23 | MQTTESP8266Holder::_wifi; |
fpucher | 21:4b8d80bf664f | 24 | //ESP8266Interface _wifi; |
fpucher | 21:4b8d80bf664f | 25 | |
fpucher | 21:4b8d80bf664f | 26 | public: |
fpucher | 21:4b8d80bf664f | 27 | MQTTESP8266(PinName tx, PinName rx, PinName reset, const char *ssid, const char *pass) : |
fpucher | 21:4b8d80bf664f | 28 | MQTTESP8266Holder(tx, rx, reset, ssid, pass) { |
fpucher | 21:4b8d80bf664f | 29 | _wifi.init(); |
fpucher | 21:4b8d80bf664f | 30 | _wifi.connect(); |
fpucher | 21:4b8d80bf664f | 31 | } |
fpucher | 21:4b8d80bf664f | 32 | |
fpucher | 21:4b8d80bf664f | 33 | ESP8266Interface& getInterface() { |
fpucher | 21:4b8d80bf664f | 34 | return _wifi; |
fpucher | 21:4b8d80bf664f | 35 | } |
fpucher | 21:4b8d80bf664f | 36 | |
fpucher | 21:4b8d80bf664f | 37 | void reconnect() { |
fpucher | 21:4b8d80bf664f | 38 | _wifi.disconnect(); |
fpucher | 21:4b8d80bf664f | 39 | _wifi.connect(); |
fpucher | 21:4b8d80bf664f | 40 | } |
fpucher | 21:4b8d80bf664f | 41 | }; |
fpucher | 21:4b8d80bf664f | 42 | |
fpucher | 21:4b8d80bf664f | 43 | |
fpucher | 21:4b8d80bf664f | 44 | #endif |