This commit is contained in:
Антон Кирпиков 2024-05-20 19:48:54 +03:00
parent b43920bacc
commit 4f3726d89b

30
ard.py
View File

@ -2,22 +2,30 @@ import uvicorn
from serial import Serial
import threading
from fastapi import FastAPI
s=""
import json
ser = Serial('COM6', 9600)
def pot():
global s
while True:
s = ser.read(1) # read up to one hundred bytes
th=threading.Thread(target=pot)
th.start()
data = {"value": 0}
def read_data():
global data
while True:
incoming_data = ser.read(1) # read up to one byte
try:
data["value"] = int(incoming_data)
except ValueError:
pass
app = FastAPI()
def get_data():
return json.dumps(data)
th = threading.Thread(target=read_data)
th.start()
@app.get("/")
async def root():
return ("message", s)
return data
if __name__ == "__main__":
uvicorn.run(app, port=10000)