Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # I could NOT have done this without a few different sources on the web but this is a simple working script to pull data off an EPSolar Tracer BN series charge controller. The EPSolar USB RS485 adapter is a lot of work so skip it and and get a cheap $3.50 USB to RS485 off Ebay and snip an end off an Ethernet cable.
- from pymodbus.client.sync import ModbusSerialClient as ModbusClient
- import serial
- from pymodbus.pdu import ModbusRequest
- from pymodbus.transaction import ModbusRtuFramer
- from pymodbus.register_read_message import ReadHoldingRegistersResponse
- client = ModbusClient(method='rtu', port='/dev/ttyUSB0', baudrate=115200, stopbits=1, bytesize=8, timeout=2)
- client.connect()
- print(client)
- result = client.read_input_registers(0x3100,20, unit=1)
- solarVoltage = float(result.registers[0] / 100.0)
- solarCurrent = float(result.registers[1] / 100.0)
- solarWatt = float(result.registers[2] / 100.0)
- batteryVoltage = float(result.registers[4] / 100.0)
- chargeCurrent = float(result.registers[5] / 100.0)
- loadCurrent = float(result.registers[19] / 100.0)
- # Do something with the data
- print ("Solar Voltage", str (solarVoltage) + 'V')
- print ("Solar Current", str (solarCurrent) + 'A')
- print ("Current Watts", str (solarWatt) + 'W')
- print ("Battery Voltage", str (batteryVoltage) +'V')
- print ("Charge Current", str (chargeCurrent) + 'A')
- print ("Load Power", str (loadCurrent) + 'W')
- #print (result)
- client.close()
Advertisement
Add Comment
Please, Sign In to add comment