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: ...@@ -186,7 +186,7 @@ class BLEClient:
186 "result": None, 186 "result": None,
187 "id": request_id 187 "id": request_id
188 }) 188 })
189 await log_message("下发", response) 189 # await log_message("下发", response)
190 await websocket.send(response) 190 await websocket.send(response)
191 191
192 elif method == "write": 192 elif method == "write":
...@@ -198,8 +198,11 @@ class BLEClient: ...@@ -198,8 +198,11 @@ class BLEClient:
198 if all([service_id, characteristic_id, message]): 198 if all([service_id, characteristic_id, message]):
199 if encoding == "base64": 199 if encoding == "base64":
200 message_bytes = base64.b64decode(message) 200 message_bytes = base64.b64decode(message)
201 print("write message_bytes",message_bytes)
201 else: 202 else:
203 print("write message",message)
202 message_bytes = message.encode(encoding) 204 message_bytes = message.encode(encoding)
205
203 206
204 await self.client.write_gatt_char(characteristic_id, message_bytes) 207 await self.client.write_gatt_char(characteristic_id, message_bytes)
205 response = json.dumps({ 208 response = json.dumps({
...@@ -216,6 +219,7 @@ class BLEClient: ...@@ -216,6 +219,7 @@ class BLEClient:
216 219
217 if all([service_id, characteristic_id]): 220 if all([service_id, characteristic_id]):
218 data = await self.client.read_gatt_char(characteristic_id) 221 data = await self.client.read_gatt_char(characteristic_id)
222 print('read-data',base64.decode(data))
219 response = json.dumps({ 223 response = json.dumps({
220 "jsonrpc": "2.0", 224 "jsonrpc": "2.0",
221 "result": { 225 "result": {
...@@ -285,6 +289,7 @@ class BLEClient: ...@@ -285,6 +289,7 @@ class BLEClient:
285 289
286 # 解码当前数据用于比较 290 # 解码当前数据用于比较
287 current_message = base64.b64encode(data).decode('utf-8') 291 current_message = base64.b64encode(data).decode('utf-8')
292 print('notification_handler current_message',base64.b64decode(current_message))
288 293
289 # 过滤逻辑 294 # 过滤逻辑
290 if current_message == last_message and (current_time - last_time) < 0.5: 295 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!