samples: net: lwm2m_client: Replace deprecated calls
Replace calls to deprecated functions with new ones. Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
This commit is contained in:
parent
abafd7e810
commit
6dfe7e2458
|
@ -26,8 +26,8 @@ static int firmware_update_cb(uint16_t obj_inst_id,
|
|||
/* If success, set the update result as RESULT_SUCCESS.
|
||||
* In reality, it should be set at function lwm2m_setup()
|
||||
*/
|
||||
lwm2m_engine_set_u8("5/0/3", STATE_IDLE);
|
||||
lwm2m_engine_set_u8("5/0/5", RESULT_SUCCESS);
|
||||
lwm2m_set_u8(&LWM2M_OBJ(5, 0, 3), STATE_IDLE);
|
||||
lwm2m_set_u8(&LWM2M_OBJ(5, 0, 5), RESULT_SUCCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -51,12 +51,12 @@ static int firmware_block_received_cb(uint16_t obj_inst_id,
|
|||
void init_firmware_update(void)
|
||||
{
|
||||
/* setup data buffer for block-wise transfer */
|
||||
lwm2m_engine_register_pre_write_callback("5/0/0", firmware_get_buf);
|
||||
lwm2m_register_pre_write_callback(&LWM2M_OBJ(5, 0, 0), firmware_get_buf);
|
||||
lwm2m_firmware_set_write_cb(firmware_block_received_cb);
|
||||
|
||||
if (IS_ENABLED(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)) {
|
||||
lwm2m_engine_create_res_inst("5/0/8/0");
|
||||
lwm2m_engine_set_res_buf("5/0/8/0", &supported_protocol[0],
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(5, 0, 8, 0));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(5, 0, 8, 0), &supported_protocol[0],
|
||||
sizeof(supported_protocol[0]),
|
||||
sizeof(supported_protocol[0]), 0);
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ static int led_on_off_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_ins
|
|||
|
||||
led_state = led_val;
|
||||
/* TODO: Move to be set by an internal post write function */
|
||||
lwm2m_engine_set_s32("3311/0/5852", 0);
|
||||
lwm2m_set_s32(&LWM2M_OBJ(3311, 0, 5852), 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -62,10 +62,10 @@ int init_led_device(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
lwm2m_engine_create_obj_inst("3311/0");
|
||||
lwm2m_engine_register_post_write_callback("3311/0/5850", led_on_off_cb);
|
||||
lwm2m_engine_set_res_buf("3311/0/5750", LIGHT_NAME, sizeof(LIGHT_NAME), sizeof(LIGHT_NAME),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_create_object_inst(&LWM2M_OBJ(3311, 0));
|
||||
lwm2m_register_post_write_callback(&LWM2M_OBJ(3311, 0, 5850), led_on_off_cb);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3311, 0, 5750), LIGHT_NAME, sizeof(LIGHT_NAME),
|
||||
sizeof(LIGHT_NAME), LWM2M_RES_DATA_FLAG_RO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ static int device_reboot_cb(uint16_t obj_inst_id,
|
|||
/* Add an error for testing */
|
||||
lwm2m_device_add_err(LWM2M_DEVICE_ERROR_LOW_POWER);
|
||||
/* Change the battery voltage for testing */
|
||||
lwm2m_engine_set_s32("3/0/7/0", (bat_mv - 1));
|
||||
lwm2m_set_s32(&LWM2M_OBJ(3, 0, 7, 0), (bat_mv - 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static int device_factory_default_cb(uint16_t obj_inst_id,
|
|||
/* Add an error for testing */
|
||||
lwm2m_device_add_err(LWM2M_DEVICE_ERROR_GPS_FAILURE);
|
||||
/* Change the USB current for testing */
|
||||
lwm2m_engine_set_s32("3/0/8/1", (usb_ma - 1));
|
||||
lwm2m_set_s32(&LWM2M_OBJ(3, 0, 8, 1), (usb_ma - 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -110,7 +110,8 @@ static int lwm2m_setup(void)
|
|||
/* setup SECURITY object */
|
||||
|
||||
/* Server URL */
|
||||
ret = lwm2m_engine_get_res_buf("0/0/0", (void **)&server_url, &server_url_len, NULL, NULL);
|
||||
ret = lwm2m_get_res_buf(&LWM2M_OBJ(0, 0, 0), (void **)&server_url, &server_url_len, NULL,
|
||||
NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -120,88 +121,68 @@ static int lwm2m_setup(void)
|
|||
strchr(SERVER_ADDR, ':') ? "[" : "", SERVER_ADDR,
|
||||
strchr(SERVER_ADDR, ':') ? "]" : "");
|
||||
|
||||
lwm2m_engine_set_res_data_len("0/0/0", server_url_len + 1);
|
||||
lwm2m_set_res_data_len(&LWM2M_OBJ(0, 0, 0), server_url_len + 1);
|
||||
|
||||
/* Security Mode */
|
||||
lwm2m_engine_set_u8("0/0/2", IS_ENABLED(CONFIG_LWM2M_DTLS_SUPPORT) ? 0 : 3);
|
||||
lwm2m_set_u8(&LWM2M_OBJ(0, 0, 2), IS_ENABLED(CONFIG_LWM2M_DTLS_SUPPORT) ? 0 : 3);
|
||||
#if defined(CONFIG_LWM2M_DTLS_SUPPORT)
|
||||
lwm2m_engine_set_string("0/0/3", (char *)client_psk_id);
|
||||
lwm2m_engine_set_opaque("0/0/5",
|
||||
lwm2m_set_string(&LWM2M_OBJ(0, 0, 3), (char *)client_psk_id);
|
||||
lwm2m_set_opaque(&LWM2M_OBJ(0, 0, 5),
|
||||
(void *)client_psk, sizeof(client_psk));
|
||||
#endif /* CONFIG_LWM2M_DTLS_SUPPORT */
|
||||
|
||||
#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
|
||||
/* Mark 1st instance of security object as a bootstrap server */
|
||||
lwm2m_engine_set_u8("0/0/1", 1);
|
||||
lwm2m_set_u8(&LWM2M_OBJ(0, 0, 1), 1);
|
||||
|
||||
/* Create 2nd instance of security object needed for bootstrap */
|
||||
lwm2m_engine_create_obj_inst("0/1");
|
||||
lwm2m_create_object_inst(&LWM2M_OBJ(0, 1));
|
||||
#else
|
||||
/* Match Security object instance with a Server object instance with
|
||||
* Short Server ID.
|
||||
*/
|
||||
lwm2m_engine_set_u16("0/0/10", CONFIG_LWM2M_SERVER_DEFAULT_SSID);
|
||||
lwm2m_engine_set_u16("1/0/0", CONFIG_LWM2M_SERVER_DEFAULT_SSID);
|
||||
lwm2m_set_u16(&LWM2M_OBJ(0, 0, 10), CONFIG_LWM2M_SERVER_DEFAULT_SSID);
|
||||
lwm2m_set_u16(&LWM2M_OBJ(1, 0, 0), CONFIG_LWM2M_SERVER_DEFAULT_SSID);
|
||||
#endif
|
||||
|
||||
/* setup SERVER object */
|
||||
|
||||
/* setup DEVICE object */
|
||||
|
||||
lwm2m_engine_set_res_buf("3/0/0", CLIENT_MANUFACTURER,
|
||||
sizeof(CLIENT_MANUFACTURER),
|
||||
sizeof(CLIENT_MANUFACTURER),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_set_res_buf("3/0/1", CLIENT_MODEL_NUMBER,
|
||||
sizeof(CLIENT_MODEL_NUMBER),
|
||||
sizeof(CLIENT_MODEL_NUMBER),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_set_res_buf("3/0/2", CLIENT_SERIAL_NUMBER,
|
||||
sizeof(CLIENT_SERIAL_NUMBER),
|
||||
sizeof(CLIENT_SERIAL_NUMBER),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_set_res_buf("3/0/3", CLIENT_FIRMWARE_VER,
|
||||
sizeof(CLIENT_FIRMWARE_VER),
|
||||
sizeof(CLIENT_FIRMWARE_VER),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_register_exec_callback("3/0/4", device_reboot_cb);
|
||||
lwm2m_engine_register_exec_callback("3/0/5", device_factory_default_cb);
|
||||
lwm2m_engine_set_res_buf("3/0/9", &bat_level, sizeof(bat_level),
|
||||
sizeof(bat_level), 0);
|
||||
lwm2m_engine_set_res_buf("3/0/10", &mem_free, sizeof(mem_free),
|
||||
sizeof(mem_free), 0);
|
||||
lwm2m_engine_set_res_buf("3/0/17", CLIENT_DEVICE_TYPE,
|
||||
sizeof(CLIENT_DEVICE_TYPE),
|
||||
sizeof(CLIENT_DEVICE_TYPE),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_set_res_buf("3/0/18", CLIENT_HW_VER,
|
||||
sizeof(CLIENT_HW_VER), sizeof(CLIENT_HW_VER),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_engine_set_res_buf("3/0/20", &bat_status, sizeof(bat_status),
|
||||
sizeof(bat_status), 0);
|
||||
lwm2m_engine_set_res_buf("3/0/21", &mem_total, sizeof(mem_total),
|
||||
sizeof(mem_total), 0);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 0), CLIENT_MANUFACTURER, sizeof(CLIENT_MANUFACTURER),
|
||||
sizeof(CLIENT_MANUFACTURER), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 1), CLIENT_MODEL_NUMBER, sizeof(CLIENT_MODEL_NUMBER),
|
||||
sizeof(CLIENT_MODEL_NUMBER), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 2), CLIENT_SERIAL_NUMBER, sizeof(CLIENT_SERIAL_NUMBER),
|
||||
sizeof(CLIENT_SERIAL_NUMBER), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 3), CLIENT_FIRMWARE_VER, sizeof(CLIENT_FIRMWARE_VER),
|
||||
sizeof(CLIENT_FIRMWARE_VER), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_register_exec_callback(&LWM2M_OBJ(3, 0, 4), device_reboot_cb);
|
||||
lwm2m_register_exec_callback(&LWM2M_OBJ(3, 0, 5), device_factory_default_cb);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 9), &bat_level, sizeof(bat_level), sizeof(bat_level), 0);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 10), &mem_free, sizeof(mem_free), sizeof(mem_free), 0);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 17), CLIENT_DEVICE_TYPE, sizeof(CLIENT_DEVICE_TYPE),
|
||||
sizeof(CLIENT_DEVICE_TYPE), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 18), CLIENT_HW_VER, sizeof(CLIENT_HW_VER),
|
||||
sizeof(CLIENT_HW_VER), LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 20), &bat_status, sizeof(bat_status),
|
||||
sizeof(bat_status), 0);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 21), &mem_total, sizeof(mem_total),
|
||||
sizeof(mem_total), 0);
|
||||
|
||||
/* add power source resource instances */
|
||||
lwm2m_engine_create_res_inst("3/0/6/0");
|
||||
lwm2m_engine_set_res_buf("3/0/6/0", &bat_idx, sizeof(bat_idx),
|
||||
sizeof(bat_idx), 0);
|
||||
|
||||
lwm2m_engine_create_res_inst("3/0/7/0");
|
||||
lwm2m_engine_set_res_buf("3/0/7/0", &bat_mv, sizeof(bat_mv),
|
||||
sizeof(bat_mv), 0);
|
||||
lwm2m_engine_create_res_inst("3/0/8/0");
|
||||
lwm2m_engine_set_res_buf("3/0/8/0", &bat_ma, sizeof(bat_ma),
|
||||
sizeof(bat_ma), 0);
|
||||
lwm2m_engine_create_res_inst("3/0/6/1");
|
||||
lwm2m_engine_set_res_buf("3/0/6/1", &usb_idx, sizeof(usb_idx),
|
||||
sizeof(usb_idx), 0);
|
||||
lwm2m_engine_create_res_inst("3/0/7/1");
|
||||
lwm2m_engine_set_res_buf("3/0/7/1", &usb_mv, sizeof(usb_mv),
|
||||
sizeof(usb_mv), 0);
|
||||
lwm2m_engine_create_res_inst("3/0/8/1");
|
||||
lwm2m_engine_set_res_buf("3/0/8/1", &usb_ma, sizeof(usb_ma),
|
||||
sizeof(usb_ma), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 6, 0));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 6, 0), &bat_idx, sizeof(bat_idx), sizeof(bat_idx), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 7, 0));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 7, 0), &bat_mv, sizeof(bat_mv), sizeof(bat_mv), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 8, 0));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 8, 0), &bat_ma, sizeof(bat_ma), sizeof(bat_ma), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 6, 1));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 6, 1), &usb_idx, sizeof(usb_idx), sizeof(usb_idx), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 7, 1));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 7, 1), &usb_mv, sizeof(usb_mv), sizeof(usb_mv), 0);
|
||||
lwm2m_create_res_inst(&LWM2M_OBJ(3, 0, 8, 1));
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 8, 1), &usb_ma, sizeof(usb_ma), sizeof(usb_ma), 0);
|
||||
|
||||
/* setup FIRMWARE object */
|
||||
if (IS_ENABLED(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT)) {
|
||||
|
|
|
@ -45,7 +45,7 @@ static void temp_work_cb(struct k_work *work)
|
|||
v = 20.0 + (double)sys_rand32_get() / UINT32_MAX * 5.0;
|
||||
}
|
||||
|
||||
lwm2m_engine_set_float("3303/0/5700", &v);
|
||||
lwm2m_set_f64(&LWM2M_OBJ(3303, 0, 5700), v);
|
||||
|
||||
out:
|
||||
k_work_schedule(&temp_work, PERIOD);
|
||||
|
@ -53,7 +53,7 @@ out:
|
|||
|
||||
void init_temp_sensor(void)
|
||||
{
|
||||
if (lwm2m_engine_create_obj_inst("3303/0") == 0) {
|
||||
if (lwm2m_create_object_inst(&LWM2M_OBJ(3303, 0)) == 0) {
|
||||
k_work_init_delayable(&temp_work, temp_work_cb);
|
||||
k_work_schedule(&temp_work, K_NO_WAIT);
|
||||
}
|
||||
|
|
|
@ -49,9 +49,9 @@ static int timer_digital_state_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_
|
|||
|
||||
void init_timer_object(void)
|
||||
{
|
||||
lwm2m_engine_create_obj_inst("3340/0");
|
||||
lwm2m_engine_register_validate_callback("3340/0/5850", timer_on_off_validate_cb);
|
||||
lwm2m_engine_register_post_write_callback("3340/0/5543", timer_digital_state_cb);
|
||||
lwm2m_engine_set_res_buf("3340/0/5750", TIMER_NAME, sizeof(TIMER_NAME), sizeof(TIMER_NAME),
|
||||
LWM2M_RES_DATA_FLAG_RO);
|
||||
lwm2m_create_object_inst(&LWM2M_OBJ(3340, 0));
|
||||
lwm2m_register_validate_callback(&LWM2M_OBJ(3340, 0, 5850), timer_on_off_validate_cb);
|
||||
lwm2m_register_post_write_callback(&LWM2M_OBJ(3340, 0, 5543), timer_digital_state_cb);
|
||||
lwm2m_set_res_buf(&LWM2M_OBJ(3340, 0, 5750), TIMER_NAME, sizeof(TIMER_NAME),
|
||||
sizeof(TIMER_NAME), LWM2M_RES_DATA_FLAG_RO);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue