mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-06 09:40:14 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2482bba1d8 | ||
|
06df4af4a0 | ||
|
adb746995e | ||
|
157e3458b0 | ||
|
fe3cd35ac0 | ||
|
94a9555c4c | ||
|
39b157e839 | ||
|
f79e7ac889 |
@@ -102,7 +102,7 @@ Installation
|
||||
|
||||
5. For micro:bit, install Scratch-link hex on your device.
|
||||
|
||||
* Download and unzip the [micro:bit Scratch Hex file](https://downloads.scratch.mit.edu/microbit/scratch-microbit.hex.zip).
|
||||
* Download and unzip the [micro:bit Scratch Hex file](https://downloads.scratch.mit.edu/microbit/scratch-microbit-1.1.0.hex.zip).
|
||||
* 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'.
|
||||
|
@@ -34,8 +34,8 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
connected_devices = {}
|
||||
|
||||
class Device():
|
||||
def __init__(self, iface, path, node_name, name, address):
|
||||
self.iface = iface
|
||||
def __init__(self, interface, path, node_name, name, address):
|
||||
self.interface = interface
|
||||
self.path = path
|
||||
self.node_name = node_name
|
||||
self.name = name
|
||||
@@ -95,7 +95,7 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
logger.debug(f"service to check: {s}")
|
||||
given_uuid = BTUUID(s)
|
||||
logger.debug(f"given UUID: {given_uuid} hash={given_uuid.__hash__()}")
|
||||
dev_uuids = await dev.iface.uuids
|
||||
dev_uuids = await dev.interface.uuids
|
||||
if not dev_uuids:
|
||||
logger.debug(f"dev UUID not available")
|
||||
continue
|
||||
@@ -122,7 +122,7 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
async def _notify_device(self, device) -> None:
|
||||
params = { 'rssi': -80, 'name': 'Unknown' }
|
||||
try:
|
||||
params['rssi'] = await device.iface.rssi
|
||||
params['rssi'] = await device.interface.rssi
|
||||
except Exception:
|
||||
None
|
||||
if device.name:
|
||||
@@ -149,17 +149,17 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
devpath = self.iface + "/" + node_name
|
||||
if BLEDBusSession.connected_devices.get(devpath):
|
||||
continue
|
||||
iface = DeviceInterfaceAsync()
|
||||
iface._connect('org.bluez', devpath, bus=self.dbus)
|
||||
interface = DeviceInterfaceAsync()
|
||||
interface._connect('org.bluez', devpath, bus=self.dbus)
|
||||
try:
|
||||
devname = await iface.name
|
||||
devname = await interface.name
|
||||
except Exception as e:
|
||||
logger.debug(f"device {node_name} does not have name: {e}")
|
||||
devaddr = await iface.address
|
||||
device = self.Device(iface, devpath, node_name, devname,
|
||||
devaddr = await interface.address
|
||||
device = self.Device(interface, devpath, node_name, devname,
|
||||
devaddr)
|
||||
if not await self._matches(device, self.discover_filters):
|
||||
await iface.disconnect()
|
||||
await interface.disconnect()
|
||||
continue
|
||||
self.found_devices[node_name] = device
|
||||
await self._notify_device(device)
|
||||
@@ -309,7 +309,7 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
dev = self.found_devices[params['peripheralId']]
|
||||
try:
|
||||
logger.debug(f" {dev}")
|
||||
await dev.iface.connect()
|
||||
await dev.interface.connect()
|
||||
res["result"] = None
|
||||
self.device = dev
|
||||
self.status = self.CONNECTED
|
||||
@@ -362,7 +362,7 @@ class BLEDBusSession(pyscrlink.scratch_link.Session):
|
||||
dev = self.device
|
||||
logger.info(f"Disconnecting from '{dev.name}'@{dev.address}")
|
||||
self._stop_notifications()
|
||||
await dev.iface.disconnect()
|
||||
await dev.interface.disconnect()
|
||||
BLEDBusSession.connected_devices.pop(dev.path)
|
||||
logger.info(f"Disconnected from '{dev.name}'@{dev.address}")
|
||||
self.device = None
|
||||
|
@@ -33,8 +33,17 @@ from pyscrlink import gencert
|
||||
|
||||
from pyscrlink import ble
|
||||
|
||||
logLevel = logging.INFO
|
||||
|
||||
# for logging
|
||||
logger = logging.getLogger('pyscrlink.scratch_link')
|
||||
formatter = logging.Formatter(fmt='%(asctime)s %(message)s')
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logLevel)
|
||||
handler.setFormatter(formatter)
|
||||
logger.setLevel(logLevel)
|
||||
logger.addHandler(handler)
|
||||
logger.propagate = False
|
||||
|
||||
HOSTNAME="device-manager.scratch.mit.edu"
|
||||
scan_seconds=10.0
|
||||
@@ -588,24 +597,14 @@ def main():
|
||||
parser.add_argument('-b', '--dbus', action='store_true',
|
||||
help='use DBus backend for BLE devices')
|
||||
args = parser.parse_args()
|
||||
|
||||
logLevel = logging.INFO
|
||||
if args.debug:
|
||||
print("Print debug messages")
|
||||
logLevel = logging.DEBUG
|
||||
|
||||
formatter = logging.Formatter(fmt='%(asctime)s %(message)s')
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logLevel)
|
||||
handler.setFormatter(formatter)
|
||||
logger.setLevel(logLevel)
|
||||
logger.addHandler(handler)
|
||||
logger.propagate = False
|
||||
|
||||
handler.setLevel(logLevel)
|
||||
logger.setLevel(logLevel)
|
||||
scan_seconds = args.scan_seconds
|
||||
scan_retry = args.scan_retry
|
||||
dbus = args.dbus
|
||||
if args.debug:
|
||||
logger.debug("Print debug messages")
|
||||
logger.debug(f"set scan_seconds: {scan_seconds}")
|
||||
logger.debug(f"set scan_retry: {scan_retry}")
|
||||
|
||||
|
Reference in New Issue
Block a user