From d6a111ede71dce0f82aeef1dc9fa21b815de9017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Thu, 16 Nov 2023 23:11:02 +0100 Subject: [PATCH] debugging 503 errors after idle time --- bluewind/headwind/__init__.py | 31 +++++++++++++++---------------- default.env | 3 +-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/bluewind/headwind/__init__.py b/bluewind/headwind/__init__.py index 29e6509..f6c27f1 100644 --- a/bluewind/headwind/__init__.py +++ b/bluewind/headwind/__init__.py @@ -15,13 +15,12 @@ CHARACTERISTIC = "a026e038-0a7d-4ab3-97fa-f1500f9feb8b" # > bytearray(b'\xfd\x01\x00\x01') class Headwind: - fanClient = None def __init__(self, address): - self.fanClient = BleakClient(address) + self.address = address async def readSpeed(self): try: - async with self.fanClient as client: + async with BleakClient(self.address) as client: result = await client.read_gatt_char(CHARACTERISTIC) return result[2] except Exception: @@ -29,7 +28,7 @@ class Headwind: async def readMode(self): try: - async with self.fanClient as client: + async with BleakClient(self.address) as client: result = await client.read_gatt_char(CHARACTERISTIC) return result[3] # Return state code, needs to figure out what each code means except Exception: @@ -37,32 +36,32 @@ class Headwind: async def writeSleep(self): try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, SLEEP) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, SLEEP, response=False) return True except Exception as e: return False async def writeOn(self): try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, ON) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, ON, response=False) return True except Exception as e: return False async def writeSpeedMode(self): try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, SPD) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, SPD, response=False) return True except Exception as e: return False async def writeHrMode(self): try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, HR) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, HR, response=False) return True except Exception as e: return False @@ -71,8 +70,8 @@ class Headwind: if speed > 0: value = [0x2, speed] try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, value) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, value, response=False) return True except Exception as e: return False @@ -80,8 +79,8 @@ class Headwind: async def writeOff(self): try: - async with self.fanClient as client: - await client.write_gatt_char(CHARACTERISTIC, OFF) + async with BleakClient(self.address) as client: + await client.write_gatt_char(CHARACTERISTIC, OFF, response=False) return True except Exception as e: return False \ No newline at end of file diff --git a/default.env b/default.env index eac4c0d..f627499 100644 --- a/default.env +++ b/default.env @@ -1,2 +1 @@ -FLASK_ADDRESS='F2:B3:F7:6A:24:48' -FLASK_URL='127.0.0.1:5000' \ No newline at end of file +FLASK_ADDRESS='F2:B3:F7:6A:24:48' \ No newline at end of file