This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connect Victron Battery monitor to Openplotter SignalK?
#1
I ask for help on how data can be read in the Victron battery monitor and send them to SignaK Openplotter of using this software?
http://www.jeperez.com/online-monitor-vi...-bmv-602s/
  Reply
#2
(03-22-2017, 06:00 AM)kste Wrote: I ask for help on how data can be read in the Victron battery monitor and send them to SignaK Openplotter of using this software?
http://www.jeperez.com/online-monitor-vi...-bmv-602s/

You are on the right way. I tried to emulate the bmv-600 (with a fixed string) and used this code for sending it to SignalK. (I didn't test it with a real bmv-600 so there will be many errors. Perhaps you can combine this code with the one you found.)
Code:
#!/usr/bin/python
#victron BMV600S

import signal, sys, time, socket, datetime, subprocess, math, serial, re

# Control-C signal handler to suppress exceptions if user presses Control C
# This is totally optional.
def signal_handler(sig, frame):
   print('You pressed Ctrl+C!!!!')
   sys.exit(0)
   
# init
signal.signal(signal.SIGINT, signal_handler)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ser = serial.Serial('/dev/ttyOP_LEONARDO', 19200, timeout=2)
ser.flush()

ValueH1 = 0
ValueH2 = 0
ValueH3 = 0
ValueH4 = 0
ValueH5 = 0
ValueH6 = 0
ValueH7 = 0
ValueH8 = 0
ValueH9 = 0
ValueH10 = 0
ValueH11 = 0
ValueH12 = 0
ValueV = 0
ValueI = 0
ValueCE = 0
ValueSOC = 0
ValueTTG = 0
ValueALARM = 0
ValueRELAY = 0
ValueAR = 0

error = False
i = 0

def safefloat(value,line):
   if re.match('^-?[0-9]+$', line):
       value = float(line)
   return value

# forever loop until user presses Control-C
while 1:
   i += 1
   serLine = ser.readline().split()
   #print serLine,len(serLine)
   
   if len(serLine) == 2:
   
       if 'H1' == serLine[0]:
           ValueH1 = safefloat(ValueH1,serLine[1])/100
           print 'H1 dpst DOD ',ValueH1
       elif 'H2' == serLine[0]:
           ValueH2 = safefloat(ValueH2,serLine[1])/100
           print 'H2 lst DOD ',ValueH2
       elif 'H3' == serLine[0]:
           ValueH3 = safefloat(ValueH3,serLine[1])/100
           print 'H3 avg DOD ',ValueH3
       elif 'H4' == serLine[0]:
           ValueH4 = safefloat(ValueH4,serLine[1])/100
           print 'H4 cycles ',ValueH4
       elif 'H5' == serLine[0]:
           ValueH5 = safefloat(ValueH5,serLine[1])/100
           print 'H5 FD ',ValueH5
       elif 'H6' == serLine[0]:
           ValueH6 = safefloat(ValueH6,serLine[1])/100
           print 'H6 Tot.AH ',ValueH6
       elif 'H7' == serLine[0]:
           ValueH7 = safefloat(ValueH7,serLine[1])/100
           print 'H7 Min V ',ValueH7
       elif 'H8' == serLine[0]:
           ValueH8 = safefloat(ValueH8,serLine[1])/100
           print 'H8 Max V ',ValueH8
       elif 'H9' == serLine[0]:
           ValueH9 = safefloat(ValueH9,serLine[1])/100
           print 'H9 day aft. full ',ValueH9
       elif 'H10' == serLine[0]:
           ValueH10 = safefloat(ValueH10,serLine[1])/100
           print 'H10 Sync ',ValueH10
       elif 'H11' == serLine[0]:
           ValueH11 = safefloat(ValueH11,serLine[1])/100
           print 'H11 Low V al ',ValueH11
       elif 'H12' == serLine[0]:
           ValueH12 = safefloat(ValueH12,serLine[1])/100
           print 'H12 High V al. ',ValueH12

       elif 'V' == serLine[0]:
           ValueV = safefloat(ValueV,serLine[1])/1000
           print 'V ',ValueV
       elif 'I' == serLine[0]:
           ValueI = safefloat(ValueI,serLine[1])/1000
           print 'I ',ValueI
       elif 'I' == serLine[0]:
           if ('---' in serLine) == False:
               ValueCE = safefloat(ValueCE,serLine[1])/1000
               print 'CE ',ValueCE
       elif 'SOC' == serLine[0]:
           if ('---' in serLine) == False:
               ValueSOC = safefloat(ValueSOC,serLine[1])/10
               print 'SOC ',ValueSOC
       elif 'TTG' == serLine[0]:
           if ('---' in serLine) == False:
               ValueTTG = safefloat(ValueTTG,serLine[1])/10
               print 'TTG ',ValueTTG
       elif 'ALARM' == serLine[0]:
           if 'OFF' in serLine:
               ValueALARM = '0'
           else:
               ValueALARM = '1'

   if i >= 24:
       print 'send'
       SignalK = '{"updates": [{"source": {"type": "BAT","src" : "BMV601"},"values":['
       SignalK += '{"path": "electrical.batteries.main.voltage","value":'+str(round(ValueV, 2))+'}'
       SignalK += ',{"path": "electrical.batteries.main.current","value":'+str(round(ValueI, 2))+'}'
       SignalK += ',{"path": "electrical.batteries.main.capacity.stateOfCharge","value":'+str(ValueSOC)+'}'
       SignalK += ',{"path": "electrical.batteries.main.capacity.timeRemaining","value":'+str(round(ValueTTG, 1))+'}'
       SignalK += ']}]}\n'
       sock.sendto(SignalK, ('localhost', 55559))
       i = 0
       time.sleep(.500)
  Reply
#3
Super e-sailing the code works!
It just needs to put the right name to the USB port.
I now have the data of Victron BMV700 viewable through Openplotter
Thank you!
Smile
  Reply
#4
Forgive the stupid question that follows
I have used the python code as supplied above (thanks e-sailing!!!) with the right name for the USB port and the data shows up in signalK.
How can this be integrated with OpenPlotter? In order for the python code to see the data, the OpenPlotter NMEA0183 tab device that receives the data needs to be unselected which it seems could cause an issue down the road. If the data channel is selected as active in the NMEA0183 tab then the python program reports an error.
So I guess the question is, how can this be integrated into OpenPlotter without seeming to be a kludge? Is this something that Sailoog would have to do (a feature request) or is this something a mere human with limited programming knowedge can do ?
  Reply
#5
It isn't nmea0183. So nothing to do with nmea0183 tab.
The program converts the data directly to signalk and sends it to the signalk server. So everything is fine.
When you want to integrate it (autostart on boot + stop + start) you can add it in openplotter.conf in the same way as it is done with autosetup_tty.py.
Move your file into the /home/pi/.config/openplotter/tools folder.
Have a look at Help->OpenPlotter offline documentation "OP menu Tools"->"Tools defined"
  Reply
#6
Excellent! I will look into it ...... Thanks!
  Reply
#7
Works perfectly ! Thanks again !
  Reply
#8
Hello!

I'm planning to buy myself a BMV-702, what do you use to connect it to the RPi, the original (rather pricey) "Victron VE.Direct - USB Interface" ??
Regards, 
Arne :-)    
S/Y Tiarora
  Reply
#9
(12-27-2017, 02:17 PM)Arne Wrote: Hello!

I'm planning to buy myself a BMV-702, what do you use to connect it to the RPi, the original (rather pricey) "Victron VE.Direct - USB Interface" ??

I use an arduino with the basic software serial sketch.
  Reply
#10
(12-27-2017, 07:46 PM)PaddyB Wrote:
(12-27-2017, 02:17 PM)Arne Wrote: I'm planning to buy myself a BMV-702, what do you use to connect it to the RPi, the original "Victron VE.Direct - USB Interface" ??

I use an arduino with the basic software serial sketch.

But how have you connected the BMV-instrument to your Arduino?
Regards, 
Arne :-)    
S/Y Tiarora
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)