功能 : ESP8266物联车接口函数 作者 : 马晓健 邮箱 : jeasinema@gmail.com 声明 : 本程序仅供学习与交流使用,如需他用,须联系作者 本程序可以随意更改,但须保留本信息页 All rights reserved 2017.6.16

Dependents:   Ex_esp8266 Example_for_learning_easy

Revision:
1:08113511c9ab
Parent:
0:36956da27f53
diff -r 36956da27f53 -r 08113511c9ab esp8266.cpp
--- a/esp8266.cpp	Fri Sep 07 13:02:03 2018 +0000
+++ b/esp8266.cpp	Fri Sep 14 07:54:35 2018 +0000
@@ -8,7 +8,6 @@
 All rights reserved
 2017.6.16
 ***************************************************************/
-
 #include "esp8266.h"
 
 #include <cstdarg>
@@ -21,16 +20,19 @@
 static int ser_baud = 9600;
 
 //定义了一个调试的宏,C语言语法
-#define ESP_CMD(format, ...) do{\
-    char cmdbuf[128], *p;\
-    ser2esp8266.printf("\r"); \
-    sprintf(cmdbuf, format "\r", ##__VA_ARGS__);\
-    for(p=cmdbuf;*p;p++){\
-        ser2esp8266.putc(*p);\
-        wait(0.02);\
-    }\
-    wait(0.3);\
-}while(0)
+#define ESP_CMD(format, ...)                         \
+    do                                               \
+    {                                                \
+        char cmdbuf[128], *p;                        \
+        ser2esp8266.printf("\r");                    \
+        sprintf(cmdbuf, format "\r", ##__VA_ARGS__); \
+        for (p = cmdbuf; *p; p++)                    \
+        {                                            \
+            ser2esp8266.putc(*p);                    \
+            wait(0.02);                              \
+        }                                            \
+        wait(0.3);                                   \
+    } while (0)
 
 
 
@@ -125,13 +127,16 @@
 {
     // serial to esp8266 init
     ser2esp8266.baud(ser_baud);
-    ser2esp8266.attach(callback(this,&Esp8266::esp8266_rxCallback), Serial::RxIrq);    
+    ser2usb.printf("connecting to wifi\r\n");
+    ser2esp8266.attach(callback(this, &Esp8266::esp8266_rxCallback), Serial::RxIrq);    
     //if (mode == 0) {                                                            // client mode 
         this->reset();
         this->connect_wifi(wifi_ssid, wifi_passwd);
         while(!is_connected()){
+            ser2usb.printf("connecting...\r\n");
             wait(0.5);
         }
+        ser2usb.printf("connected\r\n");
         this->weblogin();
     //} else {
     //    
@@ -177,7 +182,8 @@
     }
 }
 
-bool Esp8266::connect_mqtt_broker(char *ip, const char *node_name, const char* sensors[][2], const char* actuator[][2]) {  //定义类的函数
+bool Esp8266::connect_mqtt_broker(const char *ip, const char *node_name, const char* sensors[][2], const char* actuator[][2]) 
+{  //定义类的函数
 
     ESP_CMD("node_name = '%s'", node_name);
     ESP_CMD("m = mqtt.Client('i_' .. node.chipid(), 120)");