Skip to content

Commit 6e753ae

Browse files
committed
modules: main: Remove workaround delay for nRF Cloud delta clearing
The 5-second delay that ensured nRF Cloud cleared deltas before provisioning requests is not nessecary anymore, as the issue is no longer reproducible. Will be addressed if the issue resurfaces. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent e87653b commit 6e753ae

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

app/src/main.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -868,12 +868,6 @@ static void handle_cloud_shadow_response(struct main_state *state_object,
868868
if (msg->type == CLOUD_SHADOW_RESPONSE_DELTA) {
869869
/* Clear the shadow delta by reporting back the command to the cloud. */
870870
update_shadow_reported_section(&config, command_type, command_id);
871-
/* Workaround: Add a 5-second delay to ensure that nRF Cloud clears the
872-
* delta internally before executing the command. If the command is a
873-
* provisioning request, the device will disconnect from the cloud. If this
874-
* happens too quickly, nRF Cloud may not clear the delta properly.
875-
*/
876-
k_sleep(K_SECONDS(5));
877871
command_execute(command_type);
878872
} else {
879873
/* For desired responses (initial shadow poll), only report config without

tests/on_target/tests/test_provisioning/test_provisioning.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,30 @@ def _wait_for_provisioning_completion_and_cloud_connection(
144144

145145
logger.info("Device provisioned and connected to nRF Cloud.")
146146

147+
def _verify_no_shadow_delta(dut_cloud, timeout: int = 120):
148+
"""
149+
Verifies that there is no shadow delta for the device in nRF Cloud.
150+
This indicates that the device has processed all commands and reported back its state.
151+
"""
152+
logger.info("Verifying that there is no shadow delta for the device...")
153+
154+
start = time.time()
155+
while time.time() - start < timeout:
156+
time.sleep(5)
157+
try:
158+
device = dut_cloud.cloud.get_device(dut_cloud.device_id)
159+
device_state = device["state"]
160+
if "delta" not in device_state or not device_state["delta"]:
161+
logger.info("No shadow delta found for the device.")
162+
return
163+
else:
164+
logger.debug("Shadow delta still present, waiting...")
165+
except Exception as e:
166+
logger.warning(f"Error retrieving device state from cloud: {e}")
167+
168+
raise RuntimeError(
169+
f"Shadow delta still present for device after {timeout} seconds"
170+
)
147171

148172
def _verify_device_config_reported_to_cloud(dut_cloud, timeout: int = 180):
149173
"""
@@ -274,6 +298,10 @@ def _run_reprovisioning(dut_cloud):
274298
# Wait for the device to process the command, reprovision, and reconnect
275299
_wait_for_provisioning_completion_and_cloud_connection(dut_cloud, timeout=300)
276300
_verify_device_config_reported_to_cloud(dut_cloud)
301+
# Ensure no shadow delta remains after reprovisioning. This means that the device has receieved
302+
# and processed the reprovisioning command successfully. AND reported back the command
303+
# to the shadow reported section, clearing the delta.
304+
_verify_no_shadow_delta(dut_cloud)
277305

278306
logger.info(
279307
"--- Phase 2: Reprovisioning with New Credentials Completed Successfully ---"

0 commit comments

Comments
 (0)