Example application using MQTT for a thermostat application.
Dependencies: C12832 EthernetInterface LM75B MQTT MbedJSONValue RGB-fun mbed-rtos mbed
Fork of HelloMQTT_FRDMK64F by
Revision 19:852fa5912f91, committed 2017-04-25
- Comitter:
- sillevl
- Date:
- Tue Apr 25 12:42:01 2017 +0000
- Parent:
- 18:da0ba00e21ab
- Commit message:
- update led color using json
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 25 12:22:31 2017 +0000
+++ b/main.cpp Tue Apr 25 12:42:01 2017 +0000
@@ -55,18 +55,19 @@
lcd.locate(0,3);
printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id);
printf("Payload %.*s\n", message.payloadlen, (char*)message.payload);
+ lcd.puts((char*)message.payload);
- Color color((int) std::strtol((char*)message.payload, 0, 16));
- led.setColor(&color);
-
-/* //lcd.puts((char*)message.payload);
+ char buffer[32] = {0};
+ memcpy(buffer, message.payload, message.payloadlen);
MbedJSONValue payload;
- parse(payload, (char*)message.payload);
+ parse(payload, buffer);
- std::string color = payload["color"].get<std::string>();
- printf("Color: %s\n", color.c_str());*/
+ std::string color_string = payload["color"].get<std::string>();
+ printf("Color: %s\n", color_string.c_str());
+ Color color((int) std::strtol(color_string.c_str(), 0, 16));
+ led.setColor(&color);
}
int main(int argc, char* argv[])
