Fixato per usare porta seriale motherboard

This commit is contained in:
2025-06-10 16:37:12 +02:00
parent 2b6af1ca7a
commit 530755db90
5 changed files with 54 additions and 6 deletions

View File

@@ -19,7 +19,8 @@ def send(port: serial.Serial, d: str):
port.flush()
def receive(port: serial.Serial, d: str) -> str:
r = port.read_until(b'\r').decode('ascii').rstrip()
# Expected response, 46chrs (231.5 230.8 229.2 012 50.0 2.27 27.0 00000001
r = port.read_until(expected=b'\r').decode('ascii').rstrip()
LOGGER.debug(f"{d} : {r}")
return r
@@ -39,13 +40,16 @@ def bruteforceCommands(port: serial.Serial):
send(port, d)
receive(port, d)
##################
###### MAIN ######
##################
def main() -> int:
INTERVAL = int(env['INTERVAL'])
UPS_COMMAND = "Q1"
UPS_STATUS = "QGS" # (Vin Fin Vout Fout Aout Load% ?1 ?2 VbatInt VbatExt Temp Flags
UPS_BATTERY = "QBV" # (Vbat n1 n2 Charge% RunMins
UPS_MODE = "QMOD" # (Mode [Echo, Line, Battery?]
try:
# Init InfluxDB-v3 Client
write_client = InfluxDBClient3(host=env['INFLUXDB_URL'],
@@ -53,6 +57,7 @@ def main() -> int:
database=env['INFLUXDB_DATABASE'])
# Init Serial port
port = serial.Serial(port=env['PORT'], baudrate=int(env['BAUD']), bytesize=8, parity='N', stopbits=1)
port.flush()
except Exception as e:
LOGGER.error(e)
return 1
@@ -70,7 +75,7 @@ def main() -> int:
raw_data = receive(port, UPS_COMMAND).lstrip('(').rstrip().split()
if len(raw_data) < 8:
LOGGER.error(f"Incomplete data: {raw_data}")
continue
break
values = {
'inV': float(raw_data[0]),
'outV': float(raw_data[2]),
@@ -92,6 +97,7 @@ def main() -> int:
###### END MAIN LOOP #########
##############################
port.close()
LOGGER.warning("Main thread exited normally")
return 0
if __name__ == "__main__":