Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-cloud-example-lpc546xx by
Code_Additions.txt@9:5836af0b0a9c, 2018-10-11 (annotated)
- Committer:
- clarkjarvis
- Date:
- Thu Oct 11 18:28:40 2018 +0000
- Revision:
- 9:5836af0b0a9c
- Parent:
- 8:99d61dd3bfb9
Updated Resource Creation to align with Open Mobile Alliance Registry
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| clarkjarvis | 6:19cb3d7341c6 | 1 | |
| clarkjarvis | 8:99d61dd3bfb9 | 2 | // To-Do #1 |
| clarkjarvis | 5:e521ea1f4c22 | 3 | |
| clarkjarvis | 6:19cb3d7341c6 | 4 | // Setup Mbed Cloud Client Resources |
| clarkjarvis | 9:5836af0b0a9c | 5 | MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); // Digital Input / Instance / Counter |
| clarkjarvis | 5:e521ea1f4c22 | 6 | button->set_value("0"); |
| clarkjarvis | 5:e521ea1f4c22 | 7 | button->methods(M2MMethod::GET); |
| clarkjarvis | 5:e521ea1f4c22 | 8 | button->observable(true); |
| clarkjarvis | 5:e521ea1f4c22 | 9 | button->attach_notification_callback(button_callback); |
| clarkjarvis | 5:e521ea1f4c22 | 10 | |
| clarkjarvis | 9:5836af0b0a9c | 11 | MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5521", "blink_rate_resource"); // Digital Output / Instance / Delay Duration |
| clarkjarvis | 5:e521ea1f4c22 | 12 | rate->set_value("500"); |
| clarkjarvis | 5:e521ea1f4c22 | 13 | rate->methods(M2MMethod::GET | M2MMethod::PUT); |
| clarkjarvis | 5:e521ea1f4c22 | 14 | rate->observable(false); |
| clarkjarvis | 5:e521ea1f4c22 | 15 | rate->attach_put_callback(blink_rate_updated); |
| clarkjarvis | 5:e521ea1f4c22 | 16 | rate_ptr = rate; |
| clarkjarvis | 5:e521ea1f4c22 | 17 | |
| clarkjarvis | 9:5836af0b0a9c | 18 | MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5823", "blink_enable_resource"); // Digital Output / Instance / Event ID |
| clarkjarvis | 5:e521ea1f4c22 | 19 | blink->methods(M2MMethod::POST); |
| clarkjarvis | 5:e521ea1f4c22 | 20 | blink->attach_post_callback(blink_enable_callback); |
| clarkjarvis | 8:99d61dd3bfb9 | 21 | |
| clarkjarvis | 8:99d61dd3bfb9 | 22 | |
| clarkjarvis | 5:e521ea1f4c22 | 23 | |
| clarkjarvis | 5:e521ea1f4c22 | 24 | |
| clarkjarvis | 5:e521ea1f4c22 | 25 | |
| clarkjarvis | 9:5836af0b0a9c | 26 | |
| clarkjarvis | 8:99d61dd3bfb9 | 27 | // To-Do #2 |
| clarkjarvis | 8:99d61dd3bfb9 | 28 | |
| clarkjarvis | 8:99d61dd3bfb9 | 29 | // Pointer declaration for Rate Resource |
| clarkjarvis | 8:99d61dd3bfb9 | 30 | static MbedCloudClientResource* rate_ptr; |
| clarkjarvis | 8:99d61dd3bfb9 | 31 | |
| clarkjarvis | 8:99d61dd3bfb9 | 32 | |
| clarkjarvis | 8:99d61dd3bfb9 | 33 | |
| clarkjarvis | 8:99d61dd3bfb9 | 34 | |
| clarkjarvis | 8:99d61dd3bfb9 | 35 | |
| clarkjarvis | 8:99d61dd3bfb9 | 36 | // To-Do #3 |
| clarkjarvis | 8:99d61dd3bfb9 | 37 | |
| clarkjarvis | 6:19cb3d7341c6 | 38 | // Resource Callback Functions |
| clarkjarvis | 5:e521ea1f4c22 | 39 | void blink_rate_updated(const char *) { |
| clarkjarvis | 5:e521ea1f4c22 | 40 | printf("PUT received, Storing LED Blink Rate: %s (ms)\r\n", rate_ptr->get_value().c_str()); |
| clarkjarvis | 5:e521ea1f4c22 | 41 | } |
| clarkjarvis | 5:e521ea1f4c22 | 42 | |
| clarkjarvis | 5:e521ea1f4c22 | 43 | void blink_enable_callback(void *) { |
| clarkjarvis | 5:e521ea1f4c22 | 44 | String pattern_str = rate_ptr->get_value(); |
| clarkjarvis | 5:e521ea1f4c22 | 45 | const char *rate = pattern_str.c_str(); |
| clarkjarvis | 5:e521ea1f4c22 | 46 | printf("POST received. Enabling LED Blink Rate = %s (ms)\n", rate); |
| clarkjarvis | 5:e521ea1f4c22 | 47 | |
| clarkjarvis | 5:e521ea1f4c22 | 48 | float value = atoi(rate_ptr->get_value().c_str())/1000.0; |
| clarkjarvis | 5:e521ea1f4c22 | 49 | timer.detach(); |
| clarkjarvis | 5:e521ea1f4c22 | 50 | timer.attach(&led_toggle,value); |
| clarkjarvis | 5:e521ea1f4c22 | 51 | } |
| clarkjarvis | 5:e521ea1f4c22 | 52 | |
| clarkjarvis | 5:e521ea1f4c22 | 53 | void button_callback(const M2MBase& object, const NoticationDeliveryStatus status) |
| clarkjarvis | 5:e521ea1f4c22 | 54 | { |
| clarkjarvis | 5:e521ea1f4c22 | 55 | printf("Button notification. Callback: (%s)\n", object.uri_path()); |
| clarkjarvis | 5:e521ea1f4c22 | 56 | } |
| clarkjarvis | 5:e521ea1f4c22 | 57 | |
| clarkjarvis | 5:e521ea1f4c22 | 58 | |
| clarkjarvis | 5:e521ea1f4c22 | 59 | |
| clarkjarvis | 8:99d61dd3bfb9 | 60 | |
| clarkjarvis | 8:99d61dd3bfb9 | 61 | |
| clarkjarvis | 8:99d61dd3bfb9 | 62 | // To-Do #4 |
| clarkjarvis | 8:99d61dd3bfb9 | 63 | |
| clarkjarvis | 6:19cb3d7341c6 | 64 | // Call to update button resource count |
| clarkjarvis | 5:e521ea1f4c22 | 65 | button->set_value(button_count); |
