esp8266-led-marquee-sign-co.../tools/re-server.py

43 lines
1.0 KiB
Python

"""
Simple socket server used to reverse engineer the messaging protocol the bundled software uses to send data to the
LED sign.
The server just dumps incoming messages in a hexdump-like format as well as an easy to read Python bytestring.
"""
import asyncio
import string
async def handle_client(reader, writer):
message = await reader.read(255)
hex_chars = [hex(j)[2:].zfill(2) for j in message]
ascii_chars = []
for j in message:
char = chr(j)
if char in (string.ascii_letters + string.digits + string.punctuation):
ascii_chars.append(char)
else:
ascii_chars.append(".")
print("Message received: ", end="")
print(" ".join(hex_chars), end=" | ")
print("".join(ascii_chars), end=" | ")
print("".join(repr(message)))
writer.close()
async def run_server():
server = await asyncio.start_server(handle_client, '', 3000)
async with server:
await server.serve_forever()
if __name__ == "__main__":
asyncio.run(run_server())