Commit Graph

31 Commits

Author SHA1 Message Date
MDE
ba8eba4800 BLESession: Introduce notification queue
During bluepy-scratch-link handles requests from Scratch, it throws away
notifications from BLE devices. This loses those notifications.

Not to lose the notifications, introduce a queue to keep notifications
from BLE devices. Once request handling completes, flush the
notifications kept in the queue.
2020-05-16 18:24:26 +09:00
MDE
199b54f094 BLESession: Simplify lock and unlock statements using 'with" statement 2020-05-16 17:48:35 +09:00
MDE
9038ef0ce3 BLESession.setNotifications: Refactor out start/stopNotifications 2020-05-16 17:44:13 +09:00
MDE
a217df401b BLESession.handle_request: Support stopNotifications request 2020-05-16 17:39:11 +09:00
MDE
1d29943233 BLESession.handle_request: Support startNotifications request 2020-05-16 17:39:11 +09:00
MDE
e42869c93b BLESession.startNotifications: Refactor out to a function 2020-05-16 17:23:11 +09:00
Shin'ichiro Kawasaki
6fdc8dcbb3 BLESession.handle_request: Fix startNotification KeyError
The value 'startNotification' is optional for the "read" request.
However, bluepy-scratch-link expects Scratch always set the value in the
requests. This may cause KeyError.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-05-16 17:09:54 +09:00
Shin'ichiro Kawasaki
1ca2e910fb scratch_link.py: Add debug print option
In the GitHub issue "Scratux support #9", debug message log was required
for analysis. However, script edit by users was required to enable debug
print. This is not handy.

To avoid that the chore by users, add -d debug print option.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-05-01 12:55:03 +09:00
Shin'ichiro Kawasaki
8958594cf9 scratch_link.py: Enrich log information
In the GitHub issue "Scratux support #9", it was noticed that
bluepy-scratch-link is not so informative to tell what is happening.
Especially when BLE controllers or BLE devices are not available, no
information is printed.

Enrich log information so that users can tell what is happening easier.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-05-01 12:54:07 +09:00
Shin'ichiro Kawasaki
4da6b4714a README.md: Remove server certificate allowance step from usage guide
With previous commit, gencert.sh automatically add the certificate to
FireFox or Chrome using certutil command. Blupy-scratch-link users no
need to allow the certificate explicitly.

Also add NSS to the required package list to install, which includes the
certutil command.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-04-19 21:46:57 +09:00
Shin'ichiro Kawasaki
3a784edbd5 gencert.sh: Automate certificate addition to FireFox and Chrome
As of today, bluepy-scratch-link users need to do special action to allow
local server certificates. This is trouble some and James Le Cuirot
suggested to automate the action with certutil tools

To avoid the user action, check if NSS DB of FireFox or Chrome exists. If
NSS DBs exist, add the certificate to those DBs.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-04-19 21:46:57 +09:00
Shin'ichiro Kawasaki
8c42fc04b7 scratch_link.py, gencert.sh: Separate certification and private key
Now gencert.sh generates private key and certificate for the Secure WSS
server in a single file. This is not good to automate certification
addition to NSS databases. Generate them separately into two files and
initialize the Secure WSS server specifying them.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-04-18 17:48:28 +09:00
Shin'ichiro Kawasaki
f0bf6e1a6a README.md: Fix broken markdown format
To have new line after list items with numbers, the list item needs
period following empty line.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-04-11 17:03:12 +09:00
Shin'ichiro Kawasaki
f87a435f96 gencert.sh: Simplify certificate file generation commands
The command lines to generate certificate file for web server are
troublesome and their parameters confuse users. To clean up the steps per
James Le Cuirot suggestions, simplify openssl options and bash commands
in the generation script and README.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-04-11 17:01:08 +09:00
MDE
e3c60f8ff3 .gitignore: Added generated certificate files
Should be moved to a separate dir later
2020-04-11 16:58:32 +09:00
MDE
58c4959454 setup: Added script for cert generation
Copied commands from README.md without the unused
pkcs export
2020-04-11 16:58:12 +09:00
Shin'ichiro Kawasaki
e9dc711f83 Merge pull request #7 from ngammarano/patch-1
Update README.md, corrected bullet list display
2020-03-13 23:23:45 +09:00
ngammarano
0bab1bdd29 Update README.md, corrected bullet list display 2020-03-12 10:42:10 -03:00
Shin'ichiro Kawasaki
27c95a9319 README.md: Improve device and distro confirmation status
Added "Confirmed devices and distros" section to clarify who confirmed
with which device or distros bluepy-scratch-link working well. Remove
trailing white spaces. Modified git repo URL for installation.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-03-01 14:46:53 +09:00
Shin'ichiro Kawasaki
d46090dd7a Merge pull request #6 from chrisglencross/master
Add Lego Mindstorms EV3 functionality. This commit implements BTSession for Bluetooth devices.
2020-03-01 14:45:16 +09:00
Chris Glencross
61a4ff5dbb Fix documentation, and mention pairing on the Raspberry Pi. 2020-02-24 20:24:18 +00:00
Chris Glencross
6b7619ebeb Add Lego Mindstorms functionality 2020-02-24 19:48:12 +00:00
Shin'ichiro Kawasaki
2240de0085 BLESession.matches: Check service adtypes both 16 bits and 128 bits
LEGO Boost communicates with a Scratch extension through Scratch-link.
It was reported that bluepy-scratch-link fails to connect to LEGO Boost.
LEGO Boost advertises adtype 0x7 "Complete List of 128-bit Service Class
UUIDs". However, bluepy-scratch-link checks only adtype 0x3 "Complete
List of 16-bit Service Class UUIDs" which is valid for micro:bit.

To allow bluepy-scratch-link, check both adtypes 0x7 and 0x3. Introduce
constants to note those two adtype values.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-01-25 18:58:35 +09:00
MDE
865c613890 filter: Removed UUID conversion
Scratch 3.0 sends full UUID for LEGO Boost Extension.
If other extensions don't do this, a classifier
will be needed.
2020-01-25 18:58:35 +09:00
MDE
cea2723a0b BLESession.__del__: Fixed NameError exception on exit because of error
Message was:
NameError: name 'close' is not defined
2020-01-25 18:58:35 +09:00
Shin'ichiro Kawasaki
2b7fb7a07a README.md: Describe how to use Chrome browser
As ngammarano reported in a GitHub issue, Chrome browser has bypass key
sequence to allow local server certificate. Add that description to
README.md merging jazzpecq's patch. Thank goes to the two :)

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-01-18 16:42:32 +09:00
Shin'ichiro Kawasaki
1215aa14cb Create LICENSE file
Clarify license of the bluepy-scratch-link script so that those who caring about licenses can take a look in the script code. I chose BSD 3-Clause "New" or "Revised" license, which is same as scratch-link to seek for the opportunity to get integrated into scratch-link, if possible.
2020-01-06 15:57:49 +09:00
Shin'ichiro Kawasaki
9cbe00224a README.md: Clarify python version 3.6 as the requirement
It was reported that the bluepy-scratch-link does not run on Ubuntu 16.04
which has python version 3.5. The script stopped with an error about
f-format string, which was introduce with python 3.6.

Even removing f-format string from the script, bluepy-scratch-link still
requires python 3.6 because websockets module requires it. Clarify that
python version requirement to avoid confusion.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2019-11-10 18:49:55 +09:00
Shin'ichiro Kawasaki
6136280c93 README.md: Describe motivation, installation and usage
Described why this script was written. Wrote down installation and usage
guide. Confirmed the guide with elementary os 5.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2019-09-15 20:50:32 +09:00
Shin'ichiro Kawasaki
402f79936f scratch_link.py: Initial commit
Implemented Scratch-link[1] feature as a small python script. Confirmed
it is working with Scratch 3.0[2] using a micro:bit as the BLE device to
link. This allows Linux PCs to connect Scratch and micro:bit.

Utilized bluez[3] and bluepy[4] to handle Bluetooth Low Energy connection.
Utilized Websocket module for Secure Web Socket server.

[1] https://github.com/LLK/scratch-link
[2] https://scratch.mit.edu/
[3] http://www.bluez.org/
[4] https://github.com/IanHarvey/bluepy

This is a minimal implementation to support micro:bit. Some of
Scratch-link features are not implemented. For example, Bluetooth (not
BLE) devices are not supported. BLE device support is confirmed only with
micro:bit.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2019-09-15 20:37:37 +09:00
Shin'ichiro Kawasaki
64ed1e53d9 Initial commit 2019-09-11 20:49:09 +09:00