Mbed Cloud Example Project - LPC546xx (Completed Version)

Fork of mbed-cloud-example-lpc546xx by Clark Jarvis

Files at this revision

API Documentation at this revision

Comitter:
clarkjarvis
Date:
Thu Oct 11 15:25:26 2018 +0000
Parent:
8:99d61dd3bfb9
Child:
10:f30cd412e968
Commit message:
Final version of complete lab

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Oct 11 15:00:58 2018 +0000
+++ b/main.cpp	Thu Oct 11 15:25:26 2018 +0000
@@ -36,6 +36,9 @@
 FATFileSystem fs("sd");
 
 // To-Do #2: Add global pointer declaration for Rate Resource
+// Pointer declaration for Rate Resource
+static MbedCloudClientResource* rate_ptr;
+
 
 static bool button_pressed = false;
 void button_press() {
@@ -47,6 +50,26 @@
 }
 
 // To-Do #3: Add Cloud Client Resource Callback Functions
+// Resource Callback Functions
+void blink_rate_updated(const char *) {
+    printf("PUT received, Storing LED Blink Rate: %s (ms)\r\n", rate_ptr->get_value().c_str());
+}
+
+void blink_enable_callback(void *) {
+    String pattern_str = rate_ptr->get_value();
+    const char *rate = pattern_str.c_str();
+    printf("POST received. Enabling LED Blink Rate = %s (ms)\n", rate);
+
+    float value = atoi(rate_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());
+}
+
 
 
 
@@ -105,6 +128,23 @@
     printf("Client initialized\r\n");
 
     // To-Do #1: Add Mbed Cloud Client resources
+    // Setup Mbed Cloud Client Resources
+    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);
+    
+    MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5853", "blink_rate_resource");
+    rate->set_value("500");
+    rate->methods(M2MMethod::GET | M2MMethod::PUT);
+    rate->observable(false);
+    rate->attach_put_callback(blink_rate_updated);
+    rate_ptr = rate;
+    
+    MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_enable_resource");
+    blink->methods(M2MMethod::POST);
+    blink->attach_post_callback(blink_enable_callback);
 
 
 
@@ -129,6 +169,8 @@
             button_pressed = false;
             printf("Button Pressed %d time(s).\r\n",(++button_count));
             // To-Do #4: Add function to set button resource value
+            // Call to update button resource count
+            button->set_value(button_count);
         }
     }