tinygo-org / bluetooth

Cross-platform Bluetooth API for Go and TinyGo. Supports Linux, macOS, Windows, and bare metal using Nordic SoftDevice or HCI
https://tinygo.org
Other
761 stars 138 forks source link

Windows: AdvertisementPayload empty #302

Open universam1 opened 2 weeks ago

universam1 commented 2 weeks ago

Thank you @jagobagascon and others for the work. Unfortunately on Windows (11) the AdvertisementPayload or manufacturer data is empty. However, via Python I receive that data just fine, on the same machine.

Go results:

BTH01-A, Address: 38:1F:8D:6C:C8:EB, RSSI: -78, Data:&{{BTH01-A [] [] []}}
THB1-a, Address: 38:1F:8D:E9:87:2B, RSSI: -86, Data:&{{THB1-a [] [] []}}
BTH01-D, Address: 38:1F:8D:36:0D:CF, RSSI: -82, Data:&{{BTH01-D [] [] []}}
Amazfit GTS, Address: D3:52:C4:29:C6:C4, RSSI: -75, Data:&{{Amazfit GTS [] [] []}}
Go code: ```Go package main import ( "fmt" "strings" "tinygo.org/x/bluetooth" ) func main() { adapter := bluetooth.DefaultAdapter // Enable BLE adapter err := adapter.Enable() if err != nil { fmt.Printf("Error enabling adapter: %s\n", err) return } fmt.Println("Scanning for BLE devices...") err = adapter.Scan(func(adapter *bluetooth.Adapter, advertisement bluetooth.ScanResult) { // Check if the device name is available and starts with "BTH" if advertisement.LocalName() != "" && strings.Contains(advertisement.LocalName(), "T") { fmt.Printf("%s, Address: %s, RSSI: %d, Data:%v\n", advertisement.LocalName(), advertisement.Address.String(), advertisement.RSSI, advertisement.AdvertisementPayload, ) } }) if err != nil { fmt.Printf("Error during scan: %s\n", err) } } ```

Python results:

Found Device - Name: BTH01-D, Address: 38:1F:8D:36:0D:CF, RSSI: -77
Advertisement Data: AdvertisementData(local_name='BTH01-D', service_data={'0000fcd2-0000-1000-8000-00805f9b34fb': b'@\x00\xa1\x015\x02\xf0\x04\x039!\x0c\xe6\t'}, rssi=-77)
Found Device - Name: BTH01-A, Address: 38:1F:8D:6C:C8:EB, RSSI: -71
Advertisement Data: AdvertisementData(local_name='BTH01-A', service_data={'0000fcd2-0000-1000-8000-00805f9b34fb': b'@\x00\xe9\x013\x023\x08\x03S\x17\x0c\xd2\t'}, rssi=-71)
Python code: ```Python import asyncio from bleak import BleakScanner def print_advertisement(device, advertisement_data): # Check if the device name starts with "BTH" if device.name and device.name.startswith("BTH"): print(f"Found Device - Name: {device.name}, Address: {device.address}, RSSI: {device.rssi}") print("Advertisement Data:", advertisement_data) async def main(): # Start scanning with a callback to filter devices by name scanner = BleakScanner() scanner.register_detection_callback(print_advertisement) print("Scanning for BLE devices...") await scanner.start() # Scan for 30 seconds await asyncio.sleep(30000) await scanner.stop() print("Scan completed.") # Run the main function asyncio.run(main()) ```

Any idea what could be fixed?

universam1 commented 2 weeks ago

I see this from args.GetAdvertisement(); *advertisement.BluetoothLEAdvertisement {IUnknown: github.com/go-ole/go-ole.IUnknown {RawVTable: *(unreadable could not resolve interface type)}}