Kuo Yiching

Dependencies:   mbed

Fork of iot_example by YX ZHANG

Revision:
8:cd472721e8a8
Parent:
7:49a823b5a935
--- a/main.cpp	Wed Dec 13 10:09:44 2017 +0000
+++ b/main.cpp	Wed Dec 20 08:46:09 2017 +0000
@@ -11,8 +11,14 @@
 #include "esp8266.h"
 
 Serial ser2usb(PA_2, PA_3, 115200);
-DigitalOut LED(PD_2);
-DigitalIn humansensor(PA_0); 
+//DigitalOut LED(PD_2);
+//DigitalIn humansensor(PA_0); 
+PwmOut mypwm19(PB_4);
+PwmOut mypwm20(PB_5);
+PwmOut mypwm21(PB_13);
+PwmOut mypwm22(PB_3);
+//DigitalIn mybutton(PA_12);
+DigitalOut myled(PB_14);
 
 int test_main(void){
     Serial esp8266(PA_9, PA_10, 9600);
@@ -25,9 +31,11 @@
 }
 
 int main(void) {
-    
+      myled = 0;
+
     // 选定与 esp8266 相连接的串口,WiFi 名称和密码
     // 参数分别为 TX pin / RX pin / SSID / Password
+    ser2usb.printf("Reset.\r\n");
     Esp8266 client(PA_9, PA_10, "TSINGHUA.iCenter", "TS.icenter");
 
     //声明所有的传感器,每行一个,每个由名字、单位两部分组成,最后一行必须为空指针作为结尾
@@ -43,8 +51,12 @@
     //声明所有的执行器,每行一个,每个由名字、参数类型两部分组成,最后一行必须为空指针作为结尾
     //服务器收到声明后,将在网页上显示这些执行器
     const char* actuators[][2] = {
-        "servo1", "int",
-        "switch2", "int",
+        "servo19", "int",
+        "servo20", "int",
+        "servo21", "int",
+        "servo22", "int",
+        "LED01", "int",
+        //"switch2", "int",
         NULL, NULL //最后一行以空指针作为结束标记
     };
 
@@ -63,15 +75,47 @@
         if(client.get_control_cmd(actuator_name, control_value)){
             ser2usb.printf("Received CMD %s, %s\r\n", actuator_name, control_value);
             //判断哪个执行器收到命令
-            if(strcmp(actuator_name, "switch1")){
-                //do something for switch1
-                LED = atoi(control_value);
-            }else if(strcmp(actuator_name, "switch2")){
+            if (!strcmp(actuator_name, "servo19")){
+                //LED = atoi(control_value);
+                if (!strcmp(control_value, "1")){
+                    mypwm19.pulsewidth(0.001);
+                }else{
+                    mypwm19.pulsewidth(0.002);
+                }
+                    
+            }else if (!strcmp(actuator_name, "servo20")){
+                if (!strcmp(control_value, "1")){
+                    mypwm20.pulsewidth(0.001);
+                }else{
+                    mypwm20.pulsewidth(0.002);
+                }
+            }else if (!strcmp(actuator_name, "servo21")){
+                if (!strcmp(control_value, "1")){
+                    mypwm21.pulsewidth(0.001);
+                }else{
+                    mypwm21.pulsewidth(0.002);
+                }
+                    
+            }else if (!strcmp(actuator_name, "servo22")){
+                if (!strcmp(control_value, "1")){
+                    mypwm22.pulsewidth(0.001);
+                }else{
+                    mypwm22.pulsewidth(0.002);
+                }
                 //do something for switch2
+            }else if (!strcmp(actuator_name, "LED01")){
+                if (!strcmp(control_value, "1")){
+                    myled = 1;
+                }else{
+                    myled = 0;
+                }
             }
+        }else{
+            //ser2usb.printf("Not Received CMD\r\n");
+
         }
 
-        if(t.read() - last_report > 1){ // 每1s发送汇报一次传感器数据
+        /*if(t.read() - last_report > 1){ // 每1s发送汇报一次传感器数据
 
             //汇报传感器数据,两个参数分别是传感器名字和值
             //client.publish_value("pressure", "100000 Pa");
@@ -80,6 +124,6 @@
             client.publish_value("huamn", "30 %");
             
             last_report = t.read();
-        }
+        }*/
     }
 }