Osamu Koizumi
/
Pelion-workshop-Grove-sensors
Pelion workshop with Grove sensors.
Diff: main.cpp
- Revision:
- 5:c18fab181ede
- Parent:
- 4:a107dae867fb
- Child:
- 6:254a7e7fbef1
--- a/main.cpp Wed Feb 14 15:09:00 2018 +0000 +++ b/main.cpp Wed Feb 14 17:26:42 2018 -0600 @@ -29,6 +29,10 @@ // Placeholder to hardware that trigger events (timer, button, etc) Ticker timer; +// Placeholder for storage +SDBlockDevice sd(PTE3, PTE1, PTE2, PTE4); +FATFileSystem fs("sd"); + // Pointers to the resources that will be created in main_application(). static MbedCloudClientResource* pattern_ptr; @@ -42,12 +46,13 @@ } void pattern_updated(const char *) { - printf("PUT received, new value: %s\n", pattern_ptr->get_value()); + printf("PUT received, new value: %s\n", pattern_ptr->get_value().c_str()); // Placeholder for PUT action } void blink_callback(void *) { - const char *pattern = pattern_ptr->get_value(); + String pattern_str = pattern_ptr->get_value(); + const char *pattern = pattern_str.c_str(); printf("POST received. LED pattern = %s\n", pattern); // Placeholder for POST action // The pattern is something like 500:200:500, so parse that. @@ -72,10 +77,6 @@ // Placeholder for network EthernetInterface net; - // Placeholder for storage - SDBlockDevice sd(PTE3, PTE1, PTE2, PTE4); - FATFileSystem fs("sd"); - printf("Start Simple Mbed Cloud Client\n"); // Initialize SD card @@ -129,17 +130,17 @@ button->set_value("0"); button->methods(M2MMethod::GET); button->observable(true); - button->attach_notification(M2MMethod::GET, (void*)button_callback); + button->attach_notification_callback(button_callback); MbedCloudClientResource *pattern = mbedClient.create_resource("3201/0/5853", "pattern_resource"); pattern->set_value("500:500:500:500"); pattern->methods(M2MMethod::GET | M2MMethod::PUT); - pattern->attach(M2MMethod::PUT, (void*)pattern_updated); + pattern->attach_put_callback(pattern_updated); pattern_ptr = pattern; MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_resource"); blink->methods(M2MMethod::POST); - blink->attach(M2MMethod::POST, (void*)blink_callback); + blink->attach_post_callback(blink_callback); mbedClient.register_and_connect();