fang chen / Mbed 2 deprecated mDot_Connect_iotlab_demo2

Dependencies:   libmDot mbed mbed-rtos

Revision:
14:3ce2765dd92f
Parent:
13:c966b64b227f
Child:
15:4131b64ca8f9
--- a/main.cpp	Sat Aug 20 08:31:14 2016 +0000
+++ b/main.cpp	Tue Jan 29 01:20:20 2019 +0000
@@ -8,16 +8,21 @@
 const char TURNON[] = "turnon";
 const char TURNOFF[] = "turnoff";
 
-const char TURN_ON_ALARM[] = "TurnOnAlarm";
-const char TURN_OFF_ALARM[] = "TurnOffAlarm";
+const char TURN_ON_LIGHT[] = "TurnOnLight";
+const char TURN_OFF_LIGHT[] = "TurnOffLight";
 
 const char _header[] = "PH Alarm";
+//DigitalOut led1(LED1);
+//DigitalOut pin(D7);
+PwmOut pwm( LED1 );
+ 
+//PwmOut pwmLED(GPIO4); 
 
 // these options must match the settings on your Conduit
 // uncomment the following lines and edit their values to match your configuration
-static std::string config_network_name = "chinaiot";
-static std::string config_network_pass = "password";
-static uint8_t config_frequency_sub_band = 2; 
+static std::string config_network_name = "iotlab01";
+static std::string config_network_pass = "1145141919810";
+static uint8_t config_frequency_sub_band = 7; 
 
 bool strCmp(char* str1, const char* str2, int len)
 {
@@ -37,7 +42,14 @@
     std::vector<uint8_t> turnonData,turnoffData;
     char sendBuf[11],recvBuf[30];
     int  i;
-
+    //pwm.period(0.001f);
+    pwm.period_ms(1);
+    pwm = 0.5f;
+    for (int val = 0; val < 10; val +=1){
+        pwm = !pwm;
+        wait(1);
+        } 
+    //pwm.period_us(1000); 
     // get a mDot handle
     dot = mDot::getInstance();
 
@@ -133,29 +145,27 @@
              for( int i=0; i< recvData.size(); i++ )
                 recvBuf[i] = recvData[i];
              logInfo("%s", recvBuf);
-             if(strCmp(recvBuf, TURN_ON_ALARM, recvData.size()))logInfo("Turn on the alarm");
-             if(strCmp(recvBuf, TURN_OFF_ALARM, recvData.size()))logInfo("Turn off the alarm");
+             if(strCmp(recvBuf, TURN_ON_LIGHT, recvData.size())){
+                 logInfo("Turn on the alarm");
+                 std::vector<uint8_t> data;
+                 data.push_back('1');
+                 pwm = 0.0f;
+                 //led1 = 1;
+                 wait(0.10f);
+                 dot->send(data);
+             }
+             if(strCmp(recvBuf, TURN_OFF_LIGHT, recvData.size())){
+                 logInfo("Turn off the alarm");
+                std::vector<uint8_t> data;
+                 data.push_back('0');
+                 pwm = 1.0f;
+                 //led1 = 0;
+                 wait(0.10f);
+                 dot->send(data);
+             }
           } 
        } 
-       osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs()));
-       for(i=0;i<30;i++)recvBuf[i]=0;
-       if ((ret = dot->send(turnoffData)) != mDot::MDOT_OK) {
-          logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
-       } else {
-          logInfo("successfully sent data to gateway");
-          recvData.clear();
-          if ((ret = dot->recv(recvData)) != mDot::MDOT_OK) {
-             logError("failed to recv: [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
-          } else {
-             logInfo("datasize = %d", recvData.size());
-             for( int i=0; i< recvData.size(); i++ )
-                recvBuf[i] = recvData[i];
-             logInfo("%s", recvBuf);
-             if(strCmp(recvBuf, TURN_ON_ALARM, recvData.size()))logInfo("Turn on the alarm");
-             if(strCmp(recvBuf, TURN_OFF_ALARM, recvData.size()))logInfo("Turn off the alarm");
-          } 
-       } 
-        osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs()));
+      
     }
 
 }