
Servomotor-Button
Dependencies: Cayenne-MQTT-mbed mbed Servo X_NUCLEO_IDW01M1v2 NetworkSocketAPI HCSR04
Revision 1:a2d8aec2bb92, committed 2016-10-20
- Comitter:
- jburhenn
- Date:
- Thu Oct 20 22:57:56 2016 +0000
- Parent:
- 0:d20655cd1f3c
- Child:
- 2:445f09de09bd
- Commit message:
- Added command example using onboard LED.
Changed in this revision
--- a/Cayenne-MQTT-Embedded-C.lib Fri Oct 07 18:30:51 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/myDevicesIoT/code/Cayenne-MQTT-Embedded-C/#09ef59d2d0f7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Cayenne-MQTT-mbed.lib Thu Oct 20 22:57:56 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/myDevicesIoT/code/Cayenne-MQTT-mbed/#421366004b5d
--- a/X_NUCLEO_IDW01M1v2.lib Fri Oct 07 18:30:51 2016 +0000 +++ b/X_NUCLEO_IDW01M1v2.lib Thu Oct 20 22:57:56 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/X_NUCLEO_IDW01M1v2/#4cd89586b370 +http://developer.mbed.org/teams/ST/code/X_NUCLEO_IDW01M1v2/#b328afdb2f0b
--- a/main.cpp Fri Oct 07 18:30:51 2016 +0000 +++ b/main.cpp Thu Oct 20 22:57:56 2016 +0000 @@ -21,6 +21,8 @@ MQTTNetwork<SpwfSAInterface> network(interface); Cayenne::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network); +DigitalOut led1(LED1); + /** * Print the message info. * @param[in] message The message received from the Cayenne server. @@ -69,10 +71,23 @@ // Add code to process the message. Here we just ouput the message data. outputMessage(message); - // 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 (message.topic == COMMAND_TOPIC && (error = mqttClient.publishResponse(message.channel, message.id, NULL, message.clientID)) != CAYENNE_SUCCESS) { - printf("Response failure, error: %d\n", error); + if (message.topic == COMMAND_TOPIC) { + switch(message.channel) { + case 0: + // Set the onboard LED state + led1 = atoi(message.values[0].value); + // Publish the updated LED state + if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.values[0].value)) != 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.channel, message.id, NULL, message.clientID)) != CAYENNE_SUCCESS) { + printf("Response failure, error: %d\n", error); + } } } @@ -138,13 +153,13 @@ // Publish some example data every few seconds. This should be changed to send your actual data to Cayenne. if (timer.expired()) { int error = 0; - if ((error = mqttClient.publishData(DATA_TOPIC, 0, TEMPERATURE, CELSIUS, 30.5)) != CAYENNE_SUCCESS) { + if ((error = mqttClient.publishData(DATA_TOPIC, 1, TEMPERATURE, CELSIUS, 30.5)) != CAYENNE_SUCCESS) { printf("Publish temperature failed, error: %d\n", error); } - if ((error = mqttClient.publishData(DATA_TOPIC, 1, LUMINOSITY, LUX, 1000)) != CAYENNE_SUCCESS) { + if ((error = mqttClient.publishData(DATA_TOPIC, 2, LUMINOSITY, LUX, 1000)) != CAYENNE_SUCCESS) { printf("Publish luminosity failed, error: %d\n", error); } - if ((error = mqttClient.publishData(DATA_TOPIC, 2, BAROMETRIC_PRESSURE, HECTOPASCAL, 800)) != CAYENNE_SUCCESS) { + if ((error = mqttClient.publishData(DATA_TOPIC, 3, BAROMETRIC_PRESSURE, HECTOPASCAL, 800)) != CAYENNE_SUCCESS) { printf("Publish barometric pressure failed, error: %d\n", error); } timer.countdown_ms(5000);