# Note: this test is for MacOS # The results are not very good between 2 MacBook Pro's: # INFO:__main__:Test 1: Write: 60.72 ms, Read: 59.08 ms, Total RTT: 119.80 ms, Timestamp: 1713, Time diff: 0 ms import asyncio import time import struct import argparse import logging from typing import Any # For the server from bless import BlessServer from bless.backends.characteristic import GATTCharacteristicProperties, GATTAttributePermissions # For the client from bleak import BleakClient, BleakScanner logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) SERVICE_UUID = "A07498CA-AD5B-474E-940D-16F1FBE7E8CD" CHAR_UUID = "51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B" CONN_PARAMS_SERVICE_UUID = "1234A00C-0000-1000-8000-00805F9B34FB" CONN_PARAMS_CHAR_UUID = "1234A00D-0000-1000-8000-00805F9B34FB" # Define the desired connection interval (7.5ms) CONN_INTERVAL_MIN = 6 # 7.5ms in 1.25ms units CONN_INTERVAL_MAX = 6 CONN_LATENCY = 0 SUPERVISION_TIMEOUT = 100 # 1 second def read_request(characteristic): return characteristic.value def write_request(characteristic, value): characteristic.value = value if value == b"ping": characteristic.value = b"pong" async def run_server(loop): server = BlessServer(name="Latency Test Server", loop=loop) server.read_request_func = read_request server.write_request_func = write_request await server.add_new_service(SERVICE_UUID) # Main characteristic for ping-pong (read and write) char_flags = GATTCharacteristicProperties.read | GATTCharacteristicProperties.write permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writeable await server.add_new_characteristic( SERVICE_UUID, CHAR_UUID, char_flags, None, permissions ) # Add new service and characteristic for connection parameters (read-only) await server.add_new_service(CONN_PARAMS_SERVICE_UUID) conn_params = struct.pack("