kawasaki / pyscrlink Goto Github PK
View Code? Open in Web Editor NEWScratch-link for Linux written in python
License: BSD 3-Clause "New" or "Revised" License
Scratch-link for Linux written in python
License: BSD 3-Clause "New" or "Revised" License
Hello,
I would like to use bluepy-scratch-link (with scratux) with a BlueGiga "BLED112" (http://www.picaxe.com/BLED112-Bluetooth-USB-Dongle/) Bluethooth USB adapter.
This dongle works with the "pygatt" library (examples found in the "pylgbst" library - https://github.com/undera/pylgbst).
This "pygatt" library is currently not supported in blue-scratch-link.
Is it possible to add support for this dongle?
Thank you.
Best Regards,
Laurent
Hello and big thanks also from my side to try to help to support Scratch Link on Linux!
I am working with kids a lot with Lego WeDo 2.0 - the "education" version of boost. Up till now I have been forced to use Windows for working with the devices (as Lego only support Windows and Mac, same for Link) so I was delighted to find your project.
I was setting everything up according to the docs (I hope I didn't miss anything) and thought I would give it a try.
When I do, I get this error:
$ ~/bluepy-scratch-link$ sudo btmgmt power on
hci0 Set Powered complete, settings: powered connectable discoverable bondable ssp br/edr le secure-conn
$ ~/bluepy-scratch-link$ sudo btmgmt le on
hci0 Set Low Energy complete, settings: powered connectable discoverable bondable ssp br/edr le secure-conn
$ ~/bluepy-scratch-link$ sudo python3 ./scratch_link.py
Started scratch-link
Start session for web socket path: /scratch/ble
Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
Can not scan BLE devices. Check BLE controller.
I tried to connect directly via Gnome with the BT-LE device, which works fine. So I guess the hardware should support BLE.
I am using Ubuntu 20.04
Any help is appreciated!
thanks
Gregor
Hello,
the device search stops immediately so I can't find my wedo 2.0 device. The scratch-link is resetting session immediately after TLS Hello.
Installed as root:
1)
apt install bluez libbluetooth-dev libnss3-tools libcap2-bin python3-pip libglib2.0-dev python3-bluez python3-websockets
pyscrlink-0.2.6 with bluepy, and older version later too (below):
Requirement already satisfied: websockets in /usr/lib/python3/dist-packages (from pyscrlink==0.2.5) (9.1)
Requirement already satisfied: pyOpenSSL in /usr/lib/python3/dist-packages (from pyscrlink==0.2.5) (21.0.0)
Requirement already satisfied: pybluez in /usr/lib/python3/dist-packages (from pyscrlink==0.2.5) (0.23)
Requirement already satisfied: bluepy in /usr/local/lib/python3.10/dist-packages (from pyscrlink==0.2.5) (1.3.0)
Installing collected packages: pyscrlink
Successfully installed pyscrlink-0.2.5
set rights
$ bluepy_helper_cap
Set capacbility 'cap_net_raw,cap_net_admin' to /usr/local/lib/python3.10/dist-packages/bluepy/bluepy-helper
and verified
sudo getcap /usr/local/lib/python3.10/dist-packages/bluepy/bluepy-helper
/usr/local/lib/python3.10/dist-packages/bluepy/bluepy-helper cap_net_admin,cap_net_raw=eip
step 2 has been tested also as user, so both pyscrlink and bluepy were stored in home dir, ...same issue
$ python3 ./.local/lib/python3.10/site-packages/pyscrlink/bluepy_helper_cap.py
Set capacbility 'cap_net_raw,cap_net_admin' to /home/user/.local/lib/python3.10/site-packages/bluepy/bluepy-helper
The symptoms:
Thanks for your ideas
Hi,
I developing a firmware and a Scratch 3 extension to make control of Silabs' Thunderboard Sense 2 (BRD4166A) available from Scratch.
I mostly mimic the Micro:bit extension and implemented the firmware based on what I've found in the extension's source code (since I did not find the Micro:bit's firmware code anywhere, it seems only the binary is available).
Te issue is the following: when I click on a block in Scratch which sends a command to the device, there is a big delay between the click and the actual status change on the device.
As I checked, scratch_link.py receives the command quickly (in a millisecond range). The TB Sense 2 device's response also fast - I've tried this directly from Python.
So, it seems, scratch_link.py is the layer which adds the delay. it is in the ~second range (around 0.5s).
The other direction is OK, so reading buttons and tilt values does not suffer from this delay.
Could you please take a look on scratch_link.py and check what causes this delay and whether there is any way to shorten this delay?
Thx!
Edit:
Meanwhile I've figured out that the issue is caused by calling _get_characteristic()
every time Scratch wants to write anything to the device:
elif self.status == self.CONNECTED and method == 'write':
logger.debug("handle write request")
service_id = params['serviceId']
chara_id = params['characteristicId']
c = self._get_characteristic(chara_id)
if not c or c.uuid != UUID(chara_id):
logger.error(f"Failed to get characteristic {chara_id}")
self.status = self.DONE
else:
Wouldn't it be possible to cache the c
value or directly write the characteristic instead of getting the handle from the device?
/sza2
I have successfully connect a Lego WeDo 2.0 hub on my laptop (Ubuntu 20.04) using pyscrlink and tested it with Scratch 3.
I also tried to connect Raspberry Pi 4 with the same hub. The WeDo hub connected and after a few seconds disconnected.
I'm getting the following error message:
pi@raspberrypi:~ $ /home/pi/.local/bin/scratch_link
2021-01-21 19:37:08,798 FireFox NSS DB not found. Do not add certificate.
2021-01-21 19:37:08,851 Certificate is ready for Chrome
2021-01-21 19:37:09,186 Started scratch-link
2021-01-21 19:37:26,914 Start session for web socket path: /scratch/ble
2021-01-21 19:37:50,445 connected to the BLE peripheral: LPF2 Smart Hub 2 I/O
2021-01-21 19:37:54,885 Failure in session for web socket path: /scratch/ble
2021-01-21 19:37:54,885 Device disconnected
Any idea what's wrong?
Hello,
I have been trying to use Lego WeDo 2.0 with ZorinOS.
After installation, then running scratch_link, I am able to make connection once using either Firefox and Opera (uses Chrominum engine on Linux?)
Connection is then attempted with Scratch via Browser
I have then tested the connection by running the motor, which works.
After a minute or two of inactivity the device stops responding, despite appearing to still being connected.
$ scratch_link
2023-03-31 21:47:25,754 Certificate is ready in FireFox NSS DB: /home/myuser/.mozilla/firefox/e26s94rt.default-release
2023-03-31 21:47:25,766 Certificate is ready in Chrome NSS DB: /home/myuser/.pki/nssdb
2023-03-31 21:47:25,795 Started scratch-link
2023-03-31 21:47:32,026 Start session for web socket path: /scratch/ble
2023-03-31 21:47:42,427 connected to the BLE peripheral: Epicman
The device still thinks it is connected, but no response, not recoverable without logout / login or restart. I don't but know how to safely stop scratch_link, so have resorted to CTRL + C, but then this causes another issue when attempting to restart scratch_link
I've followed the steps in Readme, but I'm getting :
$ sudo python3 ./scratch_link.py
File "./scratch_link.py", line 42
logger.debug(f"request: {req}")
^
SyntaxError: invalid syntax
Any idea what is wrong? How can I help troubleshoot?
I'm trying connecting wedo 2.0 but have this error:
2024-04-14 14:22:35,923 Started scratch-link
2024-04-14 14:23:20,919 Start session for web socket path: /scratch/ble
2024-04-14 14:23:21,039 Can not scan BLE devices. Check BLE controller.
I started bluepy_helper_cap, I tried "hciconfig hci0 down" and "hciconfig hci0 up", I tried connecting the device with the OS BT pairing first (it does connect), I tried the dev version, but nothing
Can anybody suggest a solution ?
I got this when running with -d
Failed to execute management command 'le on' (code: 20, error: Permission Denied)
but can't run scratch_link with sudo. How do I give correct permissions ?
Hi! I'm trying to make it work with Scratux but it throws the following error when I press the "Try again" button:
Start session for web socket path: /scratch/ble
Failure in session for web socket path: /scratch/ble
code = 1005 (no status code [internal]), no reason
It looks like Scratux is able to connect but then something goes wrong. Any idea about what might be wrong?
I think a way of allowing a local server certificate in Google Chrome is to type the bypass sequence "thisisunsafe" in https://device-manager.scratch.mit.edu:20110/. This should be required only the first time to access.
Hello,
I have a problem to establish a stable connection to lego boost module.
My set-up:
Lego Boost
+
NUC PC D34010WYK with dualboot ubuntu 20.4 and win 10.
Under Win10 I have installed scratch and also scratch link. There I could get connected stable to lego boost and from scratch drive all motors and also optical interface on lego boost.
Under Ubuntu I have installed scratux and also scratch link (as advised on https://pypi.org/project/pyscrlink/).
I can not say if scratux over scratch link is working at all, as my problem starts at very beginning.
When pairing in bluetooth, I get it on, but in a few seconds later is once again off and the lego boost auto-switches off.
Below the output from terminal while trying to connect. And also the output from hci.
Please help me, I can not find the solution by myself.
home@ubuntu:~$ bluetoothctl
Agent registered
[bluetooth]# pair 00:16:53:A5:14:EC
Attempting to pair with 00:16:53:A5:14:EC
[CHG] Device 00:16:53:A5:14:EC Connected: yes
[CHG] Device 00:16:53:A5:14:EC ServicesResolved: yes
[CHG] Device 00:16:53:A5:14:EC Paired: yes
Pairing successful
[CHG] Device 00:16:53:A5:14:EC ServicesResolved: no
[CHG] Device 00:16:53:A5:14:EC Paired: no
[CHG] Device 00:16:53:A5:14:EC Connected: no
[CHG] Controller D8:FC:93:70:00:B6 Discoverable: no
[bluetooth]#
home@ubuntu: hciconfig -a
hci0: Type: Primary Bus: USB
BD Address: D8:FC:93:70:00:B6 ACL MTU: 1021:5 SCO MTU: 96:6
UP RUNNING PSCAN
RX bytes:2592 acl:30 sco:0 events:163 errors:0
TX bytes:6262 acl:26 sco:0 commands:124 errors:0
Features: 0xff 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF
Link mode: SLAVE ACCEPT
Name: 'pepuntu'
Class: 0x1c0104
Service Classes: Rendering, Capturing, Object Transfer
Device Class: Computer, Desktop workstation
HCI Version: 4.0 (0x6) Revision: 0xe00
LMP Version: 4.0 (0x6) Subversion: 0xe00
Manufacturer: Intel Corp. (2)
Hello! First of all, thanks for this project. 😄
I had a little trouble getting it to work at first and I couldn't figure out why the browser was part of the process. It eventually dawned on me that most people on Linux will be using Scratch 3 through the browser. I had downloaded the Electron Linux binary zip and extracted the Scratch 3 resources directory from the Windows installer. Try it if you haven't, it's dead easy and it works really well.
The quick and dirty way to make the desktop app work is to pass the --ignore-certificate-errors
option to the electron
binary. That's quite nasty though and I thought I could do better.
If we're shooting for a truly trusted certificate here then we need a longer expiry time. Let's say 10 years, so that's -days 3650
.
Rather than use names like localhost
and scratch-device-manager
, we need the name to match what's actually being requested so use device-manager.scratch.mit.edu
everywhere.
The -subj
option can be dropped if you set prompt = no
in the config and then you only need to specify the CN once.
Was the keyUsage=digitalSignature\nextendedKeyUsage=serverAuth
part added for any particular reason? I found that OpenSSL fails to trust the certificate with this in place. I didn't test whether it impacts NSS (used by Firefox, Chrome, Electron) in the end but it works fine without.
The printf
bit looks a bit clunky. We can use a here string instead like this:
-config /dev/stdin <<< $'[dn]\nCN=device-manager.scratch.mit.edu\n[req]\nprompt = no\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:device-manager.scratch.mit.edu'
I have no idea what the openssl pkcs12
part is supposed to be for. scratch-device-manager.pfx
doesn't appear to be used for anything and I got this working without it.
Similarly, the grep | tr
part is bizarre. cat
will do the same job as grep -h ^
and OpenSSL doesn't write Windows-style line endings so the tr
isn't needed. This could simply be:
cat scratch-device-manager.cer scratch-device-manager.key > scratch-device-manager.pem
Alternatively, why not just skip that step entirely and have Python read the certificate and key from separate files like this?
cert = pathlib.Path(__file__).with_name("scratch-device-manager.key")
key = pathlib.Path(__file__).with_name("scratch-device-manager.cer")
ssl_context.load_cert_chain(cert, key)
So to sum up, the one and only command you need for generating the key and certificate is:
openssl req -x509 -out scratch-device-manager.cer -keyout scratch-device-manager.key -newkey rsa:2048 -nodes -sha256 -days 3650 -extensions EXT -config /dev/stdin <<< $'[dn]\nCN=device-manager.scratch.mit.edu\n[req]\nprompt = no\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:device-manager.scratch.mit.edu'
Getting regular browsers to trust scratch-device-manager.cer
is easy enough. Firefox, Chrome, and friends allow you to import trusted certificates through the UI but what about the desktop app? By default, Electron uses the same user-wide trust store as Chrome in ~/.pki/nssdb
so if you import it into Chrome then Electron will see it too. What if you don't have Chrome? You can use the certutil
tool from NSS to do it from the command line.
certutil -A -d sql:~/.pki/nssdb -n "Scratch Device Manager" -t CT,, -i scratch-device-manager.crt
So hopefully we can stop telling users to do thisisunsafe
and the like now. There is a way to get Firefox, Chrome, and Electron all to use the same system-wide trust store. This could be useful for school environments but it's a little outside the scope of these instructions. Ask me if you're interested.
Hi kawasaki-san
I found the issue with playing toio.
I put io on playmat to use absolutely position.
BLE session disconnected was occurred.
I attached log file scratch_link with -d option.
log.txt
disconnect may be occurred around line 83705.
Hi kawasaki,
I'm having trouble trying to link my EV3 to Scratch in Firefox on my Ubuntu desktop. Everything works fine but running scan the terminal indicates the following error
antoine@aldebaran:~$ scratch_link
2022-07-09 15:52:49,216 Certificate is ready in FireFox NSS DB: /home/antoine/.mozilla/firefox/weuf2nuw.default
2022-07-09 15:52:49,222 Certificate is ready in FireFox NSS DB: /home/antoine/.mozilla/firefox/weuf2nuw.default
2022-07-09 15:52:49,323 Certificate is ready for Chrome
2022-07-09 15:52:49,345 Started scratch-link
2022-07-09 15:52:57,703 Start session for web socket path: /scratch/bt
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/home/antoine/.local/lib/python3.10/site-packages/pyscrlink/scratch_link.py", line 212, in run
self.discover()
File "/home/antoine/.local/lib/python3.10/site-packages/pyscrlink/scratch_link.py", line 189, in discover
discoverer.find_devices(lookup_names=True)
File "/home/antoine/.local/lib/python3.10/site-packages/bluetooth/bluez.py", line 434, in find_devices
_bt.hci_filter_all_events (flt)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 4: invalid start byte
Any idea ?
Best regards,
Antoine
I am trying to connect to LEGO boost from Ubuntu/Firefox/Scratch via a BLE dongle using pyscrlink. Installation (following the instructions at https://github.com/kawasaki/pyscrlink) works fine. But trying to connect from Scratch, as described in the instructions, fails, the LEGO boost extension saying "no devices found". Doing so, scratch_link -d outputs the following:
Print debug messages
2023-02-25 15:52:14,387 set scan_seconds: 10.0
2023-02-25 15:52:14,412 Certificate is ready in FireFox NSS DB: /home/ratschan/.mozilla/firefox/wx5xyc5d.default-release
2023-02-25 15:52:15,271 Certificate is ready in FireFox NSS DB: /home/ratschan/.mozilla/firefox/dj0c5tt0.default
2023-02-25 15:52:15,301 Certificate is ready for Chrome
2023-02-25 15:52:15,356 Started scratch-link
2023-02-25 15:54:57,652 Start session for web socket path: /scratch/ble
2023-02-25 15:54:57,652 start session handler
2023-02-25 15:54:57,652 start recv_request
2023-02-25 15:54:57,754 start recv_request
2023-02-25 15:54:57,754 request: {"jsonrpc":"2.0","method":"discover","params":{"filters":[{"services":["00001623-1212-efde-1623-785feabcd123"],"manufacturerData":{"919":{"dataPrefix":[0,64],"mask":[0,255]}}}],"optionalServices":[]},"id":0}
2023-02-25 15:54:57,754 handle request to BLE device
2023-02-25 15:54:57,754 discover
2023-02-25 15:54:57,754 {'filters': [{'services': ['00001623-1212-efde-1623-785feabcd123'], 'manufacturerData': {'919': {'dataPrefix': [0, 64], 'mask': [0, 255]}}}], 'optionalServices': []}
2023-02-25 15:54:57,763 start BLE scan: 10.0 seconds
2023-02-25 15:55:07,788 Failure in session for web socket path: /scratch/ble
2023-02-25 15:55:07,788 BTLEDisconnectError: Device disconnected
I also tried to follow the steps "at In Case You Fail to Connect" but could not really make sense of the instructions. Opening "https://device-manager.scratch.mit.edu:20110/" in the browser, I get "Failed to open a WebSocket connection: invalid Connection header: keep-alive. You cannot access a WebSocket server directly with a browser. You need a WebSocket client.". But the instructions say "This is expected". Now I do not understand what to conclude from this ...
Hi @kawasaki,
I have got a LEGO HUB from the LEGO Mindstorms robot inventor set. I am not sure if it should connect aswell using the scratch_link
script. Is it compatible with LEGO HUB?
I managed to pair the LEGO HUB using bluetoothctl:
pi@raspberrypi:~ $ bluetoothctl
Agent registered
[bluetooth]# devices
Device 38:0B:3C:AD:54:5F LEGO Hub 38:0B:3C:AD:54:5F
Output from scratch_link:
pi@raspberrypi:~ $ /home/pi/.local/bin/scratch_link
2021-01-03 15:34:12,556 FireFox NSS DB not found. Do not add certificate.
2021-01-03 15:34:12,616 Certificate is ready for Chrome
2021-01-03 15:34:12,659 Started scratch-link
2021-01-03 15:34:17,185 Start session for web socket path: /scratch/bt
But Scratch is not finding the device. ("No devices found").
Is the LEGO HUB equal / compatible to LEGO MINDSTORMS EV3?
Thanks for your support :-)
Best regards
Andy
Dear Kawasaki,
I found your bluepy-scratch-link project and got it up and running folowing your README. My goal is to control the Lego Boost robot from scratch 3.
I found one very small issue at line 198 (del(self))
close(self) did not work for me, I chaged it to self.close() and it works.
Then, connecting from Chrom+scratch works fine.
Next step was that in function matches(self,dev,filters) the conversion from string s to type UUID dit not work when trying to cast to int() first. so I changed "given_uuid = UUID(int(s))" to just be "given_uuid = UUID(s)". works.
(btw: I can create a pull request later, if required).
Can you try to confirm these bugs and check if you micro:bit works with my fixes as well?
Now the next big thing:
Scratch requests a service with UUID 00001623-1212-efde-1623-785feabcd123 nad if I sniff to the boost device using gatttool, I can see that it advertises exactly this ID. But so far I have no clue how to make use of this.
Last action I can observe is, that the line "service_class_uuid = dev.getValueText(0x3)" results in NONE and the next sanity check bailes out. So either dev is not filled properly, or the access by getValueText() is not robust to find the right string.
Can you help me adapting your script to Lego boost? I can supply you with scans and details, work on the code and test it.
best,
friso
2021-11-13 16:40:55,134 Start session for web socket path: /scratch/ble
2021-11-13 16:40:55,135 start session handler
2021-11-13 16:40:55,135 start recv_request
2021-11-13 16:40:55,237 start recv_request
2021-11-13 16:40:55,239 request: {"jsonrpc":"2.0","method":"discover","params":{"filters":[{"services":["00001623-1212-efde-1623-785feabcd123"]}],"optionalServices":[]},"id":0}
2021-11-13 16:40:55,239 handle request to BLE device
2021-11-13 16:40:55,239 discover
2021-11-13 16:40:55,239 {'filters': [{'services': ['00001623-1212-efde-1623-785feabcd123']}], 'optionalServices': []}
2021-11-13 16:40:55,246 start BLE scan: 5.0 seconds
2021-11-13 16:41:00,510 in matches 79:09:e5:82:11:7f [{'services': ['00001623-1212-efde-1623-785feabcd123']}]
2021-11-13 16:41:00,511 service to check: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,511 given: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,511 in matches 62:68:79:c3:db:3e [{'services': ['00001623-1212-efde-1623-785feabcd123']}]
2021-11-13 16:41:00,511 service to check: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,511 given: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,511 in matches b8:7c:6f:43:2d:af [{'services': ['00001623-1212-efde-1623-785feabcd123']}]
2021-11-13 16:41:00,512 service to check: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,512 given: 00001623-1212-efde-1623-785feabcd123
2021-11-13 16:41:00,512 adtype complete 16b
2021-11-13 16:41:00,513 Failure in session for web socket path: /scratch/ble
2021-11-13 16:41:00,513 Error: Non-hexadecimal digit found
device: LPF2 Smart Hub 2 I/O
scratch-link output:
BLE service not found: [{'services': ['00001523-1212-efde-1523-785feabcd123']}]. Check BLE device.
While I run it with -d, the output is
adtype 128b: None
adtype 16b: None
I add code in scratch_link.py as below:
def matches(self, dev, filters):
"""
Check if the found BLE device mathces the filters Scracth specifies.
"""
logger.debug(f"in matches {dev} {filters}")
dev_data = dev.getScanData()
logger.debug(f"dev data: {dev_data}")
and run it with -d. I see the service value is in the Incomplete List of 128-bit Service Class UUIDs. So, I add codes as below
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_128B)
logger.debug(f"adtype 128b: {service_class_uuid}")
if not service_class_uuid:
service_class_uuid = dev.getValueText(self.ADTYPE_INCOMP_128B)
logger.debug(f"adtype incomp 128b: {service_class_uuid}")
if not service_class_uuid:
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_16B)
logger.debug(f"adtype 16b: {service_class_uuid}")
if not service_class_uuid:
continue
It works! The set-color command sended from scratch run in the wedo2 controller perfectly.
In issue #4, @miguev pointed out that sudo command is not handy for young children. I open this issue to think about this challenge.
For young children to use this without depending on adults, it is more convenient to make it work without using sudo with this one-time setup:
$ sudo apt-get install libcap2-bin
$ cd /usr/local/lib/python3.8/dist-packages/bluepy/
$ sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper
$ /opt/bluepy-scratch-link/scratch_link.py
I think this would be good to add to the README.md ─ without it, scratch_link.py fails to enable the low energy mode:
Failed to execute management command 'le on' (code: 20, error: Permission Denied)
I think the URL don't work anymore : https://device-manager.scratch.mit.edu:20110
Have you got some idea ?
Thierry
Hello,
I'm getting the following error when i press the "Start Searching" button in Scratch 3 with pyscrlink running on Ubuntu 22.04:
[10348:0306/122147.012576:ERROR:ssl_client_socket_impl.cc(981)] handshake failed; returned -1, SSL error code 1, net_error -101
In the terminal window running pyscrlink i get no error messages:
$ /usr/local/bin/scratch_link -d
Print debug messages
2023-03-06 12:21:07,006 set scan_seconds: 10.0
2023-03-06 12:21:07,025 Certificate is ready in FireFox NSS DB: /home/administrator/.mozilla/firefox/qj7kn4vq.default-release
2023-03-06 12:21:07,036 Certificate is ready for Chrome
2023-03-06 12:21:07,078 Started scratch-link
I have the following packages installed on my system:
sudo apt install bluez libbluetooth-dev libnss3-tools libcap2-bin python3-pip libglib2.0-dev python3-bluez python3-websockets
sudo pip3 install pyscrlink
and i have run the command:
/usr/local/bin/bluepy_helper_cap
First of all, thanks for this project to allow using Scratch with Lego hardware under Linux. Unfortunately i have an issue connecting to a Boost device.
Ubuntu 21.10
pyscrlink pip3 package version 0.2.4
Firefox 94.0
Lego Boost
Steps I did:
bluez libbluetooth-dev libnss3-tools libcap2-bin libglib2.0-dev
pyscrlink
with pip3 install pyscrlink
bluepy_helper_cap
device-manager.scratch.mit.edu
as an alias for 127.0.0.1
in /etc/hosts
scratch_link
https://device-manager.scratch.mit.edu:20110
with Firefox and add security exceptionscratch_link
bluetoothctl
to pair with Boost hardware (Pairing successful
reported and hardware LED turns from flashing white to permanent blue)scratch_link -d
Expected result
Actual result
wss://device-manager.scratch.mit.edu:20110/scratch/ble
with JSON payload response
{"jsonrpc": "2.0", "error": {"message": "Can not scan BLE devices. Check BLE controller."}, "result": null, "id": 0}
scratch_link -d
console output:
2021-11-07 16:54:19,006 set scan_seconds: 10.0
2021-11-07 16:54:19,014 Certificate is ready in FireFox NSS DB: /home/athlon/.mozilla/firefox/[...]
2021-11-07 16:54:19,019 Certificate is ready in FireFox NSS DB: /home/athlon/.mozilla/firefox/[...]
2021-11-07 16:54:19,062 Certificate is ready for Chrome
2021-11-07 16:54:19,073 Started scratch-link
2021-11-07 16:54:49,592 Start session for web socket path: /scratch/ble
2021-11-07 16:54:49,592 start session handler
2021-11-07 16:54:49,592 start recv_request
2021-11-07 16:54:49,694 start recv_request
2021-11-07 16:54:49,694 request: {"jsonrpc":"2.0","method":"discover","params":{"filters":[{"services":["00001623-1212-efde-1623-785feabcd123"],"manufacturerData":{"919":{"dataPrefix":[0,64],"mask":[0,255]}}}],"optionalServices":[]},"id":0}
2021-11-07 16:54:49,694 handle request to BLE device
2021-11-07 16:54:49,694 discover
2021-11-07 16:54:49,694 {'filters': [{'services': ['00001623-1212-efde-1623-785feabcd123'], 'manufacturerData': {'919': {'dataPrefix': [0, 64], 'mask': [0, 255]}}}], 'optionalServices': []}
2021-11-07 16:54:49,696 start BLE scan: 10.0 seconds
2021-11-07 16:54:49,698 BLE iface #0: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
2021-11-07 16:54:49,699 start BLE scan: 10.0 seconds
2021-11-07 16:54:49,701 BLE iface #1: Failed to execute management command 'le on' (code: 17, error: Invalid Index)
2021-11-07 16:54:49,702 start BLE scan: 10.0 seconds
2021-11-07 16:54:49,704 BLE iface #2: Failed to execute management command 'le on' (code: 17, error: Invalid Index)
2021-11-07 16:54:49,704 Can not scan BLE devices. Check BLE controller.
2021-11-07 16:54:49,704 loop in BLE thread
2021-11-07 16:54:49,704 {'jsonrpc': '2.0', 'error': {'message': 'Can not scan BLE devices. Check BLE controller.'}, 'result': None}
2021-11-07 16:54:49,704 send out found devices
2021-11-07 16:54:49,704 response: {"jsonrpc": "2.0", "error": {"message": "Can not scan BLE devices. Check BLE controller."}, "result": null, "id": 0}
2021-11-07 16:54:49,704 end_request of BLESession
2021-11-07 16:54:49,705 start to notify
2021-11-07 16:54:49,705 in handle loop
2021-11-07 16:54:49,705 start recv_request
2021-11-07 16:54:49,705 start to notify
2021-11-07 16:54:49,705 in handle loop
[...]
In order to use btmgmt (on Arch at least) the bluez-tools package is required. It would be helpful to add this to the readme.
@shimodash shared a pyscrlink issue through off-line communication today. I record the issue here.
The BLE device toio has its own Scratch enhancement for visual programming tool, and Scratch-link is required to connect the toio devices and the programming tool. The unique point of the Scratch for toio is that a single Scratch project can connect to two toio devices to allow users to be more creative. The Scratch-link on MacOS and Windows have no problem to support connections to the two toios. However, pyscrlink cannot support it. It is ok to connect the first single toio. When the user started to search the second toio for connection, the connection to the first toio gets lost, and pyscrlink shows the message "Disconnected".
Hi,
I installed your 'pyscrlink' on Linux Mint. It works fine.
However when I checked in System Monitor, I found out it can use non-negligeable CPU ressource, it can go to 10% and more. And it can reach up to 50% (and stay there) when I stop a Scratch program using my Micro:bit.
I wonder if there is any way to lower the cpu usage? Changing the priority does not help.
Hi,
Just heaving trying to have some fun with an ev3 and I realized that something is never gonna happen until it's changed...
pyscrlink/pyscrlink/scratch_link.py
Line 70 in 7511909
I cannot connect to EV3 as jsonres is always None due to handle_request always returning None.
pyscrlink/pyscrlink/scratch_link.py
Line 80 in 7511909
Log:
2023-01-20 11:04:04,499 start recv_request 2023-01-20 11:04:04,499 request: {"jsonrpc":"2.0","method":"discover","params":{"majorDeviceClass":8,"minorDeviceClass":1},"id":0} 2023-01-20 11:04:04,499 default handle_request: discover, {'majorDeviceClass': 8, 'minorDeviceClass': 1} 2023-01-20 11:04:04,499 Failure in session for web socket path: /scratch/bt
What should jsonres contain?
Thank you!
When starting scratch_link
on openSUSE, the program crashes and is immediately restarted with the message Restarting scratch-link...
, what causes an endless loop.
The core of this behavior is that the address device-manager.scratch.mit.edu
can't be resolved.
A workaround for this is to add following line to /etc/hosts
127.0.0.1 device-manager.scratch.mit.edu
Is there a chance to get pyscrlink for Debian 12 (Bookworm).
A lot of school installations were updated to Debian 12 during the last year but now the Scratch 3 hardware link does not work anymore.
Hello,
I have a hard time connecting to Intelino Smart Train.
martin@bono:~$ scratch_link
2021-12-24 21:06:48,682 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/qk78wey4.Default User
2021-12-24 21:06:48,689 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/qk78wey4.Default User
2021-12-24 21:06:48,703 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/qk78wey4.Default User/chrome_debugger_profile
2021-12-24 21:06:48,712 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/qb752b1e.ff75
2021-12-24 21:06:48,719 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/u16lwrru.default
2021-12-24 21:06:48,727 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/fq9mqhp8.Martin
2021-12-24 21:06:48,974 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/no8dwo1j.Default User
2021-12-24 21:06:48,983 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/jmegri7g.p1
2021-12-24 21:06:48,991 Certificate is ready in FireFox NSS DB: /home/martin/.mozilla/firefox/ya14x5g6.temp
2021-12-24 21:06:48,999 Certificate is ready for Chrome
2021-12-24 21:06:49,016 Started scratch-link
2021-12-24 21:06:56,467 Start session for web socket path: /scratch/ble
2021-12-24 21:07:06,878 Can not scan BLE devices. Check BLE controller.
martin@bono:~$ bluetoothctl
Agent registered
[CHG] Controller 40:74:E0:9F:B6:B2 Pairable: yes
[bluetooth]# devices
Device 00:A0:50:B6:45:0E intelino J-1
Device 50:81:D8:01:8A:13 Sony PLAYSTATION(R)3 Controller
Device 98:D3:31:FB:14:F7 HC-06
Device 30:21:03:00:04:85 Creative T100
Device 20:1B:88:14:AD:70 Mi True Wireless EBs Basic 2
Device 34:88:5D:3F:5D:38 Bluetooth Mouse M557
Device 00:1B:FB:C3:8C:64 Sony PLAYSTATION(R)3 Controller
Device 20:01:08:00:A9:32 Escape 220
Device 74:51:BA:ED:0C:A5 Mi Phone
[bluetooth]# connect 00:A0:50:B6:45:0E
Attempting to connect to 00:A0:50:B6:45:0E
[CHG] Device 00:A0:50:B6:45:0E Connected: yes
Connection successful
[NEW] Primary Service (Handle 0x8746)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000a
00001801-0000-1000-8000-00805f9b34fb
Generic Attribute Profile
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000a/char000b
00002a05-0000-1000-8000-00805f9b34fb
Service Changed
[NEW] Descriptor (Handle 0xf360)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000a/char000b/desc000d
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
[NEW] Primary Service (Handle 0x80f0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000e
0000180a-0000-1000-8000-00805f9b34fb
Device Information
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000e/char000f
00002a24-0000-1000-8000-00805f9b34fb
Model Number String
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000e/char0011
00002a25-0000-1000-8000-00805f9b34fb
Serial Number String
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service000e/char0013
00002a26-0000-1000-8000-00805f9b34fb
Firmware Revision String
[NEW] Primary Service (Handle 0x80f0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0015
0000180f-0000-1000-8000-00805f9b34fb
Battery Service
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0015/char0016
00002a19-0000-1000-8000-00805f9b34fb
Battery Level
[NEW] Descriptor (Handle 0x7360)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0015/char0016/desc0018
00002904-0000-1000-8000-00805f9b34fb
Characteristic Format
[NEW] Descriptor (Handle 0x7360)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0015/char0016/desc0019
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
[NEW] Primary Service (Handle 0x80f0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001a
00060000-f8ce-11e4-abf4-0002a5d5c51b
Vendor specific
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001a/char001b
00060001-f8ce-11e4-abf4-0002a5d5c51b
Vendor specific
[NEW] Descriptor (Handle 0x76a0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001a/char001b/desc001d
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
[NEW] Descriptor (Handle 0x76a0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001a/char001b/desc001e
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[NEW] Primary Service (Handle 0x80f0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001f
43dfd9e9-17e5-4860-803d-9df8999b0d7a
Vendor specific
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001f/char0020
40c540d0-344c-4d0d-a1da-9cc260b82d43
Vendor specific
[NEW] Descriptor (Handle 0x77a0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service001f/char0020/desc0022
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[NEW] Primary Service (Handle 0x80f0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0023
4dad4922-5c86-4ba7-a2e1-0f240537bd08
Vendor specific
[NEW] Characteristic (Handle 0x75eb)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0023/char0024
a4b80869-a84c-4160-a3e0-72fa58ff480e
Vendor specific
[NEW] Descriptor (Handle 0x7aa0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0023/char0024/desc0026
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
[NEW] Descriptor (Handle 0x7aa0)
/org/bluez/hci0/dev_00_A0_50_B6_45_0E/service0023/char0024/desc0027
00002901-0000-1000-8000-00805f9b34fb
Characteristic User Description
[CHG] Device 00:A0:50:B6:45:0E ServicesResolved: yes
Pairing doesn't work. Probably the train is not pairable.
[bluetooth]# pair 00:A0:50:B6:45:0E
Attempting to pair with 00:A0:50:B6:45:0E
[CHG] Device 00:A0:50:B6:45:0E Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device 00:A0:50:B6:45:0E Connected: no
Using https://scratch.intelino.com/
I can connect to the device
I've found your project while reading scratchfoundation/scratch-link#84
Unfortunately I'm not able to use or read your code unless it's licensed.
Please read https://choosealicense.com/ and select one for your project. If you want to help in integrating your solution into scratch-link (if possible), you should follow their choice found here: https://github.com/LLK/scratch-link/blob/develop/LICENSE
In issue #4, @miguev pointed out that some chore work is required to use bluepy-scratch-link by multiples users. Here I quote his comment.
It is also necessary for each user to have their own copy of bluepy-scratch-link and run ./gencert.sh in it, and keep ownership fo the bluepy-scratch-link directory.
I open this issue to think about it.
Hello,
thanks for you project. My kid loves playing with WeDo2.0 and your project keeps him being able to use it on linux. He used it on an older Linux Mint (originally installed around 2018-2019 i guess) until 1-2 weeks ago. I had the "bright" ideea to upgrade his system to latest Mint version, and now scratch_link doesn't seem to o anything.
When accessing https://scratch.mit.edu/ and trying to connect to WeDo the connection popup doesn't seem to spend any time searching for the actual device.
In the Firefox console I'm seeing this message:
Firefox can’t establish a connection to the server at ws://127.0.0.1:20111/scratch/ble.
Firefox can’t establish a connection to the server at wss://device-manager.scratch.mit.edu:20110/scratch/ble.
Manually connecting to https://device-manager.scratch.mit.edu:20110/scratch/ble returns
Secure Connection Failed
An error occurred during a connection to device-manager.scratch.mit.edu:20110. PR_END_OF_FILE_ERROR
Error code: PR_END_OF_FILE_ERROR
As far a I remember PR_END_OF_FILE_ERROR is returned when the https server closes the connection without communicating anything, and scratch_link doesn't seem to log anything regarding to the webserver activity, so i guess that something is wrong on the ws side.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.