Skip to content

Commit be567ef

Browse files
committed
A few smaller updates (untested!)
I haven't yet had a chance to test the code changes.
1 parent c96d147 commit be567ef

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

bt-serial/BluetoothSerial.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ TODO:
6666
- Consider putting `/var/lib/bluetooth` on the `/data` partition so pairings are remembered.
6767
- Provide a way to configure the serial port parameters. For example, a web interface, or perhaps `bt_serial_bridge.py`
6868
could accept connections on a second port, where it only receives serial port configuration options?
69+
- Consider in-band AT commands as per [ITU-T V.250](https://www.itu.int/rec/T-REC-V.250-200307-I/en)
70+
- `(1sec)+++(1sec)` (break), `AT+IPR=(baud)`, `AT+ICF=(data/stop/parity)`, `AT+IFC=(flow ctrl)`, `ATO` (resume)
6971

7072

7173
<!-- spell: ignore Pairable bluetoothd fakepty icanon rfkill socat wlan trixie proxychains raspi raspinotes mysync -->

bt-serial/bt_serial_bridge.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,22 @@ def bluetooth_ctx(*, uuid: str, debug: bool):
270270
server_sock.listen(1)
271271

272272
bluetooth.advertise_service(
273-
server_sock, "SerialBridge", service_id=uuid,
274-
service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
273+
sock=server_sock, name=uuid, service_id=uuid,
274+
service_classes=[bluetooth.SERIAL_PORT_CLASS],
275275
profiles=[bluetooth.SERIAL_PORT_PROFILE],
276-
description="Serial-to-Bluetooth Bridge")
276+
provider="BTSerialBridge", description="Serial-to-Bluetooth Bridge")
277277

278278
if debug:
279279
print(
280280
'Waiting for RFCOMM connection on port'
281281
f"{server_sock.getsockname()}...")
282282
bt_sock, client_info = server_sock.accept()
283283
print(f"Accepted connection from {client_info}")
284+
# Note that `BluetoothSocket` objects *wrap* a `socket` object:
285+
# https://github.com/pybluez/pybluez/blob/82cbba8a/bluetooth/bluez.py#L233
286+
# Also note Serial objects are custom objects, but on POSIX (only!) they
287+
# have a fileno:
288+
# https://github.com/pyserial/pyserial/blob/911a0b8c/serial/serialposix.py#L806
284289

285290
try:
286291
yield bt_sock
@@ -291,6 +296,8 @@ def bluetooth_ctx(*, uuid: str, debug: bool):
291296

292297

293298
def bridge_ports(*, ser: serial.Serial, bt: socket.socket, debug: bool):
299+
# TODO: consider switching to asyncio.
300+
# Hints: `asyncio.loop.add_reader`, `loop.sock_recv` etc.
294301
keep_running = True
295302
while keep_running:
296303
try:
@@ -311,7 +318,7 @@ def bridge_ports(*, ser: serial.Serial, bt: socket.socket, debug: bool):
311318
if debug:
312319
print(f"Serial -> BT: {data!r}")
313320
if data:
314-
bt.send(data)
321+
bt.sendall(data)
315322
elif not ser.is_open:
316323
print('Stopping b/c of Serial disconnect')
317324
keep_running = False

0 commit comments

Comments
 (0)