
This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.
Fork of mbed-os-example-client by
Revision 65:ea64e559b7d3, committed 2017-02-20
- Comitter:
- mbed_official
- Date:
- Mon Feb 20 15:10:50 2017 +0000
- Parent:
- 64:d7458b04a609
- Child:
- 66:8079b3572c2e
- Commit message:
- Do not increase counter if device is not yet registered.
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-client
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Feb 15 09:30:13 2017 +0000 +++ b/main.cpp Mon Feb 20 15:10:50 2017 +0000 @@ -223,20 +223,24 @@ * from mbed Device Connector, then up the value with one. */ void handle_button_click() { - M2MObjectInstance* inst = btn_object->object_instance(); - M2MResource* res = inst->resource("5501"); + if (mbed_client.register_successful()) { + M2MObjectInstance* inst = btn_object->object_instance(); + M2MResource* res = inst->resource("5501"); - // up counter - counter++; -#ifdef TARGET_K64F - printf("handle_button_click, new value of counter is %d\n", counter); -#else - printf("simulate button_click, new value of counter is %d\n", counter); -#endif - // serialize the value of counter as a string, and tell connector - char buffer[20]; - int size = sprintf(buffer,"%d",counter); - res->set_value((uint8_t*)buffer, size); + // up counter + counter++; + #ifdef TARGET_K64F + printf("handle_button_click, new value of counter is %d\n", counter); + #else + printf("simulate button_click, new value of counter is %d\n", counter); + #endif + // serialize the value of counter as a string, and tell connector + char buffer[20]; + int size = sprintf(buffer,"%d",counter); + res->set_value((uint8_t*)buffer, size); + } else { + printf("simulate button_click, device not registered\n"); + } } private: @@ -407,7 +411,7 @@ break; } if(clicked) { - clicked = false; + clicked = false; button_resource.handle_button_click(); } }