Keegan Hu
/
仓库
init
Fork of iot_example by
esp8266.h@3:06080fa094a0, 2017-11-13 (annotated)
- Committer:
- zyx
- Date:
- Mon Nov 13 20:25:48 2017 +0800
- Revision:
- 3:06080fa094a0
- Parent:
- 2:b10925c474fc
- Child:
- 8:d5e340a59c71
complete demo for IoT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brainliang | 0:63af4719467f | 1 | |
zhangyx | 1:3b487c4813a2 | 2 | #include "mbed.h" |
brainliang | 0:63af4719467f | 3 | |
brainliang | 0:63af4719467f | 4 | class Esp8266 { //声明一个类 |
zhangyx | 2:b10925c474fc | 5 | volatile bool network_start; |
zhangyx | 2:b10925c474fc | 6 | volatile bool mqtt_start; |
zyx | 3:06080fa094a0 | 7 | volatile bool control_cmd; |
zhangyx | 2:b10925c474fc | 8 | char esp_tokenBuf[32], esp_paramBuf[32]; // recv from esp8266 |
zyx | 3:06080fa094a0 | 9 | char control_buf[32]; |
zhangyx | 1:3b487c4813a2 | 10 | bool esp_buf_ready; |
zhangyx | 1:3b487c4813a2 | 11 | Serial ser2esp8266; |
zhangyx | 1:3b487c4813a2 | 12 | |
zhangyx | 1:3b487c4813a2 | 13 | protected: |
zhangyx | 1:3b487c4813a2 | 14 | void esp8266_rxCallback(); |
zhangyx | 2:b10925c474fc | 15 | void gotResponse(char *token, char *param); |
zyx | 3:06080fa094a0 | 16 | void buildCapability(char *out, const char* infoList[][2]); |
brainliang | 0:63af4719467f | 17 | public: |
zhangyx | 1:3b487c4813a2 | 18 | Esp8266(PinName TX, PinName RX, const char *wifi_ssid, const char *wifi_passwd); |
brainliang | 0:63af4719467f | 19 | |
brainliang | 0:63af4719467f | 20 | // 通用 |
brainliang | 0:63af4719467f | 21 | bool reset(); |
brainliang | 0:63af4719467f | 22 | |
brainliang | 0:63af4719467f | 23 | // 连接模式 |
zhangyx | 1:3b487c4813a2 | 24 | bool connect_wifi(const char *wifi_ssid, const char *wifi_passwd); |
brainliang | 0:63af4719467f | 25 | bool weblogin(); |
zyx | 3:06080fa094a0 | 26 | bool connect_mqtt_broker(char *ip, const char* sensors[][2], const char* actuator[][2]); |
zhangyx | 2:b10925c474fc | 27 | bool is_connected(); |
brainliang | 0:63af4719467f | 28 | |
zyx | 3:06080fa094a0 | 29 | bool publish_value(const char *topic, const char *data); |
zyx | 3:06080fa094a0 | 30 | bool subscribe_control(const char *topic, const char *data = NULL); |
zyx | 3:06080fa094a0 | 31 | bool is_control_available(void) { return control_cmd; } |
zyx | 3:06080fa094a0 | 32 | bool get_control_cmd(char* actuator, char* value); |
brainliang | 0:63af4719467f | 33 | // 热点模式 |
brainliang | 0:63af4719467f | 34 | }; |