Commit 88c06aeb authored by Robert Lubos's avatar Robert Lubos Committed by Christopher Friedt
Browse files

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: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 008c384c
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ static int state_post_write_cb(uint16_t obj_inst_id,
			       bool last_block, size_t total_size)
{
	int i;
	char path[MAX_RESOURCE_LEN];

	i = get_button_index(obj_inst_id);
	if (i < 0) {
@@ -95,10 +96,19 @@ static int state_post_write_cb(uint16_t obj_inst_id,
	}

	if (button_data[i].state && !button_data[i].last_state) {
		/* off to on transition */
		button_data[i].counter++;
		if (button_data[i].counter < 0) {
			button_data[i].counter = 0;
		/* off to on transition, increment the counter */
		int64_t counter = button_data[i].counter + 1;

		if (counter < 0) {
			counter = 0;
		}

		snprintk(path, sizeof(path), "%u/%u/%u",
			 IPSO_OBJECT_PUSH_BUTTON_ID, obj_inst_id,
			 DIGITAL_INPUT_COUNTER_RID);

		if (lwm2m_engine_set_s64(path, counter) < 0) {
			LOG_ERR("Failed to increment counter resource %s", path);
		}
	}