aa901ba8 by huangyf2

6.8.2.py

1 parent 54ac76a2
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
......@@ -186,7 +186,7 @@ class BLEClient:
"result": None,
"id": request_id
})
await log_message("下发", response)
# await log_message("下发", response)
await websocket.send(response)
elif method == "write":
......@@ -198,9 +198,12 @@ class BLEClient:
if all([service_id, characteristic_id, message]):
if encoding == "base64":
message_bytes = base64.b64decode(message)
print("write message_bytes",message_bytes)
else:
print("write message",message)
message_bytes = message.encode(encoding)
await self.client.write_gatt_char(characteristic_id, message_bytes)
response = json.dumps({
"jsonrpc": "2.0",
......@@ -216,6 +219,7 @@ class BLEClient:
if all([service_id, characteristic_id]):
data = await self.client.read_gatt_char(characteristic_id)
print('read-data',base64.decode(data))
response = json.dumps({
"jsonrpc": "2.0",
"result": {
......@@ -285,6 +289,7 @@ class BLEClient:
# 解码当前数据用于比较
current_message = base64.b64encode(data).decode('utf-8')
print('notification_handler current_message',base64.b64decode(current_message))
# 过滤逻辑
if current_message == last_message and (current_time - last_time) < 0.5:
......
This diff is collapsed. Click to expand it.
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!