Cayenne demo

Dependencies:   Cayenne-MQTT-mbed NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed Servo

Fork of Cayenne-X-NUCLEO-IDW01M1-TMP36 by myDevicesIoT

Files at this revision

API Documentation at this revision

Comitter:
rozendhyan
Date:
Tue Aug 29 17:05:03 2017 +0000
Parent:
7:fed254c30643
Child:
9:668337c0fb8a
Commit message:
add Tigger servo

Changed in this revision

Servo.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Tue Aug 29 17:05:03 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/main.cpp	Tue Aug 29 16:05:42 2017 +0000
+++ b/main.cpp	Tue Aug 29 17:05:03 2017 +0000
@@ -9,8 +9,11 @@
 #include "SpwfInterface.h"
 #include "BME280.hpp"
 #include "LED.hpp"
+#include "Servo.h"
 //Tigger flag
-bool Flag = false;
+bool LED_Flag = false;
+bool Servo_Flag = false;
+float Servo_control = 0.0;
 // WiFi network info.
 char* ssid = "megu megu fire";
 char* wifiPassword = "66666667";
@@ -20,6 +23,8 @@
 char* password = "0d4e9d94e7897df9af861007853ed3f906b0627d";
 char* clientID = "536277d0-8cb9-11e7-9727-55550d1a07e7";
 
+LED led(D7);
+Servo servo(D6);
 SpwfSAInterface interface(D8, D2); // TX, RX
 MQTTNetwork<SpwfSAInterface> network(interface);
 CayenneMQTT::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network, username, password, clientID);
@@ -54,7 +59,7 @@
     if (message.type) {
         printf(" type=%s", message.type);
     }
-    
+    printf("message.valueCount = %d\n",message.valueCount);
     for (size_t i = 0; i < message.valueCount; ++i) {
         if (message.getValue(i)) {
             printf(" value=%s", message.getValue(i));
@@ -70,12 +75,16 @@
         printf(" id=%s", message.id);
     }
     printf("\n");
-    printf("get channel ==%d\nget value ==%d\n",channel,value);
+    printf("get channel ==%d\nget value ==%c\n",channel,value);
     if(channel ==1 && value ==49){
         printf("LED has been Triger\n");
-        Flag=true;
+        //LED_Flag=true;
+        led.On();
+    }else if(channel ==2 && (value>=48 && value <=58)){
+        servo = ((float)(value-48)/10);
     }else{
-        Flag=false;
+        LED_Flag=false;
+        led.Off();
     }
 }
 
@@ -155,14 +164,10 @@
     MQTTTimer timer(5000);
     //TMP36 tmpSensor(A5);
     BME280 bmpSensor;
-    LED led(D7);
+    
     
     
     while (true) {
-        if(Flag)
-            led.On();
-        else
-            led.Off();
         // Yield to allow MQTT message processing.
         mqttClient.yield(1000);
         //printf("%d\n",bmpSensor->Temp_read());
@@ -216,8 +221,10 @@
     if (network.connected())
         printf("network disconnect\n");
         network.disconnect();
+        
+        
+    
     
 
-    return 0;
 }