|
| 1 | +#!/usr/bin/python |
| 2 | +import sys |
| 3 | +import os |
| 4 | +import time |
| 5 | +import getopt |
| 6 | +import socket |
| 7 | +import ConfigParser |
| 8 | +import struct |
| 9 | +import binascii |
| 10 | +ipaddress = str(sys.argv[1]) |
| 11 | +from pymodbus.client.sync import ModbusTcpClient |
| 12 | +client = ModbusTcpClient(ipaddress, port=502) |
| 13 | + |
| 14 | + |
| 15 | +resp= client.read_holding_registers(40206,1,unit=1) |
| 16 | +value1 = resp.registers[0] |
| 17 | +all = format(value1, '04x') |
| 18 | +final = int(struct.unpack('>h', all.decode('hex'))[0]) * -1 |
| 19 | +f = open('/var/www/html/openWB/ramdisk/wattbezug', 'w') |
| 20 | +f.write(str(final)) |
| 21 | +f.close() |
| 22 | + |
| 23 | +resp= client.read_holding_registers(40084,2,unit=1) |
| 24 | +multipli = resp.registers[0] |
| 25 | +multiplint = format(multipli, '04x') |
| 26 | +fmultiplint = int(struct.unpack('>h', multiplint.decode('hex'))[0]) |
| 27 | + |
| 28 | +respw= client.read_holding_registers(40083,2,unit=1) |
| 29 | +value1w = respw.registers[0] |
| 30 | +allw = format(value1w, '04x') |
| 31 | +rawprodw = finalw = int(struct.unpack('>h', allw.decode('hex'))[0]) * -1 |
| 32 | +if fmultiplint == -1: |
| 33 | + rawprodw = rawprodw / 10 |
| 34 | +if fmultiplint == -2: |
| 35 | + rawprodw = rawprodw / 100 |
| 36 | +if fmultiplint == -3: |
| 37 | + rawprodw = rawprodw / 1000 |
| 38 | +if fmultiplint == -4: |
| 39 | + rawprodw = rawprodw / 10000 |
| 40 | +f = open('/var/www/html/openWB/ramdisk/pvwatt', 'w') |
| 41 | +f.write(str(rawprodw)) |
| 42 | +f.close() |
| 43 | + |
| 44 | +resp= client.read_holding_registers(40093,2,unit=1) |
| 45 | +value1 = resp.registers[0] |
| 46 | +value2 = resp.registers[1] |
| 47 | +all = format(value1, '04x') + format(value2, '04x') |
| 48 | +final = int(struct.unpack('>i', all.decode('hex'))[0]) |
| 49 | +f = open('/var/www/html/openWB/ramdisk/pvkwh', 'w') |
| 50 | +f.write(str(final)) |
| 51 | +f.close() |
| 52 | +pvkwhk= final / 1000 |
| 53 | +f = open('/var/www/html/openWB/ramdisk/pvkwhk', 'w') |
| 54 | +f.write(str(pvkwhk)) |
| 55 | +f.close() |
| 56 | + |
| 57 | + |
| 58 | +resp= client.read_holding_registers(40234,2,unit=1) |
| 59 | +value1 = resp.registers[0] |
| 60 | +value2 = resp.registers[1] |
| 61 | +all = format(value1, '04x') + format(value2, '04x') |
| 62 | +final = int(struct.unpack('>i', all.decode('hex'))[0]) |
| 63 | +f = open('/var/www/html/openWB/ramdisk/bezugkwh', 'w') |
| 64 | +f.write(str(final)) |
| 65 | +f.close() |
| 66 | + |
| 67 | +resp= client.read_holding_registers(40226,2,unit=1) |
| 68 | +value1 = resp.registers[0] |
| 69 | +value2 = resp.registers[1] |
| 70 | +all = format(value1, '04x') + format(value2, '04x') |
| 71 | +final = int(struct.unpack('>i', all.decode('hex'))[0]) |
| 72 | +f = open('/var/www/html/openWB/ramdisk/einspeisungkwh', 'w') |
| 73 | +f.write(str(final)) |
| 74 | +f.close() |
| 75 | + |
0 commit comments