This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Generic Sensor lwM2M-Client

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

Parents Reply Children
  • Hi Charlie,

    Thanks for responding. Interesting. I've found out where the problem lies.

    It's the `lwm2m_engine_create_obj_inst("3300/0");` call that returns `<err> net_lwm2m_engine: obj instance 3300/0 not found`... 

    Still makes me wonder what could be the problem. Do you have any idea as to what the problem could be? Otherwise I guess I'll just have to rewrite the implementation.

    Kind regards,

    Jochem

  • Turned out; taking your time is key... Overlooked one teeny tiny little detail. The configuration variable in the prj.cnf... Solved now, sorry for having wasted your time.

Related