Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Cayenne-MQTT-mbed mbed Servo X_NUCLEO_IDW01M1v2 NetworkSocketAPI HCSR04
Diff: main.cpp
- Revision:
- 10:2951beb4fca3
- Parent:
- 9:e3a211745f71
- Child:
- 11:760e0ede36bb
--- a/main.cpp Tue Jul 16 03:54:11 2019 +0000
+++ b/main.cpp Tue Jul 16 21:15:50 2019 +0000
@@ -31,6 +31,7 @@
//Servo myservo(D10);
int iotvalue;
+int iotvalue2;
//Function prototype new
MQTTTimer publishData(MQTTTimer, int, int);
@@ -46,6 +47,7 @@
wait(0.2);
ledGreen = iotvalue;
+ ledRed = iotvalue2;
//ULTRASONIC SENSOR WITH LED/////////////////////
// long distance = sensor.distance();
@@ -103,7 +105,7 @@
// printf("Publish data failed, error: %d\n", error);
// }
// Restart the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval.
- timer.countdown_ms(5000);
+ timer.countdown_ms(2500);
}
return timer;
}
@@ -168,6 +170,15 @@
printf("Publish LED state failure, error: %d\n", error);
}
break;
+ case 5:
+ // Set the onboard LED state
+ iotvalue2 = atoi(message.getValue());
+ printf("From Cayenne = %d\n",iotvalue);
+ // 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.