add cozir serial to osc

This commit is contained in:
Philipp Kramer 2022-05-19 09:59:50 +02:00
parent 16d4a68345
commit 590ed26d7f

32
COZIR-OSC/cozir.py Normal file
View file

@ -0,0 +1,32 @@
import argparse
from serial import Serial # pip install pyserial
from pythonosc import udp_client #pip install python-osc
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1", help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=7005, help="The port the OSC server is listening on")
args = parser.parse_args()
client = udp_client.SimpleUDPClient(args.ip, args.port)
ser = Serial('COM4', 9600, timeout=1)
ser.write(b'M 6\n')
ser.write(b'K 1\n')
while True:
#read data from serial port
serread = ser.readline()
#if there is smth do smth
if len(serread) >= 1:
datastring = serread.decode("utf-8").rstrip('\n').rstrip('\r')
#print(datastring)
data=datastring.split(' ')
print(data)
client.send_message('data/humidity', int(data[2]))
client.send_message('data/temperature', int(data[4]))
client.send_message('data/co2filtered', int(data[6]))
client.send_message('data/co2raw', int(data[8]))