thingy 91

Good day 

I'm attempting to create an object type for my thingy91.  I've attempted to use the method described in this link to do so:


https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.1/nrf/include/net/lwm2m_client_utils.html#id4

However, I am not seeing any change server side.  Has the method changed? Are there limitations within Leshan demo server?

Attached is a snippet of my c

// DEFINING NEW OJECT TYPE
// ***********************
#define IPSO_DIGITAL_OUTPUT_ID        3201
#define OUTPUT_DIGITAL_STATE_ID        5550
#define RESOURCE_PATH LWM2M_PATH(IPSO_DIGITAL_OUTPUT_ID, 0, OUTPUT_DIGITAL_STATE_ID)

/* resource state */
struct output_data {
   bool state;
};
static struct output_data output_data[2];

#define N_RESOURCES        1
 static struct lwm2m_engine_obj_field fields[] = {
    OBJ_FIELD(OUTPUT_DIGITAL_STATE_ID, RW, BOOL),
};

static struct lwm2m_engine_obj output_obj;
static struct lwm2m_engine_obj_inst inst[2];
static struct lwm2m_engine_res res[2][N_RESOURCES];
static struct lwm2m_engine_res_inst res_inst[2][N_RESOURCES];

static struct lwm2m_engine_obj_inst *output_create(uint16_t id)
{

	LOG_ERR("create ouput init");
   /* Check that there is no other instance with this ID */
   /* It is assumed that the instance ID is same as the index in the array */
   if (inst[id].obj) {
      LOG_ERR("Cannot create instance - already existing: %u", id);
      return NULL;
   }

   if (id >= 2) {
      LOG_ERR("Cannot create instance - no more room: %u", id);
      return NULL;
   }

   /* Set default values */
   (void)memset(&output_data[id], 0, sizeof(output_data[id]));

   (void)memset(res[id], 0, sizeof(res[id][0]) * ARRAY_SIZE(res[id]));
   init_res_instance(res_inst[id], ARRAY_SIZE(res_inst[id]));

   /* initialize instance resource data */
   int i = 0, j = 0;
//    INIT_OBJ_RES(OUTPUT_DIGITAL_STATE_ID, res[id], i,
//          res_inst[id], j, 1, false, true,
//          &output_data[id].state,
//          sizeof(output_data[id].state),
//          NULL, NULL, NULL, NULL);
INIT_OBJ_RES(OUTPUT_DIGITAL_STATE_ID, res[id], i, res_inst[id], j, 1, false, true,&output_data[id].state,
		     sizeof(output_data[id].state), NULL, NULL, NULL, NULL, NULL);
   inst[id].resources = res[id];
   inst[id].resource_count = i;

   LOG_DBG("Created IPSO Output instance: %d", id);

   return &inst[id];
}

static void *on_off_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id, size_t *data_len)
 {
    // /* Only object instance 0 is currently used */
    // if (obj_inst_id != 0) {
    //    *data_len = 0;
    // return NULL;
    // }

    // /* Demo: change the sensor value */
    // ++sensor_value.val2;

    // /* Return sensor value for the LwM2M library */
    // lwm2m_engine_set_float32("3300/0/5700", &sensor_value);
    // *data_len = sizeof(sensor_value);
    // return &sensor_value;
 }

int ipso_output_init()
{
   output_obj.obj_id = IPSO_DIGITAL_OUTPUT_ID;
   output_obj.fields = fields;
   output_obj.field_count = ARRAY_SIZE(fields);
   output_obj.max_instance_count = ARRAY_SIZE(inst);
   output_obj.create_cb = output_create;
   lwm2m_register_obj(&output_obj);
   int err = lwm2m_engine_create_obj_inst(LWM2M_PATH(3201, 0));
   LOG_WRN("object inst created : %d", err);
   lwm2m_engine_register_post_write_callback(RESOURCE_PATH, on_off_cb);
   return 0;
}
// ***********************
ode. 

Parents Reply Children
Related