IoT demo

Dependencies:   mbed

Fork of my_example_esp8266 by liang brain

Files at this revision

API Documentation at this revision

Comitter:
zhangyx
Date:
Wed Dec 13 10:09:44 2017 +0000
Parent:
6:629e300b6c3b
Child:
8:d5e340a59c71
Commit message:
fix control command

Changed in this revision

esp8266.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/esp8266.cpp	Thu Dec 07 11:55:39 2017 +0000
+++ b/esp8266.cpp	Wed Dec 13 10:09:44 2017 +0000
@@ -197,7 +197,7 @@
     ESP_CMD("m:on(\"message\", function(conn, topic, data)");
     ESP_CMD("if topic:find(\"^/control/\") then");
     ESP_CMD("local tok = topic:match(\"^/control/.+/(.+)\")");
-    ESP_CMD("if tok then print(\"\\035\"..tok..\"+\"..data) end");
+    ESP_CMD("if tok then print(\"\\035control+\"..tok..\"+\"..data) end");
     ESP_CMD("end");
     ESP_CMD("end)");
 
--- a/main.cpp	Thu Dec 07 11:55:39 2017 +0000
+++ b/main.cpp	Wed Dec 13 10:09:44 2017 +0000
@@ -10,20 +10,33 @@
 #include "mbed.h"
 #include "esp8266.h"
 
-Serial ser2usb(PA_9, PA_10, 115200);
+Serial ser2usb(PA_2, PA_3, 115200);
 DigitalOut LED(PD_2);
+DigitalIn humansensor(PA_0); 
+
+int test_main(void){
+    Serial esp8266(PA_9, PA_10, 9600);
+    while(1){
+        if(ser2usb.readable())
+            esp8266.putc(ser2usb.getc());
+        if(esp8266.readable())
+            ser2usb.putc(esp8266.getc());
+    }
+}
 
 int main(void) {
+    
     // 选定与 esp8266 相连接的串口,WiFi 名称和密码
     // 参数分别为 TX pin / RX pin / SSID / Password
-    Esp8266 client(PA_2, PA_3, "TSINGHUA.iCenter", "TS.icenter");
+    Esp8266 client(PA_9, PA_10, "TSINGHUA.iCenter", "TS.icenter");
 
     //声明所有的传感器,每行一个,每个由名字、单位两部分组成,最后一行必须为空指针作为结尾
     //服务器收到声明后,将在网页上显示这些传感器
     const char* sensors[][2] = {
-        "pressure", "Pa",
-        "temperature", "C",
-        "humidity", "%",
+        //"pressure", "Pa",
+//        "temperature", "C",
+//        "humidity", "%",
+        "huamn","person",
         NULL, NULL //最后一行以空指针作为结束标记
     };
 
@@ -61,9 +74,10 @@
         if(t.read() - last_report > 1){ // 每1s发送汇报一次传感器数据
 
             //汇报传感器数据,两个参数分别是传感器名字和值
-            client.publish_value("pressure", "100000 Pa");
-            client.publish_value("temperature", "20 C");
-            client.publish_value("humidity", "30 %");
+            //client.publish_value("pressure", "100000 Pa");
+//            client.publish_value("temperature", "20 C");
+//            client.publish_value("humidity", "30 %");
+            client.publish_value("huamn", "30 %");
             
             last_report = t.read();
         }