Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: AdvertisementPayload empty #302

Open
universam1 opened this issue Nov 2, 2024 · 4 comments
Open

Windows: AdvertisementPayload empty #302

universam1 opened this issue Nov 2, 2024 · 4 comments
Labels

Comments

@universam1
Copy link

universam1 commented Nov 2, 2024

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:
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:
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
Copy link
Author

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

@deadprogram
Copy link
Member

@universam1
Copy link
Author

Thank you @deadprogram , so what makes Python succeed here?

@deadprogram
Copy link
Member

These comments are interesting here https://github.com/hbldh/bleak/blob/develop/bleak/backends/winrt/scanner.py#L126

Perhaps @jagobagascon can interpret this code to figure out how to parse this data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants