init commit

This commit is contained in:
mk
2025-10-15 21:59:47 -03:00
commit 1d3281b164
3 changed files with 53 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
env

50
main.py Normal file
View File

@@ -0,0 +1,50 @@
import serial
import serial.tools.list_ports
import socket
HOST = '127.0.0.1'
PORT = 64222
def choose_serial_port():
ports = list(serial.tools.list_ports.comports())
if not ports:
print("No serial ports found.")
return None
print("Available serial ports:")
for i, port in enumerate(ports):
print(f"[{i}] {port.device} - {port.description}")
while True:
try:
choice = int(input("Select a port by number: "))
if 0 <= choice < len(ports):
return ports[choice].device
else:
print(f"Please enter a number between 0 and {len(ports) - 1}")
except ValueError:
print("Invalid input. Please enter a number.")
def main():
SERIAL = choose_serial_port()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print("Trying to connect to ", HOST, ":", PORT,"...")
s.connect((HOST, PORT))
print("Connected.")
print("Opening serial ",SERIAL,"...")
serialConn = serial.Serial(SERIAL)
with serialConn as ser:
print("Connected to Serial.")
while True:
line = str(ser.readline())
numbers = ''.join(c if c.isdigit() else ' ' for c in line).split()
uvLevel = int(numbers[-1]) if numbers else 0
print(line, " | Captured input: ", uvLevel)
message = str(uvLevel).encode() # Convert integer to bytes
s.sendall(message)
if __name__ == "__main__":
main()

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
serial