Page 1 of 1

Batrium BMS Monitoring

Posted: Tue, 23 Oct 2018, 21:25
by bigjsl
Hope this is the right place to post this.

I wrote a bit of python3 to monitor my Batrium BMS.

You can modify it using info here: https://github.com/Batrium/WatchMonUdpL ... 20v1.0.pdf

I plan to incorporate it into my pvoutput upload script.
# Batrium UDP monitor in Python3
# John Lindsay

import select, socket
import struct

port = 18542  # where do you expect to get a msg?
bufferSize = 1024 # whatever you need

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('',port))
s.setblocking(0)

byterecord = struct.Struct('B')
intrecord = struct.Struct('H')
floatrecord = struct.Struct('f')
global got_soc
got_soc = False
global got_volts
got_volts = False

completed = False

while not(completed):
    result = select.select([s],[],[])
    msg = result[0][0].recv(bufferSize)
    if msg[:3] == b'\x3a\x33\x3f':
      battery_soc=((float(byterecord.unpack(msg[32:33])[0])/2)-5) # byte -5% to 105% 0.5% per bit => /2 - 5
      got_soc = True
    if msg[:3] == b'\x3a\x32\x3e':
      battery_min = intrecord.unpack(msg[8:10])[0]/1000.0  #Uint16 x 1000
      battery_max = intrecord.unpack(msg[10:12])[0]/1000.0  #Uint16 x 1000
      battery_bypass_count = (byterecord.unpack(msg[33:34])[0])
      battery_volts = intrecord.unpack(msg[40:42])[0]/100.0  #Uint16 x 100
      battery_amps = floatrecord.unpack(msg[42:46])[0]/1000.0 #float4 x 1000
      got_volts = True
    completed = (got_volts and got_soc)

print ("soc%:",battery_soc)
print ("min:", battery_min)
print ("max:", battery_max)
print ("bypass:", battery_bypass_count)
print ("volts:",(battery_volts))
print ("amps:",(battery_amps))

Re: AVASS Battery order details

Posted: Tue, 23 Oct 2018, 21:26
by bigjsl
It produces output like this:
soc%: 79.0
min: 3.28
max: 3.32
bypass: 0
volts: 52.67
amps: -12.2866875

Re: Batrium BMS Monitoring

Posted: Tue, 23 Oct 2018, 22:18
by rhills
Hi John,

The topic you originally posted this in (AVASS Battery Order Details wasn't really the right place for it. That wasn't your fault as it had been starting to wander off the original subject anyway so I have now locked it.

I think your posts deserved their own topic, so I created one for them.

Cheers,

Re: Batrium BMS Monitoring

Posted: Wed, 24 Oct 2018, 08:48
by jonescg
Also, if you want to post code you can do it using this feature:

Code: Select all

Code code code {stuff}
More code more code more code
colon slash break curly braces etc.
Using the [c0de] blah [/code ] (with an 'o' instead of a zero, obviously)