diff --git a/frontend/src/lib/services/ble-deployer.ts b/frontend/src/lib/services/ble-deployer.ts index 66feb20..04c1b76 100644 --- a/frontend/src/lib/services/ble-deployer.ts +++ b/frontend/src/lib/services/ble-deployer.ts @@ -367,8 +367,11 @@ export class BLEHardwareDeployer { /* INIT: any non-IDLE(0), non-ERROR(5/6) state means command was processed. * DATA: state must stay RECEIVING(1) — error if >=5. */ if (cmd === CMD_INIT) { - if (state >= 1 && state <= 4) { - console.log(`[BLE-CMD] ${cmdName}: state=${state} — INIT confirmed via read poll`); + /* Only RECEIVING(1) means INIT was processed. + * Don't accept FLASHING(3) or SERIAL_BRIDGE(4) — + * those are stale states from a previous deploy. */ + if (state === 1) { + console.log(`[BLE-CMD] ${cmdName}: state=1 (RECEIVING) — INIT confirmed via read poll`); return 'ok' as const; } } else { /* DATA */ diff --git a/frontend/static/sw.js b/frontend/static/sw.js index 09ca5e6..eade4f8 100644 --- a/frontend/static/sw.js +++ b/frontend/static/sw.js @@ -1,5 +1,5 @@ // static/sw.js -const CACHE_VERSION = 'elemes-v9'; +const CACHE_VERSION = 'elemes-v10'; const STATIC_CACHE = `${CACHE_VERSION}-static`; const API_CACHE = `${CACHE_VERSION}-api`; const ASSET_CACHE = `${CACHE_VERSION}-assets`; diff --git a/velxio-deployer-firmware/main/state_machine.c b/velxio-deployer-firmware/main/state_machine.c index 2775a01..af74d06 100644 --- a/velxio-deployer-firmware/main/state_machine.c +++ b/velxio-deployer-firmware/main/state_machine.c @@ -168,7 +168,11 @@ void state_machine_process_event(sm_event_t event, void *data) case STATE_SERIAL_BRIDGE: if (event == EVENT_BLE_INIT) { serial_bridge_stop(); - binary_parser_reset(); + /* Don't call binary_parser_reset() here — the parser's INIT + * handler (binary_parser.c:51-68) already resets buffer_offset, + * buffer_size, memset, and state. Calling reset here wipes + * expected_total_crc to 0 AFTER the parser already set it + * from the INIT payload, causing END CRC verification to fail. */ current_state = STATE_RECEIVING; led_set_pattern(LED_BLUE_BLINK); ESP_LOGI(TAG, "Transition: SERIAL_BRIDGE -> RECEIVING (re-deploy)"); @@ -185,7 +189,7 @@ void state_machine_process_event(sm_event_t event, void *data) if (event == EVENT_BLE_INIT) { ESP_LOGI(TAG, "Re-deploy from ERROR state — transition to RECEIVING"); serial_bridge_stop(); - binary_parser_reset(); + /* Parser resets itself on INIT — see note in SERIAL_BRIDGE handler. */ current_state = STATE_RECEIVING; led_set_pattern(LED_BLUE_BLINK); } else if (event == EVENT_BUTTON_RETRY) {