v2.9.0: azure_iot_hub_dps_reset() does not reset DPS registration

According to the documentation, you should run azure_iot_hub_dps_reset() in order to force DPS registration again.

But if the device has previously been enrolled and a device created using DPS, and then the keys changed on the device, the reset function doesn't remove the required keys to trigger DPS.

Temporarily fixed by adding a "return 0" as very first thing in dps_settings_handler() in order for the clauses where reg status = AZURE_IOT_HUB_DPS_REG_STATUS_ASSIGNED is set.

The proper fix is for the reset function, or rather, azure_iot_hub_dps_hostname_delete() and azure_iot_hub_dps_device_id_delete(), to _not_ return err on unsuccessful deletion of the first part (key), so that second key (len) can be correctly deleted, i.e.:

void azure_iot_hub_dps_hostname_delete(void)
{
	settings_delete(DPS_SETTINGS_KEY "/" DPS_SETTINGS_HOSTNAME_KEY);
	settings_delete(DPS_SETTINGS_KEY "/" DPS_SETTINGS_HOSTNAME_LEN_KEY);
	dps_reg_ctx.assigned_hub = AZ_SPAN_EMPTY;
}

or possibly:

int azure_iot_hub_dps_hostname_delete(void)
{
	int err1 = 0, err2 = 0;

	err1 = settings_delete(DPS_SETTINGS_KEY "/" DPS_SETTINGS_HOSTNAME_KEY);
	if (err1) {
		LOG_ERR("Failed to delete Azure IoT Hub hostname, error: %d", err1);
	}

	err2 = settings_delete(DPS_SETTINGS_KEY "/" DPS_SETTINGS_HOSTNAME_LEN_KEY);
	if (err2) {
		LOG_ERR("Failed to delete Azure IoT Hub hostname length, error: %d", err2);
	}

	dps_reg_ctx.assigned_hub = AZ_SPAN_EMPTY;

	return err1 + err2;
}

This issue took me quite some time to figure out and it essentially bricks a device, so I hope it'll be fixed in an upcoming release.

Related