IoT demo

Dependencies:   mbed

Fork of my_example_esp8266 by liang brain

esp8266.h

Committer:
zhangyx
Date:
2017-11-07
Revision:
1:3b487c4813a2
Parent:
0:63af4719467f
Child:
2:b10925c474fc

File content as of revision 1:3b487c4813a2:


#include "mbed.h"

class Esp8266 {                                                                 //声明一个类
    bool network_start;
    bool mqtt_start;
    char esp_token[1024], esp_param[2048];
    char esp_tokenBuf[1024], esp_paramBuf[2048];   // recv from esp8266
    bool esp_buf_ready;
    Serial ser2esp8266;
    
protected:
    void esp8266_rxCallback();
public:
    Esp8266(PinName TX, PinName RX, const char *wifi_ssid, const char *wifi_passwd);
    
    // 通用
    bool reset();
    
    // 连接模式
    bool connect_wifi(const char *wifi_ssid, const char *wifi_passwd);
    bool weblogin();
    bool connect_mqtt_broker(char *ip);
    
    bool publish(char *topic, char *data, int size = -1);
    bool subscribe_poll(char *topic, char *data, int size = -1);
    // 热点模式
};