Skip to content

Commit 88c06ae

Browse files
rluboscfriedt
authored andcommitted
net: lwm2m: Fix IPSO Push Button counter incrementation
The Counter resource in the IPSO Push Button object was incremented silently by the post write handler of the State resource. This prevented the resource from being marked as updated, effectively preventing the engine from sending notifications to observers. Fix this, by setting the new counter value with `lwm2m_engine_set_u64()` instead. This will update the resource value, and trigger the engine to send notifications if needed. Signed-off-by: Robert Lubos <[email protected]>
1 parent 008c384 commit 88c06ae

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

subsys/net/lib/lwm2m/ipso_push_button.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,27 @@ static int state_post_write_cb(uint16_t obj_inst_id,
8888
bool last_block, size_t total_size)
8989
{
9090
int i;
91+
char path[MAX_RESOURCE_LEN];
9192

9293
i = get_button_index(obj_inst_id);
9394
if (i < 0) {
9495
return i;
9596
}
9697

9798
if (button_data[i].state && !button_data[i].last_state) {
98-
/* off to on transition */
99-
button_data[i].counter++;
100-
if (button_data[i].counter < 0) {
101-
button_data[i].counter = 0;
99+
/* off to on transition, increment the counter */
100+
int64_t counter = button_data[i].counter + 1;
101+
102+
if (counter < 0) {
103+
counter = 0;
104+
}
105+
106+
snprintk(path, sizeof(path), "%u/%u/%u",
107+
IPSO_OBJECT_PUSH_BUTTON_ID, obj_inst_id,
108+
DIGITAL_INPUT_COUNTER_RID);
109+
110+
if (lwm2m_engine_set_s64(path, counter) < 0) {
111+
LOG_ERR("Failed to increment counter resource %s", path);
102112
}
103113
}
104114

0 commit comments

Comments
 (0)