reaper7 / SDM_Energy_Meter

reading SDM72 SDM120 SDM220 SDM230 SDM630 modbus energy meters from arduino (esp8266, esp32, avr)
245 stars 97 forks source link

Stupid sdm120 from Aliexpress [solved] #16

Closed da3020 closed 6 years ago

da3020 commented 6 years ago

Hi guys. I've bought SDM120 power meter on Aliexpress. It has no any suffixes at label. Just SDM120. Looks exactly like this. I have spend three days trying to connect it to Arduino Mega and parsed four different librarys before I've understood one really despicable thing. The item is that it has OWN undocumented protocol. I vave found original protocol on the manufacturer's website. But meter from Aliexpress did not match this.

When i send for example, voltage request:
01 04 00 00 00 02 71 CB

the meter  response like:
00 01 04 04 43 66 E6 66 C4
00 01 04 04 43 66 B3 33 3B
00 01 04 04 43 66 CC CD 9A
and so on ...
00 01 04 04 43 xx xx xx xx

So, it seams like first byte is missing and response starts from second byte. And really - if I interpret b4-b7 bytes like the value then it works! Code needs to be changed like:

((uint8_t*)&res)[3]= sdmarr[4];
((uint8_t*)&res)[2]= sdmarr[5];
((uint8_t*)&res)[1]= sdmarr[6];
((uint8_t*)&res)[0]= sdmarr[7];

and error checks need to be redused. But I don't know what the last byte meens.


I have found interesting thing now. If I cut first and last bytes from response and calculate CRC for remaining bytes on this website then last byte of CRC-16 (modbus) value is ALWAYS equal to cutted last byte from response. See screenshot

Is it any simplified CRC byte? Does anybody knows?


Hi again! I have serious reasons to believe that rs485-ttl convertor is the reason of my fault. Yes!!! It need to remove R7 resistor from rs485 to TTL convertor!

nicklasharaldsson commented 6 years ago

I'm having similar problems.

I have this rs232 <-> rs485 converter: https://www.sparkfun.com/products/10124

If i remove one byte in the beginning and end of response it works fine. But for some reason i get a trailing and leading zero on every response.

My fix is to just throw these away before we parse the response.

I have installed 120 ohm resistors, tried to change the 220 ohm smd resistor on the module with a 120 ohm resitor but still get the same results.

I am using softwareserial and ESP8266 on an nodemcu 0.9.

Don't know if this is a bug of this library, probably more lika a hardware issue. But it might help others coming here.

MinionDiv commented 2 years ago

RS485 RTU SDM120*** Connec modbus fail. REG >>> 0 Connec modbus fail. REG >>> 6 Connec modbus fail. REG >>> C Connec modbus fail. REG >>> 1E Connec modbus fail. REG >>> 46 Connec modbus fail. REG >>> 156

Voltage = 0.00 VAC Current = 0.00 Amps Active Power= 0.00 Watts Power Factor = 0.00 Frequency = 0.00 Hz Total Active Energy = 0.00 kWh Connec modbus fail. REG >>> 0 Connec modbus fail. REG >>> 6 Connec modbus fail. REG >>> C Connec modbus fail. REG >>> 1E Connec modbus fail. REG >>> 46 Connec modbus fail. REG >>> 156

is it due to my convertor problem?