49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import socket
|
|
import sys
|
|
import logging
|
|
from time import sleep
|
|
|
|
|
|
def main():
|
|
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
|
datefmt='%H:%M:%S',
|
|
level=logging.DEBUG,
|
|
stream=sys.stdout)
|
|
|
|
host = "localhost"
|
|
port = 65432
|
|
|
|
while True:
|
|
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
client_socket.connect((host, port))
|
|
|
|
client_socket.send(b"""{
|
|
"jsonrpc": "2.0",
|
|
"id": "1",
|
|
"method": "SetLedPattern",
|
|
"params": {
|
|
"led": 19,
|
|
"pattern": 3.1
|
|
}
|
|
}
|
|
""")
|
|
|
|
try:
|
|
res = client_socket.recv(1024)
|
|
if not res:
|
|
logging.info("Client disconnected")
|
|
break
|
|
|
|
logging.info(f"SetLedPattern response: {res.decode()}")
|
|
except socket.timeout:
|
|
logging.error("Connection timed out")
|
|
break
|
|
|
|
client_socket.close()
|
|
|
|
sleep(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|