EASTRON SDM120C - RS485 Modbus meter

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sat Feb 07, 2015 12:25 pm

I had much luck with Gianfrdp scripts. Also make sure you didn't invert a/b wires and put a 120ohm resistor at the end of the bus.

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Wed Feb 11, 2015 4:47 pm

Hi Gianfrdp,
Would it be possible to end the SDM120 data frame with an 'OK' or something like aurora ? That would require to check if the modbus request is correct. It would allow to validate if the data have been returned successfully.
Here's a log of my export meter :
20150211 16:55 EEXP(21401*Wh) 21401
20150211 17:00 EEXP(21401*Wh) 21401
20150211 17:05 EEXP(227.39*Wh) 227
The data have mess up with the voltage :?
Grazie

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Wed Feb 11, 2015 9:44 pm

I will try with this one to see if all data are returned

Code: Select all

#!/bin/bash

ADDRESSES="$1"
BAUD_RATE="$2"
DEVICE="$3"

ADDR_ARR=$(echo $ADDRESSES | tr "," "\n")

while [ true ]; do

    ID=0
    POWER=""
    ENERGY=""

    for ADDRESS in $ADDR_ARR
    do
	#((ID++))
	ID=$ADDRESS
	CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -p -v -c -f -g -e -i -t -q ${DEVICE}"
	
	VALUE=`$CMD`

	VOLTAGE=$(echo ${VALUE} | cut -d\  -f1)
	CURRENT=$(echo ${VALUE} | cut -d\  -f2)
	POWER=$(echo ${VALUE} | cut -d\  -f3)
	POWERFACTOR=$(echo ${VALUE} | cut -d\  -f4)
	FRQ=$(echo ${VALUE} | cut -d\  -f5)
	ENERGYIMPORT=$(echo ${VALUE} | cut -d\  -f6)
	ENERGYEXPORT=$(echo ${VALUE} | cut -d\  -f7)
	ENERGYTOT=$(echo ${VALUE} | cut -d\  -f8)

	if [ ! -v ENERGYTOT ]
	then
	    timestamp=$(date +"%Y-%m-%d %H:%M:%S")
	    echo "Last variable is unset >> /tmp/485meter.err"
	elif [ -z "$ENERGYTOT" ]
	then
	    timestamp=$(date +"%Y-%m-%d %H:%M:%S")
	    echo "Last variable is set to an empty string >> /tmp/485meter.err"
	else
	   #echo "Variable is set to some string"
            echo -e "$ID($VOLTAGE*V)\n$ID($CURRENT*A)\nTOT($POWER*W)\n$ID($POWERFACTOR*F)\n$ID($FRQ*Hz)\nEIMP($ENERGYIMPORT*Wh)\nEEXP($ENERGYEXPORT*Wh)\nETOT($ENERGYTOT*Wh)" > /tmp/485metern${ADDRESS}.txt
	fi

	#sleep 1s
	#sleep 0.5
    done

done
Another idea is simply to put each value in a different tmp file ;)

ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by ninodifr » Fri Feb 13, 2015 1:09 pm

hi, jeanmarc
put the values in different file tmp would not solve the problem
the value is lost during the reading of data
ex. request val 1, 2, 3, 4, 5
Answer val 1, 2, 4, 5
in this case it is lost the value 3, and then the value 4 has taken the place of the value 3 and the value 5 to the value 4.
the solution would be to do a reading for every single value or check if the required values are read all, if the returned values are not all unwrapped reading
with two values required (power and total energy) we have already tried with gianfrdp and it works.

Code: Select all

#!/bin/bash
ADDRESSES="$1"
BAUD_RATE="$2"
DEVICE="$3"
ADDR_ARR=$(echo $ADDRESSES | tr "," "\n")
while [ true ]; do
ID=0
POWER=""
ENERGY=""
for ADDRESS in $ADDR_ARR
do
#((ID++))
ID=$ADDRESS
CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -z 10 -i -p -q ${DEVICE}"
#echo $CMD
VALUE=`$CMD`
POWER=$(echo ${VALUE} | cut -d\ -f1)
ENERGY=$(echo ${VALUE} | cut -d\ -f2)
if [ "$ENERGY" != "0" -a x"$ENERGY" != x -a "$POWER" != "0" -a x"$POWER" != x ]; then
echo -e "$ID($POWER*W)\n$ID($ENERGY*Wh)" > /run/shm/metern${ADDRESS}.txt
#echo -e "$VALUE" > /run/shm/metern${ADDRESS}.txt
fi
sleep 5s
done
done

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Fri Feb 13, 2015 2:04 pm

Hi,
Well i suck at bash scripting but my example above only fill the file if the 8th and last value (ENERGYTOT) is set to a string. If the data is 1 2 4 5 6 7 8, it won't work, but.. i unsuccessfully try it. :x

For now, i have write a stupid php file, that kill the daemon pooling, then request one value at a time.
I do that for ENERGYIMPORT and ENERGYEXPORT. Once it is done, i restart the daemon for live things.

It is ain't neat but, so far, it seem reliable. Previously, it happen that ENERGYIMPORT/EXPORT takes the voltage value.
I'am not sure but I believe the meter or the modbus library return bad data :?
Maybe it would be possible to check within SDM120C script if data are valid and if the whole rows is correct, end up with an OK ?

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Sun Feb 15, 2015 10:30 am

I will try to add a check if all requested values are returned correctly

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sun Feb 15, 2015 2:58 pm

Thanks :)
Meanwhile, I end up with this

Code: Select all

#!/bin/bash

ADDRESS="$1"
BAUD_RATE="$2"
DEVICE="$3"
CNT=0

while [ true ]; do

	VOLTAGE=""
	CURRENT=""
	POWER=""
	CURRENT=""
	POWERFACTOR=""
	FRQ=""

	CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -p -v -c -f -g -e -i -t -q ${DEVICE}"
	VALUE=`$CMD`

	VOLTAGE=$(echo ${VALUE} | cut -d\  -f1)
	CURRENT=$(echo ${VALUE} | cut -d\  -f2)
	POWER=$(echo ${VALUE} | cut -d\  -f3)
	POWERFACTOR=$(echo ${VALUE} | cut -d\  -f4)
	FRQ=$(echo ${VALUE} | cut -d\  -f5)

	if [ "$VOLTAGE" != "0" -a x"$VOLTAGE" != x -a "$CURRENT" != "0" -a x"$CURRENT" != x -a "$POWER" != "0" -a x"$POWER" != x -a "$POWERFACTOR" != "0" -a x"$POWERFACTOR" != x -a "$FRQ" != "0" -a x"$FRQ" != x ]; then
	ID=$ADDRESS
		echo -e "$ID($VOLTAGE*V)\n$ID($CURRENT*A)\nTOT($POWER*W)\n$ID($POWERFACTOR*F)\n$ID($FRQ*Hz)" > /tmp/485live.txt
	fi
	CNT=$((CNT + 1))

	if [ "$CNT" -ge 10 ]; then
		ENERGYIMPORT=""
		ENERGYEXPORT=""
		sleep 1s	
		CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -i -q -z3 ${DEVICE}"
		VALUE=`$CMD`
		ENERGYIMPORT=$(echo ${VALUE} | cut -d\  -f1)
		VALUE=""
		sleep 1s
		CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -e -q -z3 ${DEVICE}"
		VALUE=`$CMD`
		ENERGYEXPORT=$(echo ${VALUE} | cut -d\  -f1)

		if [ "$ENERGYIMPORT" != "0" -a x"$ENERGYIMPORT" != x -a "$ENERGYEXPORT" != "0" -a x"$ENERGYEXPORT" != x ]; then
			echo -e "EIMP($ENERGYIMPORT*Wh)\nEEXP($ENERGYEXPORT*Wh)" > /tmp/485metern.txt
		fi
		CNT=0
	fi
	#sleep 0.5
done

ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by ninodifr » Sun Feb 15, 2015 4:32 pm

the idea is good
But it makes no sense to ask 8 values and make the control of 5
or take control of all 8 values required or remove (-i -e -t)
because we will ask them later with separate control

perhaps it would be enough to control only the last value required
8 values and ask if we lose one, the value 8 will be empty
if you ask five values and we lose one, the value 5 will be empty
even if you lose, for example the value 3, the values will slip and will always miss the last value

AlbertoRuga
Posts: 36
Joined: Sat Jan 18, 2014 10:46 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by AlbertoRuga » Sun Feb 15, 2015 6:38 pm

hello, thank you for the interesting article, I tried to run it on mip rapberry but gives me this error TERM = xterm-256color: No such file or directory "I Do I login via ssh.

could you help me?

Thank You


Alberto Ruga

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sun Feb 15, 2015 7:54 pm

Well, could you give more details ? What commands did you type ?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest