最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to change the Bluetooth name of the Raspberry pico 2W? - Stack Overflow

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

The 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
发布评论

评论列表(0)

  1. 暂无评论