BUTTON LED COMBO - ST IOT CHALLENGE 2020

Dependencies:   Cayenne-MQTT-mbed mbed X_NUCLEO_IDW01M1v2 NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
stiotchallenge
Date:
Fri Aug 02 05:00:44 2019 +0000
Parent:
12:5c663a304fca
Child:
14:b1ac34c01d70
Commit message:
Module 2: Led-Button Combo

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jul 23 01:51:31 2019 +0000
+++ b/main.cpp	Fri Aug 02 05:00:44 2019 +0000
@@ -7,8 +7,6 @@
 #include "CayenneMQTTClient.h"
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
-//#include "hcsr04.h"
-//#include "Servo.h"
 
 // WiFi network info.
 char* ssid = "iPhone";
@@ -26,11 +24,10 @@
 DigitalIn button1(USER_BUTTON);
 DigitalOut led1(LED1);
 DigitalOut ledGreen(D11);
-DigitalOut ledRed(D12);
-//HCSR04 sensor(D7, D6);
-//Servo myservo(D10);
+//DigitalOut ledRed(D12);
 
 int iotvalue;
+//int iotvalue2;
 
 //Function prototype new
 MQTTTimer publishData(MQTTTimer, int/*, int*/);
@@ -46,28 +43,8 @@
     wait(0.2);
 
     ledGreen = iotvalue;
-    
-/*ULTRASONIC + SERVO/////////////////////////////
-    int openclose;
-    long distance = sensor.distance();   
-    printf("distance  %d  \n",distance);
-    wait(1.0); // 1 sec
-    if (distance > 50) {
-        ledGreen = 0;
-        ledRed = 1;   
-        myservo = 1; //tutup
-        wait(0.2);
-        openclose = 0;
-    }
-    if (distance <50) {
-        ledGreen = 1;
-        ledRed = 0;
-        myservo = 0; //buka
-        wait(0.2);
-        openclose = 1;
-    }
-*/    
-    timer = publishData(timer, ledGreen/*, openclose*/);
+      
+    timer = publishData(timer, ledGreen/*, ledRed*/);
     return timer;
 }
 
@@ -149,6 +126,16 @@
             break;
         }
         
+/*        case 5:
+            // Set the onboard LED state
+            iotvalue2 = atoi(message.getValue());
+            printf("From Cayenne = %d\n",iotvalue2);
+            // Publish the updated LED state
+            if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) {
+                printf("Publish LED state failure, error: %d\n", error);
+            }
+            break;
+*/        
         // If this is a command message we publish a response. Here we are just sending a default 'OK' response.
         // An error response should be sent if there are issues processing the message.
         if ((error = mqttClient.publishResponse(message.id, NULL, message.clientID)) != CAYENNE_SUCCESS) {