-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support for Intelino Smart Train #31
Comments
I replaced BTW the filter is |
Attaching output of |
GitHub issue #31 reported that Intelino Smart Train is not connected with pyscrlink. It also reported that getValueText(0x9) call for the device instead of getValueText(0x8) avoids the failure. This implies that the Intelino Smart Train does not report AdType 0x8 "Shortened local name" but it reports AdType 0x9 "Complete local name". To get local name of the BLE devices regardless AdType support status of those devices, introduce a helper function _getDevName(). It gets the AdType 0x9 "Complete local name" first. If it is not available, get AdType 0x8 "Shortened local name". Use this helper function at all places to get the device name. Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
Hi @zdila Thank you for sharing the issues. It is great that you found that dev.getValueText(0x09) make pyscrlink connect to Intelino Smart Train. I will improve the pyscrlink code to try out both dev.getValueText(0x09) and dev.getValueText(0x08. Regarding the disconnection, I checked the debug.log. Connection was established, and notification start was requested to the device, and some data write were made to the device. After that It looks like that the Scarch for Intelino Smart Train disconnects the connection to pyscrlink. Here I quote a part of debug.log. The line "scratch closed session" means that something is happening in the scratch side.
In the log, I did not find any notification message from the device. So my mere guess is that scratch for Intelino Smart Train timed out to wait for notifications from the device. At this moment, I can not think of further way to investigate this issue. I wanted to take a look in the code of scratch for Intelino Smart Train, but I can not find it on the net... |
Thanks for your reply. I've managed to create a dump of websocket communication from working scratch-link on MacOS. Will it help? It contains all messages from connecting to the train till manual disconnection. When connected, train sends many messages (probably its status, like current speed or what color did it just scan. |
WS dump when using pyscrlink: pyscrlink-ws-dump.json.gz |
It looks like pyscrlink is not receiving characteristics change (or not sending them via WS). I tried following steps using nRF Connect Android app:
then I started recording and saw many notifications on characteristic |
Meanwhile I've written Scratch Link for Linux and Intelino smart train in nodejs: https://github.com/zdila/intelino-smart-train-scratch-link-linux |
@zdila It's great that your wrote nodejs version of scratch-link :) I'm interested in your node js code. Is it working good for your device? If so, that's a good step forward. Thank you for sharing the wireshark and nRF Connect logs. They helped me to have the wider view. From the pyscrlink logs, pyscrlink received the write and the notification subscribe requests from Scratch and handled them. However, there is no notification from the device. My current guess is that notification subscribe handling by pyscrlink is not correct (there could be a possibility that layers below pyscrlink is not working correctly, but if your nodejs version is working good, this is not the case). Still I need some more time to think about the notification subscription handling. |
I have spent some time about BLE Characteristic and notification. And learned that CCCD (Client Characteristic Configuration Descriptor) is the key to enable notification. Current pyscrlink assumes that CCCD comes just after the Characteristic Value declaration, but the spec warns that we should not assumes such an order. If this assumption in pyscrlink is wrong for the Intelino Smart Train, it could be the cause of the no notification from the device. I made a commit 2d48932 to dev branch to avoid the assumption in pyscrlink. Now pyscrlink looks up the CCCD to enable notification. I wish this fix the issue with Intelino Smart Train. @zdila If you have time to afford, please try the dev branch tip. |
I tried the Yes, my Node.js version works fine with my Intelino train. |
@ZDlia Thank you for the quick update. It is my sorrow the problem is still there. At this moment, I have no further idea about the trouble cause. I will remove Intelino statements from the README of pyscrlink. |
Just a comment after looking into your node.js implementation. Oh, it uses DBus interface to communicate with bluetooth side. It's simple and looks stable. Hmm, that could be an option for pyscrlink future improvement. |
Yes. There are other Node.js bluetooth alternatives like https://github.com/noble/noble (seems to be multiplatform but I got errors installing it as it failed compiling some native code) or https://github.com/chrvadala/node-ble (also uses D-Bus but it hides for example API for setting BT scanning filter), but using D-Bus directly (https://github.com/dbusjs/node-dbus-next library) it wasn't difficult to utilize BLE on my own :-). BTW my scratch-link is also faster in finding a device for some reason (it finds it immediately if it is powered on, whereas for pyscrlink it takes couple of seconds). Also pyscrlink is using some loop for getting events which east CPU (in my case it eats 100% of a single core if it fails to connect). I think it is a problem of PyBluez design. |
Thank you. The bluetooth libraries situation in Node.js sounds similar as that in Python. There are multiple bluetooth and BLE support libraries. Some of them are old, and not so stable. I has been thinking which bluetooth/BLE library could be the better, but that D-Bus approach sounds the best, at this moment. Also thank you for sharing your experience on the device finding speed and CPU consumption. Unfortunately (or fortunately), I have not yet observed them. Will keep them in my mind. |
Hello, i'm using pyscrlink on Linux (Ubuntu 20.04) to connect WeDo 2.0 and EV3 devices. Is it possible to try the Node.js version? |
@markakis-sch I think it would be more suitable to discuss it at https://github.com/zdila/intelino-smart-train-scratch-link-linux/issues. Node.js version currently ignores bluetooth filter and is hardcoded with |
I have made https://github.com/zdila/scratch-link-ble-linux/ ready for other BLE devices, but had no chance to test it with anything but Intelino smart train. |
Yep it would be good to create an issue in scratch-link-ble-linux for the discussion. |
Oh, then bleak can be another choice, in place of bluepy. Bleak looks newer and more active than bluepy. Will think about it :) |
I confirm that finding a device (i used a WeDo 2.0) is much slower with pyscrlink than with scratch-link-ble-linux. |
Hello,
I have a hard time connecting to Intelino Smart Train.
Pairing doesn't work. Probably the train is not pairable.
Using https://scratch.intelino.com/
I can connect to the device
The text was updated successfully, but these errors were encountered: