import serial import subprocess import time import ZSend import time import socket import sys import select interval = 1000 ser = serial.Serial('/dev/ttyACM0', 115200) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server_address = ('localhost', 10000) sock.bind(server_address) sock.setblocking(0) timeout_in_seconds=0.001 prevState = "" while True: line = ser.readline() print(line) ready = select.select([sock], [], [], timeout_in_seconds) if ready[0]: data, address = sock.recvfrom(1024) print("UDP received: " + data) if data: print("Going to write: " + data) ser.write((data + "\n").encode()) ser.flush() print("Write finished") prevState = data sensors = line.split("|") zSend = ZSend.ZSend() for sensor in sensors: params = sensor.split(";") if len(params) > 1: zabbixVarName = "temp" + params[0] val = float(params[1]) print(params[0] + ' = ' + params[1]) if val > 15 and val < 100: zabbixVarName = "temp" + params[0] zSend.add_data("Zabbix server", zabbixVarName, val, int(time.time())) elif val == 0 or val == 1: zSend.add_data("Zabbix server", params[0], int(val), int(time.time())) lastTime = 0 curTime = time.time() if curTime - lastTime > interval: zSend.bulk_send() lastTime = curTime zSend.print_vals()