Hi there!
I'm using the nRF Connect SDK with the VScode extension for developing an application for the nRF9160DK. I've taken the lwm2m_client sample as base and rewrote it to a class since that suits the rest of our codebase better.
Now, I'd like to add a generic sensor to the client. Unforutnately, I can't get it to work. The 'init' method is called at the same time of lwm2m_init_location, lwm2m_init_firmware, etc. set_value is used in another dummy thread that's started after a connection has been established. Oh, and I've used this tutorial for defining the custom generic sensor object.
struct float32_value generic_sensor_c::sensor_value = { 1, 0 };
void *generic_sensor_c::read_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id, size_t *data_len){
if (obj_inst_id != instance) {
*data_len = 0;
return NULL;
}
++sensor_value.val2;
lwm2m_engine_set_float32((char*)"3300/0/5700", &sensor_value);
*data_len = sizeof(sensor_value);
return &sensor_value;
}
void generic_sensor_c::init(){
lwm2m_engine_create_obj_inst((char*)"3300/0");
lwm2m_engine_register_read_callback((char*)"3300/0/5700", read_cb);
}
void generic_sensor_c::set_value(const int32_t new_value){
sensor_value.val2 = new_value;
lwm2m_engine_set_float32((char*)"3300/0/5700", &sensor_value);
}
Obviously, I must be overseeing something.
Kind regards,
Jochem