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@5:e521ea1f4c22, 2018-10-11 (annotated)
- Committer:
- clarkjarvis
- Date:
- Thu Oct 11 14:29:07 2018 +0000
- Revision:
- 5:e521ea1f4c22
- Child:
- 6:19cb3d7341c6
Cleaned Starting Version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| clarkjarvis | 5:e521ea1f4c22 | 1 | |
| clarkjarvis | 5:e521ea1f4c22 | 2 | |
| clarkjarvis | 5:e521ea1f4c22 | 3 | |
| clarkjarvis | 5:e521ea1f4c22 | 4 | static MbedCloudClientResource* rate_ptr; |
| clarkjarvis | 5:e521ea1f4c22 | 5 | |
| clarkjarvis | 5:e521ea1f4c22 | 6 | // Mbed Cloud Client resource setup |
| clarkjarvis | 5:e521ea1f4c22 | 7 | MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 8 | button->set_value("0"); |
| clarkjarvis | 5:e521ea1f4c22 | 9 | button->methods(M2MMethod::GET); |
| clarkjarvis | 5:e521ea1f4c22 | 10 | button->observable(true); |
| clarkjarvis | 5:e521ea1f4c22 | 11 | button->attach_notification_callback(button_callback); |
| clarkjarvis | 5:e521ea1f4c22 | 12 | |
| clarkjarvis | 5:e521ea1f4c22 | 13 | MbedCloudClientResource *rate = mbedClient.create_resource("3201/0/5853", "blink_rate_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 14 | rate->set_value("500"); |
| clarkjarvis | 5:e521ea1f4c22 | 15 | rate->methods(M2MMethod::GET | M2MMethod::PUT); |
| clarkjarvis | 5:e521ea1f4c22 | 16 | rate->observable(false); |
| clarkjarvis | 5:e521ea1f4c22 | 17 | rate->attach_put_callback(blink_rate_updated); |
| clarkjarvis | 5:e521ea1f4c22 | 18 | rate_ptr = rate; |
| clarkjarvis | 5:e521ea1f4c22 | 19 | |
| clarkjarvis | 5:e521ea1f4c22 | 20 | MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_enable_resource"); |
| clarkjarvis | 5:e521ea1f4c22 | 21 | blink->methods(M2MMethod::POST); |
| clarkjarvis | 5:e521ea1f4c22 | 22 | blink->attach_post_callback(blink_enable_callback); |
| clarkjarvis | 5:e521ea1f4c22 | 23 | |
| clarkjarvis | 5:e521ea1f4c22 | 24 | |
| clarkjarvis | 5:e521ea1f4c22 | 25 | |
| clarkjarvis | 5:e521ea1f4c22 | 26 | |
| clarkjarvis | 5:e521ea1f4c22 | 27 | |
| clarkjarvis | 5:e521ea1f4c22 | 28 | void blink_rate_updated(const char *) { |
| clarkjarvis | 5:e521ea1f4c22 | 29 | printf("PUT received, Storing LED Blink Rate: %s (ms)\r\n", rate_ptr->get_value().c_str()); |
| clarkjarvis | 5:e521ea1f4c22 | 30 | } |
| clarkjarvis | 5:e521ea1f4c22 | 31 | |
| clarkjarvis | 5:e521ea1f4c22 | 32 | void blink_enable_callback(void *) { |
| clarkjarvis | 5:e521ea1f4c22 | 33 | String pattern_str = rate_ptr->get_value(); |
| clarkjarvis | 5:e521ea1f4c22 | 34 | const char *rate = pattern_str.c_str(); |
| clarkjarvis | 5:e521ea1f4c22 | 35 | printf("POST received. Enabling LED Blink Rate = %s (ms)\n", rate); |
| clarkjarvis | 5:e521ea1f4c22 | 36 | |
| clarkjarvis | 5:e521ea1f4c22 | 37 | float value = atoi(rate_ptr->get_value().c_str())/1000.0; |
| clarkjarvis | 5:e521ea1f4c22 | 38 | timer.detach(); |
| clarkjarvis | 5:e521ea1f4c22 | 39 | timer.attach(&led_toggle,value); |
| clarkjarvis | 5:e521ea1f4c22 | 40 | } |
| clarkjarvis | 5:e521ea1f4c22 | 41 | |
| clarkjarvis | 5:e521ea1f4c22 | 42 | void button_callback(const M2MBase& object, const NoticationDeliveryStatus status) |
| clarkjarvis | 5:e521ea1f4c22 | 43 | { |
| clarkjarvis | 5:e521ea1f4c22 | 44 | printf("Button notification. Callback: (%s)\n", object.uri_path()); |
| clarkjarvis | 5:e521ea1f4c22 | 45 | } |
| clarkjarvis | 5:e521ea1f4c22 | 46 | |
| clarkjarvis | 5:e521ea1f4c22 | 47 | |
| clarkjarvis | 5:e521ea1f4c22 | 48 | |
| clarkjarvis | 5:e521ea1f4c22 | 49 | button->set_value(button_count); |
