Skip to content

Commit

Permalink
Connection to LED strip is maintained throughout program lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
srgtuszy committed Oct 28, 2024
1 parent 45e3586 commit 9b6c7e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 27 additions & 1 deletion led-controller/govee_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,30 @@ def create_brightness_packet(brightness):
xor_checksum = 0x33 ^ 0x04 ^ brightness
command.append(xor_checksum)

return command
return command

@staticmethod
def create_keep_alive_packet():
command = bytearray([
0xAA, # Command prefix for keep alive
0x01, # Command to keep alive
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0x00, # Fixed byte
0xAB # Fixed byte
])

return command
6 changes: 5 additions & 1 deletion led-controller/run_led_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ async def main():
print("Setting color to purple")
await set_light_color(client, green_color)

print(f"Finished updating {device.name}\n")
# Send keep-alive packets every second
print("Sending keep-alive packets...")
while True:
await client.write_gatt_char(WRITE_CHAR_UUID, bytes.fromhex("AA01000000000000000000000000000000000015"), response=True)
await asyncio.sleep(1)

except Exception as e:
print(f"Error controlling device {device.address}: {e}")
Expand Down

0 comments on commit 9b6c7e4

Please sign in to comment.