import asyncio import websockets import struct import numpy as np from pprint import pprint import datetime import msgpack import aiomonitor class MsgManager: def __init__(self): self.msg_history = [] def add_msg(self, msg): pprint(msg) self.msg_history.append(msg) send_functions = [] class MsgCode: ERROR = 1 # device to frontend INITIAL_INFO = 2 SESSION_STARTED = 3 SESSION_STOPPED = 4 SESSION_NEW_DATA = 5 ANSWER_USER_LIST = 6 ANSWER_SESSION_LIST = 7 WIFI_STATE_RESPONSE = 8 WIFI_SCAN_RESPONSE = 9 # from frontend to device START_SESSION = 128 STOP_SESSION = 129 TARE = 130 QUERY_USER_LIST = 131 QUERY_SESSION_LIST = 132 WIFI_STATE_SET = 133 WIFI_STATE_GET = 134 WIFI_TRIGGER_SCAN = 135 async def send_message(websocket, msg_type, payload=None): payload = struct.pack("