intelino-code / intelino-trainlib-py

Python library (SDK) for interacting with the intelino smart train.
Other
11 stars 4 forks source link

initelino.scan never finds train, macOS #1

Open g12r opened 2 years ago

g12r commented 2 years ago

Any guidance on what to troubleshoot if scan never finds the train? I've made sure it's not connected via Bluetooth, connected to another device, power cycled pc and train. Repeated all of this multiple times, repeated python env setup as well. Train works fine no-screen mode, with the phone app as well.

Attempting this on a m1 MacBook, macOS 12.1, python 3.10.0. Did all of the venv/pip steps, no issues. Terminal will request permissions, so it has it. Tried running from cmd line and PyEnv. I don't seem to be getting any environment issues, no weird exceptions... it just never finds anything.

I tried a test with just Bleak and wasn't able to connect at that layer, but I wasn't able to get it to connect. I was using the guid that shows up in BlueSee as the address to connect, but it wasn't

With Bleak logging on, output is below.

grant@Max ~/Dropbox/Code/PyStuff/Train/intelino-trainlib-py git:(master*)
λ python3 -m intelino.scan                                                                                                                                 !663
2021-12-25 14:44:15,371 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: centralManagerDidUpdateState_
2021-12-25 14:44:15,371 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: Bluetooth powered on
2021-12-25 14:44:15,371 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: 'isScanning' changed
2021-12-25 14:44:18,375 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: 'isScanning' changed
Trains (0):

Others (0):
(.env) 

Tried to see if any different behavior via TrainScanner directly...

test2.py:

from intelino.trainlib import TrainScanner

train_list = TrainScanner(timeout=5).get_trains()
print("\nlen={0}, contents={1}".format(len(train_list), train_list))

Same results, nothing found.

grant@Max ~/Dropbox/Code/PyStuff/Train/intelino-trainlib-py git:(master*)
λ python3 test2.py                                                                                                                                         !667

2021-12-25 15:30:00,762 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: centralManagerDidUpdateState_
2021-12-25 15:30:00,763 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: Bluetooth powered on
2021-12-25 15:30:00,763 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: 'isScanning' changed
2021-12-25 15:30:05,767 bleak.backends.corebluetooth.CentralManagerDelegate DEBUG: 'isScanning' changed

len=0, contents=[]
(.env) 

Ultimately, it seems like there's a basic issue finding the train at any level. It's working and connecting via other BLE utlls.

petrusek commented 2 years ago

Hello, there are a few more things you could try.

The train filter itself is just a device name filter - based on the "intelino" prefix... so if that wouldn't work, it should still show up in the "Others" section.

I suggest poking a bit further with Bleak (as you already started), that should yield some results.

Btw. did Bleak scan find the train and you just wasn't able to connect?

If that is the case, we have a few more troubleshooting (raw) examples in our other repository (https://github.com/intelino-code/intelino-trainlib-async-py/tree/master/examples). The async library is a dependency of this non-async one.

If none of these raw / pure Bleak examples would work (especially if scanning doesn't show anything), there might be some lower-level issue with Bleak on the new M1 :-( ... as we haven't seen any issues on macs before.

guoruicodes commented 2 years ago

I'm curious if this was resolved? Did it repro on any other m1? I have an m1 to hand but it would be a bit of a faff to check if it repros ....

@petrusek maybe this commit fixed it? https://github.com/hbldh/bleak/pull/692 if I am scanning this correctly. looks like #692 went into the 0.14.x releases.

petrusek commented 2 years ago

Thanks for the info @guoruicodes Unfortunately we don't advertise any services. Custom (non-standard) services have long uuids and the length of advertisement packets is very limited. This https://github.com/hbldh/bleak/pull/753 shines a ray of hope for our case, we just need to wait for macOS 12.3 to come out of beta.