112 Commits

Author SHA1 Message Date
Shin'ichiro Kawasaki
ed4df282b1 Merge pull request #39 from rcy/master-1
Update README.md to correct micro:bit hex file download link.
2023-08-15 11:28:26 +09:00
Ryan Yeske
00154f2b51 Update README.md
Remove version number

Upstream url changed on https://scratch.mit.edu/microbit
2023-08-05 17:08:21 -07:00
Shin'ichiro Kawasaki
dc2ee5a22f Tag version 0.2.8
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.8
2023-07-02 21:52:08 +09:00
Shin'ichiro Kawasaki
caa344ecbb scratch_link.py: Support COMPLETE_LOCAL_NAME for 'namePrefix' filter
Current implementation of match() does filter matching for 'namePrefix'
keyword only for SHORT_LOCAL_NAME of the device. When the device does
not provide SHORT_LOCAL_NAME but provides COMPLETE_LOCAL_NAME, match()
for 'namePrefix' fails. For example, MicroBit More v2 [1] does not
provide the SHORT_LOCAL_NAME.

To support 'namePrefix' filter match with COMPLETE_LOCAL_NAME, add
support for it. While at it, replace the SHORT_LOCAL_NAME identifier
constant with the definition in btle.ScanEntry.

[1] https://lab.yengawa.com/project/microbit-more-v2/

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2023-07-02 21:52:08 +09:00
Shin'ichiro Kawasaki
0f9ccd3b63 Tag version 0.2.7
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.7
2023-03-21 17:17:31 +09:00
Shin'ichiro Kawasaki
d1f7f58ca2 README.md: Add description about -r option for scan failure
Add an item to "In Case You Fail to Connect" section to describe that
the "-r" option may help to address device scan failure.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2023-03-21 16:54:59 +09:00
Shin'ichiro Kawasaki
7050016ee6 scratch_link.py: Add -r option to retry BLE scan
Recently, scratch link connection failure is reported. Similar failure
is observed with my environment. I found BTLEDisconnectError happens at
scanner.scan(). Though the true cause of the failure is not yet known, I
found simple retry of scanner.scan() avoids the failure. As a temporary
work around, implement -r or --scan_retry option which specify how many
times to retry the scan. I confirmed that "-r 2" option avoided the
failure.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2023-03-21 15:53:34 +09:00
Shin'ichiro Kawasaki
d845d69bb8 gencert.py: Support Snap Firefox and Chromium
Recently Ubuntu provides Firefox and Chromium in the form of Snap
package, and they place NSS DB at different path from non-Snap package.
However, current gencert.py implementation supports only the NSS DB
paths for non-Snap packages. This results in HTTPS communication failure
between the browsers and scratch_link.

Support the NSS DB paths for the Snap packages. Add a new function
prep_cert_for_app() which takes application name and its NSS DB search
path. Call this function for list of browsers, covering both non-Snap
and Snap packages.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2023-03-19 20:59:58 +09:00
Shin'ichiro Kawasaki
751190935a release.sh: add example command lines
I tend to forget the command lines to release new packages. Record it in
the release script.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-18 11:12:46 +09:00
Shin'ichiro Kawasaki
3956c81869 Tag version 0.2.6
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.6
2022-07-18 10:58:32 +09:00
Shin'ichiro Kawasaki
caaec40935 release.sh: update package build commands
Recent changes in python eco-system require different command to build
python packages. Update the commands to fit to the latest environment.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-18 10:58:32 +09:00
Shin'ichiro Kawasaki
845b37707e README.md: remove descriptions about EV3
pyscrlink no longer support LEGO Mindstorm EV3. Remove the description
about EV3 and explain why it is not supported. I wish it will be
supported again some day.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-18 10:53:57 +09:00
Shin'ichiro Kawasaki
a5d19fa2ba setup.py: remove dependency to pybluez
pybluez can not be installed with pip. Remove dependency to it.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-18 10:53:57 +09:00
Shin'ichiro Kawasaki
865a4d6f09 scratch_link.py: remove pybluez dependency
Recently pybluez is not maintained actively and causing troubles. One of
the troubles is pip installation failure [1] and this made pyscrlink
uninstallable via pip. To avoid this, remove pybluez dependency from
pyscrlink. This removes Bluetooth Classic protocol support, then LEGO
Mindstorm EV3 is no longer supported.

[1] https://github.com/pybluez/pybluez/issues/431

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-18 10:24:05 +09:00
Shin'ichiro Kawasaki
bf154e0a14 .gitignore: add more directories to ignore
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2022-07-17 10:51:32 +09:00
Shin'ichiro Kawasaki
7cc9ccac2e Tag version 0.2.5
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.5
2021-11-21 14:25:56 +09:00
Shin'ichiro Kawasaki
4558ea43df BLESession: handle device UUIDs as list
In the debug for the issue #30, it turned out that the bluepy API
ScanEntry.getValueText() for adtypes may return multiple UUIDs
concatenated with comma. Current code assumes that the API returns
single UUID, then multiple UUIDs cause the "Error: Non-hexadecimal digit
found" for the comma.

To fix it, replace ScanEntry.getValueText() call with getValue(), and
handle the result as a list of UUIDs. Also rename the helper function
_get_dev_uuid() to _get_dev_uuids() accordingly.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-11-21 14:21:50 +09:00
Shin'ichiro Kawasaki
641b84a86e BLESession: Enrich logs for device UUID check
To debug the GitHub issue #30, add more debug logs to functions to check
UUID.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-11-21 14:21:42 +09:00
Shin'ichiro Kawasaki
e6d63a5c97 Tag version 0.2.4
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.4
2021-10-16 11:09:28 +09:00
Shin'ichiro Kawasaki
6f7da4f720 README.md: Add description about "-s 1" option for toio
For toio, it is recommended to add "-s 1" option to scratch_link
command. It reduces scan wait duration, and allows toio Do Visual
Programming to connect toio devices automatically. Document it for toio
users.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-10-16 11:09:28 +09:00
Shin'ichiro Kawasaki
32da72492f scratch_link.py: Add -s option to specify BLE scan duration
Pyscrlink scans BLE devices for 10 seconds. This is a safe number to
cover various environments and devices. However, this is too long for
specific devices. One example is toio. Toio's Visual Programming
environment has automated connection to toio devices via Scratch-link,
at it assumes that the scan finishes with shorter time. To allow users
to specify shorter scan duration, add -s, or --scan_seconds option.

To simplify this new option support, utilize argparse library. Rewrite
option parser with argparse.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-10-10 15:32:06 +09:00
Shin'ichiro Kawasaki
1af4baa7d6 README.md: Clarify bluepy-helper capability setup requirement
@n3storm reported that it is not clear which device is BLE, and requires
bluepy-helper capability setup. Improve description to note that most of
devices require the setup since BLE devices are getting the majority.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-09-25 09:38:37 +09:00
Néstor Díaz Valencia
39587b497b Update README.md 2021-09-25 09:30:55 +09:00
Néstor Díaz Valencia
f506bbcaab Update README.md 2021-09-25 09:30:55 +09:00
Shin'ichiro Kawasaki
9265086b12 Tag version 0.2.3
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.3
2021-05-08 21:04:03 +09:00
Shin'ichiro Kawasaki
58a60c94db scratch_link.py: Avoid eternal loop by hostname resolve failure
When the address of device-manager.scratch.mit.edu can not be resolved,
scratch_link.py catches the exception for the resolve failure and
restarts itself. This results in eternal loop.

To avoid the eternal loop, catch the resolve failure, print error
message and break the loop. Also improve the error message for the other
exceptions caught in the loop.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-08 20:32:05 +09:00
Shin'ichiro Kawasaki
ea1109cee2 Tag version 0.2.2
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.2
2021-05-03 19:42:50 +09:00
Shin'ichiro Kawasaki
f4af270fbc README.md: Improve description for multiple devices
Describe limitation for multiple device connections in "In Case You Fail
to Connect" section. Also, mention about toio support and improved a few
descriptions.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-03 19:33:06 +09:00
Shin'ichiro Kawasaki
1b92af0f0a BLESession: Support multiple connections
When one pyscrlink uses tries to connect multiple devices at the same
time, the user can connect to the first device without problem. However,
the device scan for the second device causes connection loss for the
first connected device. As discussed in its GitHub issue #357 [1], it is
the limitation of bluepy as of today. This limitation is critical for
pyscrlink to bridge toio[2] and its own scratch[3], because the toio
scratch allows to connect two toio devices to single scratch project.

[1] https://github.com/IanHarvey/bluepy/issues/357
[2] https://www.sony.com/en/SonyInfo/design/stories/toio/
[3] https://github.com/toio/toio-visual-programming/

To bridge multiple devices by pyscrlink, keep references to multiple
devices at the first device scan. Assuming that the user prepares all of
the target devices ready at the device scan, pyscrlink can find the all
devices and keep references to them. When the user requests scan for the
second device, pyscrlink does not invoke the device scan. Instead, it
returns the references to the device it keeps. With this approach, the
disconnection by device scan can be avoided.

In detail, add BLESession.found_devices to keep the found devices and
share across multiple BLESessions. Add BLESession.nr_connected to count
connected sessions. While connected sessions exist, do not scan and
refer the list to return the found device list. Also refactor out device
scan part to a private function _scan_devices().

Note that the user must prepare all devices ready before the first scan.
The devices prepared after the first can not be found since pyscrlink
does not invoke scan. User must disconnect all devices to have pyscrlink
scan devices again.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-03 19:33:06 +09:00
Shin'ichiro Kawasaki
c206f7a5c5 BLESession: Close session on Exception
When an exception is thrown during a session, still the session no
longer works, but still keeps connection. With this status, following
device scan can not find the device. This symptom was observed when
micro:bit with scratch-microbit.hex is connected to "micro:bit MORE" and
BTLEException is thrown. Another symptom observed is the Scratch web
page closed and websocket connection slows ConnectionClosedOK exception.

To avoid the device scan failure, close the session when an exception is
caught. Also improve error message for the exception.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-03 19:32:49 +09:00
Shin'ichiro Kawasaki
e34ec61f3b Tag version 0.2.1
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.1
2021-04-11 14:14:33 +09:00
Shin'ichiro Kawasaki
e552bd21bd bluepy_helper_cap.py: Check tools out of PATH
It was informed that the required tools setcap and getcap are not placed
in /usr/bin in some user environment. They can not be executed since
they are out of PATH. To allow the script to execute the commands out of
PATH, have the script find the tools. Keep the found paths of each
command in the dictionary 'tools', and refer it to execute the commands.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-04-11 13:36:23 +09:00
Shin'ichiro Kawasaki
dc46869760 BLESession: Refine error message for capability check
The error message on bluepy-helper capability check failure was not
accurate. Refine it.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-02-07 20:27:38 +09:00
Peter Butkovic
461377f7ea Fixed missing glib.h error 2021-02-07 20:25:42 +09:00
Shin'ichiro Kawasaki
923c036cec Tag version 0.2.0
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.2.0
2020-12-27 21:09:05 +09:00
Shin'ichiro Kawasaki
8a69c2c917 README.md: Add "Issue Reporting" and Releases" sections
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-12-27 20:57:09 +09:00
Shin'ichiro Kawasaki
1e7f81906e BLESession: Refactor cached characteristics handling
To improve readability a bit, introduce _get_characteristic_cached().
Added some failure handlings in the method for robustness.
Also rename _get_all_characteristics() to _cache_characteristics() for
simplification.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-12-19 11:43:45 +09:00
sza2
73523120b9 Update scratch_link.py
Retrieve all characteristics value on connect and cache it to speed up characteristics write that was slow as the handle got by _get_characteristic() every time a write occurred.
2020-12-15 14:02:33 +01:00
Shin'ichiro Kawasaki
d8299a5b3c Tag version 0.1.0
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
v0.1.0
2020-10-27 11:35:34 +09:00
Shin'ichiro Kawasaki
8bf23a8c77 README.md: Brush up description
Improved English of the description. Updated list of devices and distros
that work with pyscrlink. Replaced 'Lego' with 'LEGO'.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-27 11:32:57 +09:00
Shin'ichiro Kawasaki
7de173f324 gencert.py: Specify X.509 certificate version 3
By default, pyOpenSSL generates X.509 certification version 1. However,
Chrome does not work with X.509 with version 1 and fails with
ERR_SSL_SERVER_CERT_BAD_FORMAT error. Set version 3 to generate X.509
certificate.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
ac819b926d bluepy_helper_cap.py, gencert.py: Remove capture_output
The argument capture_output which was introduced in python 3.7 is used in
bluepy_helper_cap.py and gencert.py. This cause failure with python 3.6
environment. Avoid the failure by removing the argument.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
22dbd5e092 release.sh: Add upload command
To upload the release package to pypi.org, add upload command.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
4ff47e2368 README.md: Describe repository rename to pyscrlink
Briefly described that bluepy-scratch-link was renamed to pyscrlink in
October 2020.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
7be5a725fa setup.py: Add install_requires argument
To install dependent packages automatically, add install_requires
argument to setup() function.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
bcd55cad00 README.md: Update description for pyscrlink
Rephrase explanation to match with the new project name "pyscrlink".

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
a53947fca3 pyscrlink/*.py, setup.py: Rename project to pyscrlink
Rename bluepy_scratch_link strings in python scripts to pyscrlink.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-23 18:06:55 +09:00
Shin'ichiro Kawasaki
c4cf901878 pyscrlink directory: Rename bluepy_scratch_link directory to pyscrlink
As the first step to rename the project to pyscrlink, rename the module
directory from bluepy_scratch_link to pyscrlink.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-11 15:12:46 +09:00
Shin'ichiro Kawasaki
7efd1ec827 scratch_link.py: Fix errors when it is run as package command
When scratch_link.py is executed as the command specified by setuptools'
entry_point, following errors happen. Fix them.

- Package name can not be resolved to import modules.
- The global variable sessionTypes can not be refereed from the main
  function.
- Command line options are not parsed in main function.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-10 17:32:52 +09:00
Shin'ichiro Kawasaki
54c3a18e5e bluepy_helper_cap.py: Add sudo to setcap command
When a python package is installed by user, the commands in the package
can not run with sudo. To run setcap in bluepy_helper_cap.py with sudo
privilege, specify sudo command within the python script.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2020-10-10 17:30:03 +09:00