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 » Thu Jan 22, 2015 6:31 pm

What is more interesting are the EN norms, in this case EN 61326-1 (about EMC it seems) and EN 61010-1 (about tension range).
There plenty norms: some are country specific VDS, NBN, NF, etc.. EN is European, IEC is international. Norms is a real mess ;) But, seriously the CE mark mean nothing.
That said, I think the Eastron products are safe, i awaiting my SDM220 ;)

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Tue Jan 27, 2015 9:28 pm

Hi,
I am trying to install your SDM120C but i'am stuck at compiling (i suck at bash :roll: )

I am installing on a Arch Linux ARM device, i installed libmodbus-3.1.1 and pkgconfig and I have to add in the Makefile :

Code: Select all

export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
..
But still get error

Code: Select all

[root@plugbox SDM120C-master]# make clean && make
rm -f *.o sdm120c
gcc -c -o sdm120c.o sdm120c.c `pkg-config --cflags libmodbus`
gcc -o sdm120c sdm120c.o `pkg-config --libs libmodbus`
[root@plugbox SDM120C-master]# 
[root@plugbox SDM120C-master]# ./sdm120c 
./sdm120c: error while loading shared libraries: libmodbus.so.5: cannot open shared object file: No such file or directory
[root@plugbox SDM120C-master]# ls -l /usr/local/lib/
total 124
-rwxr-xr-x 1 root root    920 Jan 27 20:49 libmodbus.la
lrwxrwxrwx 1 root root     18 Jan 27 20:49 libmodbus.so -> libmodbus.so.5.1.0
lrwxrwxrwx 1 root root     18 Jan 27 20:49 libmodbus.so.5 -> libmodbus.so.5.1.0
-rwxr-xr-x 1 root root 114556 Jan 27 20:49 libmodbus.so.5.1.0
drwxr-xr-x 2 root root   4096 Jan 27 20:49 pkgconfig
Any hints ? :)

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Tue Jan 27, 2015 9:37 pm

ok just done a

Code: Select all

export LD_RUN_PATH=/usr/local/lib
:)
[root@plugbox SDM120C-master]# ./sdm120c -a1 -v -b 9600 /dev/ttyUSB1
Voltage: 227.96 V
Thanks :D

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Wed Jan 28, 2015 10:44 am

Hi,
I've been playing with SDM220, it work with the same application (thanks)

But I had a problem with pooler485.sh on arch linux, the /tmp (tmpfs) is not available for the http user.

Code: Select all

[root@plugbox SDM120C]# find /tmp -name *metern*
/tmp/systemd-private-0ce0d2ebbf6e4dce967b54b528e0e6d8-php-fpm.service-m3sDFb/tmp/485metern1.txt
/tmp/systemd-private-0ce0d2ebbf6e4dce967b54b528e0e6d8-php-fpm.service-m3sDFb/tmp/metern.txt
So i had the idea to launch the application by the http user at meterN startup. In the next release i'll add a scripts/comappsdaemon.php file where you can put any daemon.

Code: Select all

<?php
// Startup of the com apps daemon if needed
$output = shell_exec('pkill -f pooler485 > /dev/null 2>&1 &');
sleep(1);
$output = shell_exec('pooler485 1 9600 /dev/ttyUSB1 > /dev/null 2>/dev/null &');
?>
Now i can retrieve values with a simple more /tmp/485metern1.txt | egrep "^1\(" | grep "*Wh)"
I also change your script a bit to get all values

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`
#echo $VALUE
	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 [ "$ENERGY" != "0" -a x"$ENERGY" != x ]; then
	if [ true ]; then
	    echo -e "$ID($VOLTAGE*V)\n$ID($CURRENT*A)\n$ID($POWER*W)\n$ID($POWERFACTOR*F)\n$ID($FRQ*Hz)\nEEXP($ENERGYIMPORT*Wh)\nEIMP($ENERGYEXPORT*Wh)\nETOT($ENERGYTOT*Wh)" > /tmp/485metern${ADDRESS}.txt
	fi
	sleep 1s

    done

done
Neat 8-)

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Thu Jan 29, 2015 9:10 am

Hello,
I'm happy it's useful for you :D.
I noted that ModBus instuctions are the same for every Eastron meter.
On the 3-phase versions there are more registers to read, obviously, but for the first phase are the same.

You can also use

Code: Select all

pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -q /dev/ttyUSB0
226.60 0.39 87.90 0.99 49.95 5502 0 5502
pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -m /dev/ttyUSB0
2(226.50*V)
2(0.38*A)
2(87.70*W)
2(0.99*-)
2(49.95*Hz)
2(5502*Wh)
2(0*Wh)
2(5502*Wh)
I user rc.local to start pooler

On github I added also a 123solar protocol for SDM120C.

On Raspbian I use libmodbus 3.0.3 (default version on repositories)

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sat Jan 31, 2015 11:51 am

Hi,
Just install my SDM220 in front of my installation, here a simple script for the household power

Code: Select all

#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// This script will output a meterN compatible format for the main command, if you own a total meter (import/export) and a production system

// Set the household total meter ID and command
$HHTID = 'TOT';
$tcmd  = 'more /tmp/485metern1.txt | egrep "^TOT\(" | grep "*W)"'; // TOT(-45*W)

// Same for the household production
$HHPID = '4';
$pcmd  = "curl http://localhost/metern/comapps/pool123solar.php?cmd=1"; // 4(100*W)

// Set the new household consumption ID
$HHCID = '1';

// Retrieve production
$regexp     = "/^$HHPID\(-?[0-9\.]+\*[A-z0-9³²%°]+\)$/i"; //LID(VALUE*UNIT)
$datareturn = exec($pcmd);
$datareturn = trim($datareturn);
if (preg_match($regexp, $datareturn)) {
    $datareturn = preg_replace("/^$HHPID\(/i", '', $datareturn, 1); // VALUE*UNIT)
    $prod       = preg_replace("/\*[A-z0-9³²%°]+\)$/i", '', $datareturn, 1); // VALUE
} else {
    $prod = 0;
    
}
// Retrieve total
$regexp     = "/^$HHTID\(-?[0-9\.]+\*[A-z0-9³²%°]+\)$/i"; //LID(VALUE*UNIT)
$datareturn = exec($tcmd);
$datareturn = trim($datareturn);
if (preg_match($regexp, $datareturn)) {
    $datareturn = preg_replace("/^$HHTID\(/i", '', $datareturn, 1); // VALUE*UNIT)
    $total      = preg_replace("/\*[A-z0-9³²%°]+\)$/i", '', $datareturn, 1); // VALUE
} else {
    $total = 0;
    
}

settype($prod, 'float');
settype($total, 'float');

$householdconso = round(($prod + $total), 2);
$str            = utf8_decode("$HHCID($householdconso*W)\n"); // 1(-55*W)
echo "$str";
?>
Next, i'll do some "stress tests" to see if my house is on fire :P

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sun Feb 01, 2015 1:09 pm

Hi,
I get some odd results with Import/Export/Total energy if i request a single output :?

Code: Select all

[root@plugbox comapps]# sdm120c -a1 -p -v -c -f -g -e -i -t  /dev/ttyUSB1
Voltage: 230.56 V 
Current: 4.31 A 
Power: 979.91 W 
Power Factor: 0.99 
Frequency: 50.01 Hz 
Import Active Energy: 16618 Wh 
Export Active Energy: 188 Wh 
Total Active Energy: 16806 Wh 
[root@plugbox comapps]# sdm120c -a1 -i /dev/ttyUSB1
Import Active Energy: 231040 Wh 
[root@plugbox comapps]# sdm120c -a1 -e /dev/ttyUSB1
Export Active Energy: 230509 Wh 
Do you know where is the problem ?
Thanks

pfiori
Posts: 19
Joined: Sun Feb 02, 2014 9:29 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by pfiori » Sun Feb 01, 2015 8:38 pm

hi all,

also I have a SDM220 modbus.

in testing phase, I compiled it on my ubuntu PC

i always receive:

Code: Select all

$ sudo make clean
rm -f *.o sdm120c
$ sudo make 
gcc -c -o sdm120c.o sdm120c.c `pkg-config --cflags libmodbus`
gcc -o sdm120c sdm120c.o `pkg-config --libs libmodbus`
$ ./sdm120c /dev/ttyUSB0 
ERROR Invalid CRC
$ 
do you have a hint?

I also tryied to use directly the PHP in this example, http://blog.vettore.org/modbus-senza-paura/ but with no success.

thanks

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 12:16 am

@jeanmarc
on SDM220 manual there is "Measurement mode"

Code: Select all

0001:mode 1(total = import)
0002:mode 2(total = import + export)
0003:mode 3 (total = import - export)
maybe you meter is configured in mode 2

EDIT: sorry, I didn't figure out the big difference with single reading
Can you try last version (1.1.0)?

@pfiori
I have SDM120C, so I cannot test it, sorry

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 10:42 am

Hello,
I am unable to compile the latest version 1.1.0 :cry: (I am running on Arch Linux ARM)

Code: Select all

[root@plugbox SDM120C]# make clean && make
rm -f *.o sdm120c
gcc -c -o sdm120c.o sdm120c.c `pkg-config --cflags libmodbus`
sdm120c.c: In function 'main':
sdm120c.c:392:38: warning: passing argument 2 of 'modbus_get_response_timeout' from incompatible pointer type
     modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec);
                                      ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:163:16: note: expected 'struct timeval *' but argument is of type 'uint32_t *'
 MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout);
                ^
sdm120c.c:392:5: error: too many arguments to function 'modbus_get_response_timeout'
     modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec);
     ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:163:16: note: declared here
 MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout);
                ^
sdm120c.c:395:34: warning: passing argument 2 of 'modbus_set_byte_timeout' makes pointer from integer without a cast
     modbus_set_byte_timeout(ctx, -1, 0);
                                  ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:167:16: note: expected 'const struct timeval *' but argument is of type 'int'
 MODBUS_API int modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout);
                ^
sdm120c.c:395:5: error: too many arguments to function 'modbus_set_byte_timeout'
     modbus_set_byte_timeout(ctx, -1, 0);
     ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:167:16: note: declared here
 MODBUS_API int modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout);
                ^
sdm120c.c:396:38: warning: passing argument 2 of 'modbus_set_response_timeout' makes pointer from integer without a cast
     modbus_set_response_timeout(ctx, resp_timeout, 0);
                                      ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:164:16: note: expected 'const struct timeval *' but argument is of type 'uint32_t'
 MODBUS_API int modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout);
                ^
sdm120c.c:396:5: error: too many arguments to function 'modbus_set_response_timeout'
     modbus_set_response_timeout(ctx, resp_timeout, 0);
     ^
In file included from sdm120c.c:35:0:
/usr/local/include/modbus/modbus.h:164:16: note: declared here
 MODBUS_API int modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout);
                ^
Makefile:10: recipe for target 'sdm120c.o' failed
make: *** [sdm120c.o] Error 1
[root@plugbox SDM120C]# 
edit: i probably need to update the libraries :?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest