データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリを使ったサンプルです。ESP8266版 https://mlkcca.com/

Dependencies:   Milkcocoa mbed

Dependents:   M2m

Committer:
jksoft
Date:
Mon Feb 29 09:19:56 2016 +0000
Revision:
4:d40cc9301d1e
Parent:
0:82d5445a9461
????????????????; Milkcocoa????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:82d5445a9461 1
jksoft 0:82d5445a9461 2 #if !defined(MQTTESP8266_H)
jksoft 0:82d5445a9461 3 #define MQTTESP8266_H
jksoft 0:82d5445a9461 4
jksoft 0:82d5445a9461 5 #include "MQTTmbed.h"
jksoft 0:82d5445a9461 6 #include "ESP8266Interface.h"
jksoft 0:82d5445a9461 7 #include "MQTTSocket.h"
jksoft 0:82d5445a9461 8
jksoft 0:82d5445a9461 9 // This struct is only used to workaround the order that the interfaces are initialized
jksoft 0:82d5445a9461 10 // MQTTSocket contains a TCPSocketConnection which needs the ESP8266Interface to be
jksoft 0:82d5445a9461 11 // instantiated first. Unfortunately the only way to instantiate a member before a superclass
jksoft 0:82d5445a9461 12 // is through another superclass.
jksoft 0:82d5445a9461 13 struct MQTTESP8266Holder {
jksoft 0:82d5445a9461 14 MQTTESP8266Holder(PinName tx, PinName rx, PinName reset, const char *ssid, const char *pass) :
jksoft 0:82d5445a9461 15 _wifi(tx, rx, reset, ssid, pass) {}
jksoft 0:82d5445a9461 16
jksoft 0:82d5445a9461 17 ESP8266Interface _wifi;
jksoft 0:82d5445a9461 18 };
jksoft 0:82d5445a9461 19
jksoft 0:82d5445a9461 20 // Straightforward implementation of a MQTT interface
jksoft 0:82d5445a9461 21 class MQTTESP8266 : public MQTTESP8266Holder, public MQTTSocket {
jksoft 0:82d5445a9461 22 private:
jksoft 0:82d5445a9461 23 MQTTESP8266Holder::_wifi;
jksoft 0:82d5445a9461 24 //ESP8266Interface _wifi;
jksoft 0:82d5445a9461 25
jksoft 0:82d5445a9461 26 public:
jksoft 0:82d5445a9461 27 MQTTESP8266(PinName tx, PinName rx, PinName reset, const char *ssid, const char *pass) :
jksoft 0:82d5445a9461 28 MQTTESP8266Holder(tx, rx, reset, ssid, pass) {
jksoft 0:82d5445a9461 29 _wifi.init();
jksoft 0:82d5445a9461 30 _wifi.connect();
jksoft 0:82d5445a9461 31 }
jksoft 0:82d5445a9461 32
jksoft 0:82d5445a9461 33 ESP8266Interface& getInterface() {
jksoft 0:82d5445a9461 34 return _wifi;
jksoft 0:82d5445a9461 35 }
jksoft 0:82d5445a9461 36
jksoft 0:82d5445a9461 37 void reconnect() {
jksoft 0:82d5445a9461 38 _wifi.disconnect();
jksoft 0:82d5445a9461 39 _wifi.connect();
jksoft 0:82d5445a9461 40 }
jksoft 0:82d5445a9461 41 };
jksoft 0:82d5445a9461 42
jksoft 0:82d5445a9461 43
jksoft 0:82d5445a9461 44 #endif