Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import asyncio
import base64
import json
import os
import struct
import time
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError
# ---------------------------------------------------------------------------
# DFU Configuration
# ---------------------------------------------------------------------------
DEVICE_ADDRESS = "D9:E1:E4:73:11:33" # Replace with your device's BLE address
FIRMWARE_FILE = "app_update.bin" # Firmware binary to upload
DEFAULT_CHUNK_SIZE = 200 # Reduced default chunk size
MAX_RETRIES = 3 # Number of retries for failed operations
# SMP Service and Characteristic UUIDs (MCUboot/Zephyr SMP over BLE)
SMP_SERVICE_UUID = "8D53DC1D-1DB7-4CD3-868B-8A527460AA84"
SMP_CHAR_UUID = "DA2E7828-FBCE-4E01-AE9E-261174997C48"
I am currently implementing BLE-based FOTA for the application core on an nRF5340 using MCUboot. I can successfully update the application core using the nRF Connect mobile app, but I am facing issues when attempting to perform the update via a Python script using Bleak.
Issue Details:
- I am able to establish a BLE connection and start the DFU process.
- The firmware upload appears to progress successfully, but after completion, the update does not take effect.
- The same firmware file updates successfully when using the nRF Connect mobile app.
- The device does not reboot into the new firmware after sending the reset command.
- I am not sure if the firmware confirmation step is being processed correctly.
My Setup:
- Hardware: nRF5340
- Bootloader: MCUboot
- BLE Library: Bleak (Python)
- Firmware Update Method: SMP over BLE
- MTU Size: Detected as 512 bytes
Python Script Overview:
- Scans for the BLE device and establishes a connection.
- Uploads the firmware in chunks using the SMP Image Upload command.
- Sends an SMP Image Confirm command.
- Sends a Reset command to reboot into the new firmware.
Observed Behavior:
- The firmware file is sent chunk by chunk, and I can see BLE notifications being received.
- After completing the upload, the device does not reboot into the new firmware.
- Manually rebooting the device does not seem to apply the update either.
- The same firmware file works perfectly when flashed using nRF Connect mobile.
I have attached my Python script below. Could you help me identify what might be going wrong? Are there any additional steps needed for proper firmware validation and activation?
Thanks in advance for your help!