float is modified in zephyr lwm2m engine

I'm currently using:
- NCS 1.6.1
- Zephyr
- NRF52840

I'm using the lwm2m client to read and write to lwm2m objects.

When the device starts for the first time, I store the default values so they can be modified later.
However, during boot, either the values are not stored correctly or not retrieved correctly.

For instance I store the value 5.0, then I perform a lwm2m read and the result is 5.2752532. This is incorrect.
But when I perform a lwm2m write of the value 5.0 and then a lwm2m read, the result is 5.0. This means that the storage code is not correct.

The objects I have defined with:

  OBJ_FIELD_DATA(resourceIDs[RESOURCE_ID_CHARGING_MIN_TEMP],               RW, FLOAT64),
  OBJ_FIELD_DATA(resourceIDs[RESOURCE_ID_CHARGING_MAX_TEMP],               RW, FLOAT64),

And I hookup the variables with:

char *FormatResourcePath (uint16_t objectID, uint16_t objectInstance,
                          uint16_t resourceID)
{
  snprintk(pathString, sizeof(pathString), "%u/%u/%u", objectID, objectInstance, resourceID);

  return pathString;
}

#define BIND_RESOURCE_DATA(path, var, perm)   lwm2m_engine_set_res_data(path, &var, sizeof(var), perm)
#define BIND_RESOURCE_INST_DATA(path, var, perm)   lwm2m_engine_set_res_data(path, &var, sizeof(var), perm)


  // Hook up the data pointers
  #define RESOURCE_PATH(resource_id) FormatResourcePath(OBJECT_ID, OBJECT_INSTANCE, resourceIDs[resource_id])

  BIND_RESOURCE_DATA(RESOURCE_PATH(RESOURCE_ID_CHARGING_MIN_TEMP),               config.chargerConfig.minTemperature_C,       0);
  BIND_RESOURCE_DATA(RESOURCE_PATH(RESOURCE_ID_CHARGING_MAX_TEMP),               config.chargerConfig.maxTemperature_C,       0);

Both config.chargerConfig.minTemperature_C and config.chargerConfig.maxTemperature_C are of the type double.

I assume double and FLOAT64 are the same site?

The function lwm2m_engine_set_res_data() is located in NCS/zephyr/subsys/net/lib/lwm2m/lwm2m_engine.c

Parents Reply Children
No Data
Related