Mbed Cloud Example Project - LPC546xx (Completed Version)
Fork of mbed-cloud-example-lpc546xx by
Diff: main.cpp
- Revision:
- 5:e521ea1f4c22
- Parent:
- 4:5994ee6e8f63
- Child:
- 8:99d61dd3bfb9
--- a/main.cpp Thu Oct 11 04:05:03 2018 +0000 +++ b/main.cpp Thu Oct 11 14:29:07 2018 +0000 @@ -33,11 +33,9 @@ // Placeholder for storage SDBlockDevice sd(D11, D12, D13, D10); //MOSI, MISO, SCLK, CS - FATFileSystem fs("sd"); -// Pointers to the resources that will be created in main_application(). -static MbedCloudClientResource* pattern_ptr; +// To-Do: Add global pointer declaration for static bool button_pressed = false; void button_press() { @@ -48,24 +46,9 @@ led = !led; } -void blink_rate_updated(const char *) { - printf("PUT received, Storing LED Blink Rate: %s (ms)\r\n", pattern_ptr->get_value().c_str()); -} - -void blink_enable_callback(void *) { - String pattern_str = pattern_ptr->get_value(); - const char *pattern = pattern_str.c_str(); - printf("POST received. Enabling LED Blink Rate = %s (ms)\n", pattern); +// To Do: Add Cloud Client Resource Callback Functions - float value = atoi(pattern_ptr->get_value().c_str())/1000.0; - timer.detach(); - timer.attach(&led_toggle,value); -} -void button_callback(const M2MBase& object, const NoticationDeliveryStatus status) -{ - printf("Button notification. Callback: (%s)\n", object.uri_path()); -} int main(void) { @@ -121,23 +104,9 @@ } printf("Client initialized\r\n"); - // Mbed Cloud Client resource setup - MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); - button->set_value("0"); - button->methods(M2MMethod::GET); - button->observable(true); - button->attach_notification_callback(button_callback); + // To Do: Add Mbed Cloud Client resources - MbedCloudClientResource *pattern = mbedClient.create_resource("3201/0/5853", "blink_rate_resource"); - pattern->set_value("500"); - pattern->methods(M2MMethod::GET | M2MMethod::PUT); - pattern->observable(false); - pattern->attach_put_callback(blink_rate_updated); - pattern_ptr = pattern; - MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_enable_resource"); - blink->methods(M2MMethod::POST); - blink->attach_post_callback(blink_enable_callback); // Mbed Cloud Register Client and Connect mbedClient.register_and_connect(); @@ -159,7 +128,7 @@ if (button_pressed) { button_pressed = false; printf("Button Pressed %d time(s).\r\n",(++button_count)); - button->set_value(button_count); + // To Do: Add function to set button resource value } }