Fixato per usare porta seriale motherboard
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -31,7 +31,7 @@
|
||||
"INFLUXDB_TOKEN":"apiv3_tbEpA8JmIRTfr8Wbw9npD79BcMlFsnV4_jhdt-CdUP53Mos61KBODGaggl2g5oKZZvZrZu3e6mpob6zorhEdbg",
|
||||
"INFLUXDB_URL" : "http://edelweiss-srv:8181",
|
||||
"INFLUXDB_DATABASE" : "edelweiss",
|
||||
"PORT": "/dev/ttyUSB1",
|
||||
"PORT": "/dev/ttyS0",
|
||||
"BAUD": "2400",
|
||||
"LOG_FILE": "/tmp/upsmon.log",
|
||||
"LOG_FILE_LVL": "WARNING",
|
||||
|
||||
@@ -34,13 +34,13 @@ services:
|
||||
depends_on:
|
||||
- influxdb3
|
||||
devices:
|
||||
- /dev/ttyUSB1:/dev/ttyUSB1
|
||||
- /dev/ttyS0:/dev/ttyS0
|
||||
environment:
|
||||
- INTERVAL=5
|
||||
- INFLUXDB_TOKEN=apiv3_tbEpA8JmIRTfr8Wbw9npD79BcMlFsnV4_jhdt-CdUP53Mos61KBODGaggl2g5oKZZvZrZu3e6mpob6zorhEdbg
|
||||
- INFLUXDB_URL=http://influxdb3:8181
|
||||
- INFLUXDB_DATABASE=edelweiss
|
||||
- PORT=/dev/ttyUSB1
|
||||
- PORT=/dev/ttyS0
|
||||
- BAUD=2400
|
||||
- LOG_FILE=/tmp/upsmon.log
|
||||
- LOG_FILE_LVL=WARNING
|
||||
|
||||
26
upsmon/dataexchange.txt
Normal file
26
upsmon/dataexchange.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
VP req: QMD
|
||||
UPS resp: (#######WPHVT2K0 ###2000 80 1/1 230 230 04 12.0
|
||||
VP req: QRI
|
||||
UPS resp: (230.0 008 048.0 50.0
|
||||
VP req: QHE
|
||||
UPS resp: (242 218
|
||||
VP req: QRI
|
||||
UPS resp: (230.0 008 048.0 50.0
|
||||
VP req: QGS
|
||||
UPS resp: (230.9 50.0 230.7 50.1 001.0 013 373.7 379.4 054.4 ---.- 027.3 100000000001
|
||||
VP req: QMOD
|
||||
UPS resp: (L
|
||||
VP req: QWS
|
||||
UPS resp: (0000000000000000000000000000000000000000000000000000000000000000
|
||||
VP req: QBV
|
||||
UPS resp: (054.5 04 04 096 568
|
||||
VP req: QSK1
|
||||
UPS resp: (NAK
|
||||
VP req: QSK2
|
||||
UPS resp: (NAK
|
||||
VP req: QFLAG
|
||||
UPS resp: (EpbrashczDovegfm
|
||||
VP req: QBYV
|
||||
UPS resp: (264 170
|
||||
VP req: QBYF
|
||||
UPS resp: (53.0 47.0
|
||||
16
upsmon/sniffer.py
Normal file
16
upsmon/sniffer.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import serial
|
||||
|
||||
ups_port = "/dev/ttyUSB1"
|
||||
usb_fake = "/dev/ttyUSBf"
|
||||
|
||||
ups = serial.Serial(port=ups_port, baudrate=2400, parity="N", bytesize=8, stopbits=1)
|
||||
vp = serial.Serial(port=usb_fake, baudrate=2400, parity="N", bytesize=8, stopbits=1)
|
||||
|
||||
while True:
|
||||
vp_request = vp.read_until(b'\r')
|
||||
print(f'VP req: {vp_request.decode('ascii').strip()}')
|
||||
ups.write(vp_request)
|
||||
ups.flush()
|
||||
ups_response = ups.read_until(b'\r')
|
||||
print(f'UPS resp: {ups_response.decode('ascii').strip()}')
|
||||
vp.write(ups_response)
|
||||
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user