I'm flattered to be asked, but I'm learning C/C++ and arduino myself. I can write functional code, but it's far from optimised or refined. I think you would be better asking on the arduino forums for this kind of thing.t6jay
i'm not a professional programmer, could you refine my code?
I have never seen a system that uses two different baud rates on one bus. But I can't see why it shouldn't work, you will need to stop and restart the serial every time you want to flip devices.I have to integrate this to my display. my other RS485 device is a epever and it run at 115200, I do not know if I can mix two connections with different speed on the same wires???
class RenogySmartBattery(minimalmodbus.Instrument):
def __init__(self, portname="/dev/ttyUSB0", slaveaddress=48, baudrate=9600, timeout=0.5):
minimalmodbus.Instrument.__init__(self, portname, slaveaddress)
self.serial.baudrate = baudrate
self.serial.timeout = timeout
def amps(self):
r = self.read_register(5042)
return r / 100.0 if r < 61440 else (r - 65535) / 100.0
def volts(self):
return self.read_register(5043) / 10.0
def capacity(self):
r = self.read_registers(5044, 2)
return ( r[0] << 15 | (r[1] >> 1) ) * 0.002
def max_capacity(self):
r = self.read_registers(5046, 2)
return ( r[0] << 15 | (r[1] >> 1) ) * 0.002
def percentage(self):
return self.capacity() / self.max_capacity() * 100
def state(self):
a = self.amps()
if a < 0: return "DISCHARGING"
elif a > 0: return "CHARGING"
return "IDLE"
Interesting, my battery node seems to be responding at node 0xf7... I have 2 LFPs connected in parallel with UP to LINK, and UP to RS485 tty (Also DCC50S in the remaining LINK port @ node 1). Don't seem able to assign a node / unit id in order to differentiate the batteries. Will have another go tomorrow and scan the address range again.capture between the batt and btoo, at 9600 n81
my battery node is 48 0x30
13:14:06.752 -> test2
13:14:10.080 -> 30, 3, 13, 88, 0, 11, 5, 49, 30, 3, 22, 0, 4, 0, 24, 0, 24, 0, 24, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13:14:10.455 -> 0, 0, 0, 0, C1, E4, 30, 3, 13, 99, 0, 5, 55, 43, 30, 3, A, 0, 3, 0, E6, 0, E6, 0, E6, 0, E6, 9D, 52, 30, 3, 13, B2, 0, 6, 65, 4A, 30, 3, C, 0,
13:14:10.877 -> 0, 0, 91, 0, 1, 86, 38, 0, 1, 86, 50, 5E, CD, 30, 3, 13, F0, 0, 4, 44, 9F, 30, 3, 8, 0, 0, 0, 0, 0, E, 0, A, 8F, EF, 30, 3, 14, A, 0, 2, E5,
13:14:11.298 -> D8, 30, 3, 4, 30, 30, 31, 34, C1, B8,
30, 3, 13, 88, 0, 11, 5, 49, 30, 3, 22, 0, 4, 0, 24, 0, 24, 0, 24, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13:14:19.313 -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, C1, E4, 30, 3, 13, 99, 0, 5, 55, 43, 30, 3, A, 0, 3, 0, E6, 0, E6, 0, E6, 0, E6, 9D, 52, 30, 3,
13:14:19.735 -> 13, B2, 0, 6, 65, 4A, 30, 3, C, 0, 0, 0, 91, 0, 1, 86, 38, 0, 1, 86, 50, 5E, CD, 30, 3, 13, F0, 0, 4, 44, 9F, 30, 3, 8, 0, 0, 0, 0, 0, E, 0,
13:14:20.110 -> A, 8F, EF, 30, 3, 14, A, 0, 2, E5, D8, 30, 3, 4, 30, 30, 31, 34, C1, B8,
One thing I noticed is that my IDs changed after I used the BT-2 bluetooth adapter with the new android app. After that my dcdc50 id changed so I suspect the app assigned reassigned individual ids. I had to scan, too, in order to find the remapped ids (I only have one battery though).Don't seem able to assign a node / unit id in order to differentiate the batteries.
Sadly I have no bluetooth hardware to snoop on. For the moment I have just attached one battery to the modbus network, and just using the SOC from there (Should be automatically balanced from the batteries BMS no?)One thing I noticed is that my IDs changed after I used the BT-2 bluetooth adapter with the new android app. After that my dcdc50 id changed so I suspect the app assigned reassigned individual ids. I had to scan, too, in order to find the remapped ids (I only have one battery though).
So if you have the hardware, connect both batteries and the dcdc50 to the bluetooth hub + bt2 and use the app once.
What do you mean by a scanner?Integrating my renogy batteries into my monitoring system is my next milestone. What are you using for an RS485 cable? I have a generic one and used a modbus scanner but didn't find anything.
Surely that's like throwing darts in the dark.This is what I was using:
Watching it work it looks like it iterates through each slave address and looks for a response. Is there a better way to go about it?
Surely that's like throwing darts in the dark.
You need the comms specification (9600,8,N,1 or whatever) a node address, and a valid address to read. One of the other contributors on here will have these for a battery I'm sure. (I only have DCC50S which is Node 1 9600,8,n,2)