Currently, I want to change the Name of the Pico 2W device displayed on the nRF Connect app. I am using Micro Pico in VsCode. I tried many things but the Name is always "N/A".
import bluetooth
from time import sleep
bluetooth.BLE().active(True)
ble = bluetooth.BLE()
device_name = 'PicoW_Device'
advertising_data = b'\x02\x01\x06\x03\x03\x0F\x18\x09' + bytes(device_name, 'utf-8')
ble.gap_advertise(100, adv_data=advertising_data)
print(f"The Name of the device is currently: {device_name}")
while True:
sleep(1)
I tried to change the name, but it always displayed "N/A"
Currently, I want to change the Name of the Pico 2W device displayed on the nRF Connect app. I am using Micro Pico in VsCode. I tried many things but the Name is always "N/A".
import bluetooth
from time import sleep
bluetooth.BLE().active(True)
ble = bluetooth.BLE()
device_name = 'PicoW_Device'
advertising_data = b'\x02\x01\x06\x03\x03\x0F\x18\x09' + bytes(device_name, 'utf-8')
ble.gap_advertise(100, adv_data=advertising_data)
print(f"The Name of the device is currently: {device_name}")
while True:
sleep(1)
I tried to change the name, but it always displayed "N/A"
Share Improve this question edited Mar 9 at 15:12 cards 5,0621 gold badge11 silver badges26 bronze badges asked Mar 9 at 7:52 5955_Pauli5955_Pauli 211 silver badge3 bronze badges 1- use triple `, to open and closed a block of code, then start adding your code in a new line – cards Commented Mar 9 at 15:14
1 Answer
Reset to default 1The problem is how you constructed the advertising_data
. Try this
device_name = 'PicoW_Device'
advertising_data = bytearray()
advertising_data += b'\x02\x01\x06' # Flags
advertising_data += bytearray([1 + len(device_name), 0x09]) # Name length and Complete Local Name AD type
advertising_data += device_name.encode('utf-8') # Ensures the name is encoded into bytes
ble.gap_advertise(100, adv_data=bytes(advertising_data)) # Converts the bytearray to bytes