Getting data from inverters via an RS485 connection

Ok not getting anywhere with the new adapter either, same error:

MinimalModbus debug mode. Create serial port /dev/ttyUSB0
here 0
MinimalModbus debug mode. Will write to instrument (expecting 9 bytes back): '\n\x04\x0b¼\x00\x02³p' (0A 04 0B BC 00 02 B3 70)
MinimalModbus debug mode. Clearing serial buffers for port /dev/ttyUSB0
MinimalModbus debug mode. No sleep required before write. Time since previous read: 999826.58 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: '' () (0 bytes), roundtrip time: 201.7 ms. Timeout for reading: 200.0 ms.

That is form pi zero python code.
Code:

import minimalmodbus
import socket
import serial

###		PROGRAM FLOW:
###			- Collect Data from Solis-4G inverter
###			- Convert to individual bytes
###			- Construct 2 messages 
###				- KWH Totals only sent when inverter is running, so they are not reset to zero
###				- All other 'live' data set to zero when inverter shuts down
###			- Send Packets to EMONHUB
###	
###		EmonHub Node IDs:
###			- NodeID 3: All time energy KWH	/ Today KWH (not sent overnight)
###			- NodeID 4: Live Data Readings - Zeros sent overnight 


### COLLECT DATA FROM SOLIS-4G INVERTER ###

instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 10, debug = True) # port name, slave address 

instrument.serial.baudrate = 9600   # Baud
instrument.serial.bytesize = 8
instrument.serial.parity   = serial.PARITY_NONE
instrument.serial.stopbits = 1
instrument.serial.timeout  = 0.2   # seconds

success = False # Intialise Success/Failure Flag to ensure full data is only uploaded if all data is received.

try:
	print("here 0")
	Realtime_ACW = instrument.read_long(3004, functioncode=4, signed=False)	#Read AC Watts as Unsigned 32-Bit
	print("here 1")
	Realtime_DCV = instrument.read_register(3021, numberOfDecimals=0, functioncode=4, signed=False) #Read DC Volts as Unsigned 16-Bit
	Realtime_DCI = instrument.read_register(3022, numberOfDecimals=0, functioncode=4, signed=False) #Read DC Current as Unsigned 16-Bit
	Realtime_ACV = instrument.read_register(3035, numberOfDecimals=0, functioncode=4, signed=False) #Read AC Volts as Unsigned 16-Bit
	Realtime_ACI = instrument.read_register(3038, numberOfDecimals=0, functioncode=4, signed=False) #Read AC Current as Unsigned 16-Bit
	Realtime_ACF = instrument.read_register(3042, numberOfDecimals=0, functioncode=4, signed=False) #Read AC Frequency as Unsigned 16-Bit
	Inverter_C = instrument.read_register(3041, numberOfDecimals=0, functioncode=4, signed=True) #Read Inverter Temperature as Signed 16-Bit
	
	AlltimeEnergy_KW = instrument.read_long(3008, functioncode=4, signed=False) # Read All Time Energy (KWH Total) as Unsigned 32-Bit 
	Today_KW = instrument.read_register(3014, numberOfDecimals=0, functioncode=4, signed=False) # Read Today Energy (KWH Total) as 16-Bit
    
	##Convert Data to Bytes
	A1 = Realtime_ACW % 256
	A2 = (Realtime_ACW >> 8) % 256
	A3 = (Realtime_ACW >> 16) % 256
	A4 = (Realtime_ACW >> 24) % 256

	B1 = AlltimeEnergy_KW % 256
	B2 = (AlltimeEnergy_KW >> 8) % 256
	B3 = (AlltimeEnergy_KW >> 16) % 256
	B4 = (AlltimeEnergy_KW >> 24) % 256

	C1 = Today_KW % 256
	C2 = (Today_KW >> 8) % 256

	D1 = Realtime_DCV % 256
	D2 = (Realtime_DCV >> 8) % 256

	E1 = Realtime_DCI % 256
	E2 = (Realtime_DCI >> 8) % 256

	F1 = Inverter_C % 256
	F2 = (Inverter_C >> 8) % 256

	G1 = Realtime_ACF % 256
	G2 = (Realtime_ACF >> 8) % 256

	H1 = Realtime_ACV % 256
	H2 = (Realtime_ACV >> 8) % 256

	I1 = Realtime_ACI % 256
	I2 = (Realtime_ACI >> 8) % 256

    ##Flag to stream all data to EmonHub
	success = True    

except:
	##EXCEPTION WILL OCCUR WHEN INVERTER SHUTS DOWN WHEN PANELS ARE OFF

	A1 = 0
	A2 = 0
	A3 = 0
	A4 = 0

	## Not sent when inverter turns off
	## B1 = 0
	## B2 = 0
	## B3 = 0
	## B4 = 0
	
	## C1 = 0
	## C2 = 0
	## END NOT SENT WHEN INVERTER TURNS OFF

	D1 = 0
	D2 = 0
	
	E1 = 0
	E2 = 0

	F1 = 0
	F2 = 0

	G1 = 0
	G2 = 0

	H1 = 0
	H2 = 0
	
	I1 = 0
	I2 = 0	
	
	print("inside exception")
	##Flag to stream restricted data to EmonHub
	success = False

### END COLLECT DATA FROM SOLIS-4G INVERTER ###

	
### STREAM RESULT TO EMONHUB ###
#s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Initialise Socket
#s.connect(('192.168.0.238', 8123)) #Connect to Local EmonHub

## NOT SENT WHEN INVERTER TURNS OFF
#if success == True:
#	s.sendall('03 ' + str(B1) + ' ' + str(B2) + ' ' + str(B3) + ' ' + str(B4) + ' ' + str(C1) + ' ' + str(C2) + '\r\n')

#s.sendall('04 ' + str(A1) + ' ' + str(A2) + ' ' + str(A3) + ' ' + str(A4) + ' ' + str(D1) + ' ' + str(D2) + ' ' + str(E1) + ' ' + str(E2) + ' ' + str(F1) + ' ' + str(F2) + ' ' + str(G1) + ' ' + str(G2) + ' ' + str(H1) + ' ' + str(H2) + ' ' + str(I1) + ' ' + str(I2) + '\r\n')
#s.close()
### END SEND TO EMON HUB #

Either the code is no good for a Solis 5G inverter or the adapter/pi doesn’t work or the wiring is not right but it’s hard to get wrong the wiring, pins 3 and 4 on the inverter and A and B on the usb adapter (tried the other way around just in case)
I wish I had a way to confirm that the adapter actually works right or get some sort of response from the inverter

You use it to query your inverter.
Your Windows laptop machine is the master and the inverter is the slave.

Here’s a screenshot of it set up to read my WattNode via an adapter like the one you have, on COM7:

As an example, I’ve pluggd in register address 3021 and set the display option to integer.

Ok @Bill.Thomson set it up like that and nothing but errors on device 1

Wiring is ok because if I swap A and B it times out. Any ideas?

Did you set up the connection?

I forgot to mention you have to click on Connection -> Connect to get it started.
Sorry 'bout that. :wink:

Yes like so:

OK.
COM7 is the port my adapter is on.
You’ll need to change that to the port your adapter is on. (unless of course, it’s on COM7) :grin:

Yes mine is on com7 also, and I can see tx/rx values changing at the bottom so something is happening

Here’s what it looks like when it’s talking to the slave device:

One other thing to try…

After you click Connection -> Disconnect

Under the Connection -> Settings menu change to `Register number (starting from 1)

then reconnect.

Ok tried that too no luck and the program doesn’t give any useful debug info to see what the errors mean.
Maybe they updated something in this new generation and it just doesn’t talk to modbus correctly, which I doubt since the wifi logger is of course using it
Also, isn’t the inverter the master and I need to be the slave? Not the other way around?

Have you tried changing Input Registers to Holding Registers?
Don’t forget to disconnect, change, then reconnect…

No… The inverter is the slave and the device making the queries is the master.

In the inverter rs485 menu I see this:
Baud rate: 9600
Parity None
Data bits: 8
Stop bit: 1

Not seeing data bits option in this app

True, it’s not shown, but it’s an 8-bit app. It’s working like a champ on my WattNode as I write this and the WattNode uses 8-bit comms.

Could be many different things, adapter is bad, inverter doesn’t like it, no GND, etc
Will try and get modbus documentation from Solis (if they have any) but doubt that will help since I can’t get any data back

Did you try the holding registers?
Usually RS-485 works with just 2 wires, but you may indeed need a ground.

Yup no change with holding registers or changing the start from 0 to 1.
Well this adapter doesn’t have gnd on it so cannot try it.
Might try ordering the 3 pin one and see if it works, thanks for the help :slight_smile:

OK that app should work - there are no significant changes in the inverter registers from 4G to 5G

So go back to basics here

(i have not used that app but looks fairly straight forward)

You should be looking at holding registers.

Based on this document

Solis 3phase 4G Modbus registers.pdf (505.0 KB)

Show us some pics of the Rpi, RS485 adapter up close with wiring etc and how you have connected it to the inverter

Craig

Here’s a way to do the same thing via puTTY, without pageant:

https://www.oueta.com/windows-third-party/ssh-auto-login-with-putty-from-windows/

1 Like

So on the rpi I had it connected to A/B and then one of the ground pins on the GPIO


This new adapter just came in today and I will try it out shortly, wired it like so:


Will report back once I get it tested.