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@8:99d61dd3bfb9, 2018-10-11 (annotated)
- Committer:
- clarkjarvis
- Date:
- Thu Oct 11 15:00:58 2018 +0000
- Revision:
- 8:99d61dd3bfb9
- Parent:
- 6:19cb3d7341c6
- Child:
- 9:5836af0b0a9c
Final Lab Project (Starting Point)
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 | 5:e521ea1f4c22 | 4 | |
| clarkjarvis | 6:19cb3d7341c6 | 5 | // Setup Mbed Cloud Client Resources |
| clarkjarvis | 5:e521ea1f4c22 | 6 | MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 7 | button->set_value("0"); |
| clarkjarvis | 5:e521ea1f4c22 | 8 | button->methods(M2MMethod::GET); |
| clarkjarvis | 5:e521ea1f4c22 | 9 | button->observable(true); |
| clarkjarvis | 5:e521ea1f4c22 | 10 | button->attach_notification_callback(button_callback); |
| clarkjarvis | 5:e521ea1f4c22 | 11 | |
| clarkjarvis | 5:e521ea1f4c22 | 12 | MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5853", "blink_rate_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 13 | rate->set_value("500"); |
| clarkjarvis | 5:e521ea1f4c22 | 14 | rate->methods(M2MMethod::GET | M2MMethod::PUT); |
| clarkjarvis | 5:e521ea1f4c22 | 15 | rate->observable(false); |
| clarkjarvis | 5:e521ea1f4c22 | 16 | rate->attach_put_callback(blink_rate_updated); |
| clarkjarvis | 5:e521ea1f4c22 | 17 | rate_ptr = rate; |
| clarkjarvis | 5:e521ea1f4c22 | 18 | |
| clarkjarvis | 5:e521ea1f4c22 | 19 | MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_enable_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 20 | blink->methods(M2MMethod::POST); |
| clarkjarvis | 5:e521ea1f4c22 | 21 | blink->attach_post_callback(blink_enable_callback); |
| clarkjarvis | 8:99d61dd3bfb9 | 22 | |
| clarkjarvis | 8:99d61dd3bfb9 | 23 | |
| clarkjarvis | 5:e521ea1f4c22 | 24 | |
| clarkjarvis | 5:e521ea1f4c22 | 25 | |
| clarkjarvis | 5:e521ea1f4c22 | 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); |
