功能 : ESP8266物联车接口函数 作者 : 马晓健 邮箱 : jeasinema@gmail.com 声明 : 本程序仅供学习与交流使用,如需他用,须联系作者 本程序可以随意更改,但须保留本信息页 All rights reserved 2017.6.16
Dependents: Ex_esp8266 Example_for_learning_easy
esp8266.h@0:36956da27f53, 2018-09-07 (annotated)
- Committer:
- Dennis_Yu
- Date:
- Fri Sep 07 13:02:03 2018 +0000
- Revision:
- 0:36956da27f53
- Child:
- 1:08113511c9ab
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dennis_Yu | 0:36956da27f53 | 1 | #ifndef ESP8266_H |
Dennis_Yu | 0:36956da27f53 | 2 | #define ESP8266_H |
Dennis_Yu | 0:36956da27f53 | 3 | #include "mbed.h" |
Dennis_Yu | 0:36956da27f53 | 4 | |
Dennis_Yu | 0:36956da27f53 | 5 | class Esp8266 { //声明一个类 |
Dennis_Yu | 0:36956da27f53 | 6 | volatile bool network_start; |
Dennis_Yu | 0:36956da27f53 | 7 | volatile bool mqtt_start; |
Dennis_Yu | 0:36956da27f53 | 8 | volatile bool control_cmd; |
Dennis_Yu | 0:36956da27f53 | 9 | char esp_tokenBuf[32], esp_paramBuf[32]; // recv from esp8266 |
Dennis_Yu | 0:36956da27f53 | 10 | char control_buf[32]; |
Dennis_Yu | 0:36956da27f53 | 11 | bool esp_buf_ready; |
Dennis_Yu | 0:36956da27f53 | 12 | Serial ser2esp8266; |
Dennis_Yu | 0:36956da27f53 | 13 | |
Dennis_Yu | 0:36956da27f53 | 14 | protected: |
Dennis_Yu | 0:36956da27f53 | 15 | void esp8266_rxCallback(); |
Dennis_Yu | 0:36956da27f53 | 16 | void gotResponse(char *token, char *param); |
Dennis_Yu | 0:36956da27f53 | 17 | void buildCapability(char *out, const char* infoList[][2]); |
Dennis_Yu | 0:36956da27f53 | 18 | public: |
Dennis_Yu | 0:36956da27f53 | 19 | Esp8266(PinName TX, PinName RX, const char *wifi_ssid, const char *wifi_passwd); |
Dennis_Yu | 0:36956da27f53 | 20 | |
Dennis_Yu | 0:36956da27f53 | 21 | // 通用 |
Dennis_Yu | 0:36956da27f53 | 22 | bool reset(); |
Dennis_Yu | 0:36956da27f53 | 23 | |
Dennis_Yu | 0:36956da27f53 | 24 | // 连接模式 |
Dennis_Yu | 0:36956da27f53 | 25 | bool connect_wifi(const char *wifi_ssid, const char *wifi_passwd); |
Dennis_Yu | 0:36956da27f53 | 26 | bool weblogin(); |
Dennis_Yu | 0:36956da27f53 | 27 | bool connect_mqtt_broker(char *ip, const char *node_name, const char* sensors[][2], const char* actuator[][2]); |
Dennis_Yu | 0:36956da27f53 | 28 | bool is_connected(); |
Dennis_Yu | 0:36956da27f53 | 29 | |
Dennis_Yu | 0:36956da27f53 | 30 | bool publish_value(const char *topic, const char *data); |
Dennis_Yu | 0:36956da27f53 | 31 | bool subscribe_control(const char *topic, const char *data = NULL); |
Dennis_Yu | 0:36956da27f53 | 32 | bool is_control_available(void) { return control_cmd; } |
Dennis_Yu | 0:36956da27f53 | 33 | bool get_control_cmd(char* actuator, char* value); |
Dennis_Yu | 0:36956da27f53 | 34 | // 热点模式 |
Dennis_Yu | 0:36956da27f53 | 35 | }; |
Dennis_Yu | 0:36956da27f53 | 36 | #endif |