32 lines
No EOL
1 KiB
Python
32 lines
No EOL
1 KiB
Python
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])) |