Background:
I am trying to make an app that finds a type of BLE device by recognizing a pattern in its name.
In Python, I can do this:
import asyncio from bleak import BleakScanner async def main(): devices = await BleakScanner.discover() for d in devices: if re.match("^S[a-f\d]{16}[A-F]$", d.name): # This is the correct device! print(d) asyncio.run(main())
However, I understand that Monkey C does not support regex. So, I just tried searching for devices with a name that is 18 characters long, but I didn't get any hits.
I tried out jim_m_58's BleScan app, and I found that almost all of the devices my watch found had a device name that is null.
I used the python script above on my laptop to find the BLE address of the device I want the watch to connect to, and I changed the code in my app to look for the specific BLE address instead of the device name, and it connected. So, it looks like the watch is not picking up the BLE device's name, even though my phone and laptop both do. Why might this be? Is there another way to do this that would get device names reliably?
// THIS CODE DOES NOT WORK function onScanResults( scanResults ) { for( var result = scanResults.next(); result != null; result = scanResults.next() ) { var deviceName = device.getDeviceName(); if (deviceName && deviceName.length().equals(18)) { Ble.setScanState(Ble.SCAN_STATE_OFF); view.device = Ble.pairDevice(result); Ui.requestUpdate(); } } } // THIS CODE WORKS function onScanResults( scanResults ) { for( var result = scanResults.next(); result != null; result = scanResults.next() ) { if (result.hasAddress("SPECIFIC_DEVICE_BLE_ADDRESS")) { Ble.setScanState(Ble.SCAN_STATE_OFF); view.device = Ble.pairDevice(result); Ui.requestUpdate(); } } }
If it is relevant, I am trying to make an app that is able to connect to Tesla vehicles over BLE using this new documentation.
Summary:
The best way to identify my class of devices is by recognizing a pattern in their device name. However, the watch seems to always list the device name as null.
Is there a way to consistently get the device name from a scan?