Package: pyscrlink
pyscrlinkPyscrlink is aScratch-linkfor Linux.
Scratch-link is a software module which connectsScratchto Bluetooth devices such asmicro:bit. However, as of October 2020, it only works
on Windows and MacOS, and Linux operating systems can not connect Scratch and
micro:bit.Pyscrlink allows you to connect Scratch and bluetooth devices with the Linux
OSes. It uses the Linux Bluetooth protocol stackBluezandbluepyto handle Bluetooth Low Energy
(BLE) connections. It has been reported that pyscrlink connects Scratch 3.0 with
micro:bit, LEGO WeDo, LEGO Boost and toio.Until version v0.2.5, pyscrlink supported Bluetooth Classic protocol usingpybluez. Unfortunately, pybluez is not
well maintained and caused technical troubles. Then Bluetooth Classic protocol
support is dropped from pyscrlink. This means that LEGO Mindstorm EV3 can not
be connected with pyscrlink. Bluetooth Classic support is the improvement
opportunity of pyscrlink.To use websockets, pyscrlink requires python version 3.6 or later. If your
system has python older than version 3.6, install newer version. If your
system has python 3 explicit command names python3 and pip3, use them in the
steps below.Pyscrlink was launched in 2019 as "bluepy-scratch-link". This was a small task
dedicated to micro:bit and bluepy for BLE connection. After many contributions,
it expanded coverage to pybluez with other devices for Bluetooth connectivity.
It was misleading that the name "bluepy-scratch-link" indicates that it depends
only on bluepy. As of October 2020, name of the project has been changed from
"bluepy-scratch-link" to "pyscrlink" to avoid confusion.Confirmed EnvironmentsThe instructions below was confirmed with following devices and distros.
Trial with other distros and feed-backs will be appreciated.Pyscrlink was confirmed with following devices, Linux distros and browsers.Devices:micro:bitLinux distros:Arch LinuxBrowsers:FirefoxChromiumIt was reported that pyscrlink (former bluepy-scratch-link) working with
following devices and Linux distros.Devices:LEGO WeDo by @zhaowe, @KingBBQLEGO Boost and compatible devices by @laurentchar, @miguev, @jacquesdt, @n3stormtoio by @shimodashLinux distros:Raspbian by @chrisglencrossUbuntu 16.04 @jacquesdtUbuntu Studio 20.04 @miguevDebian 11 @n3stormInstallationPrepare Bluetooth/BLE controller.Confirm that your Linux PC has a Bluetooth controller with BLE support.
Bluetooth 4.0 controller supports BLE. If your PC does not have it, need
to plug USB Bluetooth 4.0 adapter.Note: BLED112 USB dongle with Bluegiga BGAPI is not supported.Install required packages.Ubuntu
$sudoaptinstallbluezlibbluetooth-devlibnss3-toolslibcap2-binlibglib2.0-dev
Arch
$sudopacman-Sbluezbluez-utilsnsslibcapInstall python modules.$pipinstallpyscrlink
Orifyoursystemhaspython3command,
$pip3installpyscrlinkSet bluepy-helper capability.$ bluepy_helper_cap
Set capacbility 'cap_net_raw,cap_net_admin' to /usr/lib/python3.8/site-packages/bluepy-1.3.0-py3.8.egg/bluepy/bluepy-helperThe command above requires super user privilege. It may request to input
super user password.For micro:bit, install Scratch-link hex on your device.Download and unzip themicro:bit Scratch Hex file.Flash the micro:bit over USB with the Scratch Hex File, you will see the
five character name of the micro:bit scroll across the screen such as
'zo9ev'.UsageStart scratch-link python script.$scratch_linkIf your device is toio, add "-s 1" option to the scratch_link command. It
allows the toio Do Visual Programming to connect to toio automatically.Connect scratch to the target device such as micro:bit:Open FireFox or Chrome. (Make sure to run as the same user for scratch-link python script.)AccessScratch 3.0and create your project.Select the "Add Extension" button.Select the extension for your device (e.g., micro:bit) and follow the prompts to connect.Build your project with the extension blocks.In Case You Fail to ConnectIf Scratch says "Make sure you have Scratch Link installed" but you are sure
that scratch-link python script is running, check that Firefox or Chrome
allows local server certificate.Open Firefox or Chrome and accesshttps://device-manager.scratch.mit.edu:20110/. You will see a security risk warning.InFirefox: Click "Advanced" and click "Accept Risk and Continue".InChrome: type the special bypass keywordthisisunsafe.Immediately, you will see "Failed to open a WebSocket connection". This is expected.If device scan fails, check systemd bluetooth service status.systemctl status bluetooth.serviceIf the service is not working, refer guide of your distro to set it up.If the service is working, also check that /etc/bluetooth/main.conf sets AutoEnable=true.If device scan still fails, use -r option to retry device scan.
The command line below does device scan twice. Each scan takes 10 seconds.$ scratch_link -r 2It would be good to use -s option together to reduce each scan duration.
The command line below does 3 seconds device scan twice.$ scratch_link -r 2 -s 3If scratch_link.py says "failed to connect to BT device: [Errno 13] Permission denied",
make sure to pair the bluetooth device to your PC before connecting to Scratch.To connect to multiple devices at the same time, make all the target devices
ready for scan at the first device scan. This is important for toio. The toio
allows a single project to connect to two toio devices.When the second device was prepared after the first device was connected, device scan can not find the second device.To scan and find the second device, disconnect connections for the first device beforehand.Issus ReportingPlease file issues toGitHub issue tracker.ReleasesRelease 0.2.8Supported Microbit More v2Release 0.2.7Supported Snap Firefox and ChromiumAdded -r option to retry BLE scanRelease 0.2.6Removed Bluetooth Classic and LEGO Mindstorm EV3 supportRelease 0.2.5Fixed handling of multiple UUIDs for LEGO BoostRelease 0.2.4Added -s option to specify BLE scan durationImproved README.mdRelease 0.2.3Fixed eternal loop caused by hostname resolve failureRelease 0.2.2Supported multiple device connections for toioImproved session closure handlingRelease 0.2.1Added libglib to required package list in README.mdImproved setcap and getcap tool findingRelease 0.2.0Latency issue fix for BLE devices' write characteristicsRelease 0.1.0Initial release