Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit bbb120f

Browse files
Antti Yli-TokolaJanne Kiiskilä
authored andcommitted
Do not increase counter if device is not yet registered.
1 parent bfd0f2f commit bbb120f

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

main.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,24 @@ class ButtonResource {
223223
* from mbed Device Connector, then up the value with one.
224224
*/
225225
void handle_button_click() {
226-
M2MObjectInstance* inst = btn_object->object_instance();
227-
M2MResource* res = inst->resource("5501");
228-
229-
// up counter
230-
counter++;
231-
#ifdef TARGET_K64F
232-
printf("handle_button_click, new value of counter is %d\n", counter);
233-
#else
234-
printf("simulate button_click, new value of counter is %d\n", counter);
235-
#endif
236-
// serialize the value of counter as a string, and tell connector
237-
char buffer[20];
238-
int size = sprintf(buffer,"%d",counter);
239-
res->set_value((uint8_t*)buffer, size);
226+
if (mbed_client.register_successful()) {
227+
M2MObjectInstance* inst = btn_object->object_instance();
228+
M2MResource* res = inst->resource("5501");
229+
230+
// up counter
231+
counter++;
232+
#ifdef TARGET_K64F
233+
printf("handle_button_click, new value of counter is %d\n", counter);
234+
#else
235+
printf("simulate button_click, new value of counter is %d\n", counter);
236+
#endif
237+
// serialize the value of counter as a string, and tell connector
238+
char buffer[20];
239+
int size = sprintf(buffer,"%d",counter);
240+
res->set_value((uint8_t*)buffer, size);
241+
} else {
242+
printf("simulate button_click, device not registered\n");
243+
}
240244
}
241245

242246
private:
@@ -407,7 +411,7 @@ Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app
407411
break;
408412
}
409413
if(clicked) {
410-
clicked = false;
414+
clicked = false;
411415
button_resource.handle_button_click();
412416
}
413417
}

0 commit comments

Comments
 (0)