Hi,
I'm trying to use a Raspberry PI as a datalogger for Eastron SDM630 values. I would like to calculate energy production from my solar system, and steer energy consumption accordingly.
Hardware: Raspberry PI 3A+, Modbus RS485 USB 2.0 Adapter with CH340 chip, on USB HUB with keyboard and mouse.
The CRC fails continuously (has not succeeded once).
Even BinaryPayloadBuilder gives a CRC error.
The python program I use:
#!/usr/bin/env python
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
Import logging
logging.basicConfig(filename='mat3.log',level=logging.DEBUG)
#---------------------------------------------------------------------------#
# Connect info KW/H meter
#---------------------------------------------------------------------------#
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', baudrate=9600, timeout=0.5)
client.connect()
builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Little)
builder.add_string('abcdefgh')
builder.add_32bit_float(22.34)
builder.add_16bit_uint(0x1234)
builder.add_8bit_int(0x12)
builder.add_bits([0,1,0,1,1,0,1,0])
payload = builder.build()
address = 0x01
result = client.write_registers(address, payload, skip_encode=True)
# Read data and convert to float
print "L1\n",
result = client.read_input_registers(0x00, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
print decoder.decode_32bit_float(), "V \n",
result = client.read_input_registers(0x06, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
print decoder.decode_32bit_float(), "A \n",
result = client.read_input_registers(0x0C, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
print decoder.decode_32bit_float(), "W \n",
# More of the same read_input_registers stuff, ….
client.close()
Output from logging is:
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x10 0x0 0x1 0x0 0x8 0x10 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0xb8 0x52 0x41 0xb2 0x12 0x34 0x12 0x5a 0x99 0xc4
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0xdf 0xff 0xfd 0xff 0xef
DEBUG:pymodbus.framer.rtu_framer:CRC invalid, discarding header!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer - 0xdf 0xff 0xfd 0xff 0xef
DEBUG:pymodbus.framer.rtu_framer:Frame check failed, ignoring!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer -
DEBUG:pymodbus.transaction:Getting transaction 0
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.transaction:Running transaction 2
DEBUG:pymodbus.transaction:SEND: 0x0 0x4 0x0 0x0 0x0 0x2 0x70 0x1a
DEBUG:pymodbus.framer.rtu_framer:Changing state to IDLE - Last Frame End - 1556653093.52, Current Time stamp - 1556653093.52
DEBUG:pymodbus.framer.rtu_framer:Waiting for 3.5 char before next send - 4.01 ms
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
WARNING:pymodbus.client.sync:Cleanup recv buffer before send: 0xdf 0x3d 0x3b 0x39 0x37 0x35 0x33 0x31 0x2f 0x8f 0xab 0x6d 0xb6 0x97 0xdb 0x4b 0xcd 0x7
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0xf7 0xff 0xff 0xff 0xfb
DEBUG:pymodbus.framer.rtu_framer:CRC invalid, discarding header!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer - 0xf7 0xff 0xff 0xff 0xfb
DEBUG:pymodbus.framer.rtu_framer:Frame check failed, ignoring!!
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer -
DEBUG:pymodbus.transaction:Getting transaction 0
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
I read some of the messages on SDM630 in this group and see that people are able to read the SDM630 with a similar configuration, so all hope is not yet lost.
Some of the things I tried, without success:
1) Added extra information for stopbits, bytesize and parity to the client
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', stopbits=1, bytesize=8, timeout=0.5, baudrate=9600, parity='N')
2) Tried other options like 2 stopbits, even parity, odd parity and changed the settings on the SDM630
3) Changed the timeout from 0.25 to 0.5
4) Reversed A and B. I saw a message on this Google group that somebody else solved his CRC error this way. For me it didn't work: debug log is still exactly the same. Modbus is completely new for me, and so is Python, debug output and the hex values that it contains.
I read the EastronSDM630 Smart Meter Modbus Protocol Implementation manual, but I don't understand much of it.
5) Removed the USB hub and connected the RS485 USB directly on the Raspberry USB port.
Hope somebody can help me?