Mbed Cloud Example Project - LPC546xx (Completed Version)
Fork of mbed-cloud-example-lpc546xx by
Revision 10:f30cd412e968, committed 2018-10-11
- Comitter:
- clarkjarvis
- Date:
- Thu Oct 11 18:59:07 2018 +0000
- Parent:
- 9:582d0ef3b83b
- Commit message:
- Updated Resource Creation to align with Open Mobile Alliance Registry
Changed in this revision
diff -r 582d0ef3b83b -r f30cd412e968 Bonus_Code_Additions_Accel.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bonus_Code_Additions_Accel.txt Thu Oct 11 18:59:07 2018 +0000 @@ -0,0 +1,34 @@ +Bonus Lab Steps + +Add the X-Value of the onboard Acceleromter +Requires importing the MMA8652 library into project +https://os.mbed.com/components/MMA8652-Accelerometer/ + + +// Include MMA8652 header file +#include "MMA8652.h" + + +// Create an instantiation of the accelerometer +MMA8652 acc(P3_23, P3_24); + +// Add an empty callback to support the observability of the GET request +void accel_callback(const M2MBase& object, const NoticationDeliveryStatus status){} + +// Add Mbed Cloud Client Resource +MbedCloudClientResource *accel = mbedClient.create_resource("3313/0/5702", "accel_resource"); // Accelerometer / Instance / X Value +accel->set_value("0"); +accel->methods(M2MMethod::GET); +accel->observable(true); +accel->attach_notification_callback(accel_callback); + + +// Add local variables to main() to handle storing accelerometer data +float acc_data[3]; +char buffer[10]; + + +// Add code to main while loop to periodically read and set accelerometer data +acc.ReadXYZ(acc_data); +int size = snprintf(buffer,10,"%1.4f",acc_data[0]); +accel->set_value(buffer); \ No newline at end of file
diff -r 582d0ef3b83b -r f30cd412e968 Code_Additions.txt --- a/Code_Additions.txt Thu Oct 11 15:25:26 2018 +0000 +++ b/Code_Additions.txt Thu Oct 11 18:59:07 2018 +0000 @@ -1,22 +1,21 @@ // To-Do #1 - // Setup Mbed Cloud Client Resources -MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); +MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); // Digital Input / Instance / Counter 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"); +MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5521", "blink_rate_resource"); // Digital Output / Instance / Delay Duration 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"); +MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5823", "blink_enable_resource"); // Digital Output / Instance / Event ID blink->methods(M2MMethod::POST); blink->attach_post_callback(blink_enable_callback); @@ -24,6 +23,7 @@ + // To-Do #2 // Pointer declaration for Rate Resource
diff -r 582d0ef3b83b -r f30cd412e968 main.cpp --- a/main.cpp Thu Oct 11 15:25:26 2018 +0000 +++ b/main.cpp Thu Oct 11 18:59:07 2018 +0000 @@ -39,7 +39,6 @@ // Pointer declaration for Rate Resource static MbedCloudClientResource* rate_ptr; - static bool button_pressed = false; void button_press() { button_pressed = true; @@ -71,8 +70,6 @@ } - - int main(void) { // Requires DAPLink 245+ (https://github.com/ARMmbed/DAPLink/pull/364) @@ -129,25 +126,23 @@ // To-Do #1: Add Mbed Cloud Client resources // Setup Mbed Cloud Client Resources - MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); + MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); // Digital Input / Instance / Counter 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"); + MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5521", "blink_rate_resource"); // Digital Output / Instance / Delay Duration 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"); + MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5823", "blink_enable_resource"); // Digital Output / Instance / Event ID blink->methods(M2MMethod::POST); blink->attach_post_callback(blink_enable_callback); - - // Mbed Cloud Register Client and Connect mbedClient.register_and_connect(); @@ -159,12 +154,12 @@ // Setup LED and Push BUtton timer.attach(&led_toggle, 0.5); sw2.fall(&button_press); - + // Check if client is registering or registered, if true sleep and repeat. while (mbedClient.is_register_called()) { static int button_count = 0; wait_ms(100); - + if (button_pressed) { button_pressed = false; printf("Button Pressed %d time(s).\r\n",(++button_count));