IoT demo

Dependencies:   mbed

Fork of my_example_esp8266 by liang brain

esp8266.h

Committer:
zhangyx
Date:
2017-11-07
Revision:
2:b10925c474fc
Parent:
1:3b487c4813a2
Child:
3:06080fa094a0

File content as of revision 2:b10925c474fc:


#include "mbed.h"

class Esp8266 {                                                                 //声明一个类
    volatile bool network_start;
    volatile bool mqtt_start;
//    char esp_token[1024], esp_param[2048];
    char esp_tokenBuf[32], esp_paramBuf[32];   // recv from esp8266
    bool esp_buf_ready;
    Serial ser2esp8266;
    
protected:
    void esp8266_rxCallback();
    void gotResponse(char *token, char *param);
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 is_connected();
    
    bool publish(char *topic, char *data, int size = -1);
    bool subscribe_poll(char *topic, char *data, int size = -1);
    // 热点模式
};