EASTRON SDM120C - RS485 Modbus meter

thedrake
Posts: 52
Joined: Fri Aug 21, 2015 12:43 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by thedrake » Wed Nov 25, 2015 7:58 pm

hryst wrote:Hello
how to turn off the message "OK" at the end of a query result
sdm120c -p -q /dev/ttyUSB0
286.70 OK
There is still no switch in sdm120c to disable OK, but you can try with:

Code: Select all

sdm120c -p -q /dev/ttyUSB0 | cut -d' ' -f1

hryst
Posts: 3
Joined: Mon Sep 07, 2015 10:56 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by hryst » Thu Nov 26, 2015 7:56 am

works correctly, thx

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Wed Apr 13, 2016 3:43 pm

Hi,
I rewrite on a simple sdm daemon, this one is in php it may server for other com app as well :
comapps/sdm_daemon.php :

Code: Select all

<?php
/*
Start and stop in metern/config/config_daemon.php
php /srv/http/comapps/sdm_daemon.php { start | stop }
Then, request values with these commands :
cat /tmp/metern_log.txt | egrep "^1_V\(" | grep "*V)"
cat /tmp/metern_log.txt | egrep "^1_F\(" | grep "*Hz)"
cat /tmp/metern_log.txt | egrep "^1_PF\(" | grep "*F)"
cat /tmp/metern_log.txt | egrep "^1_IE\(" | grep "*Wh)"
cat /tmp/metern_log.txt | egrep "^1_EE\(" | grep "*Wh)"
cat /tmp/metern_log.txt | egrep "^1_P\(" | grep "*W)"
*/

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
$SCRDIR = dirname(__FILE__);

if (file_exists($SCRDIR . '/sdm_daemon.pid')) {
    $pid = (int) file_get_contents($SCRDIR . '/sdm_daemon.pid');
} else {
    $pid = null;
}

if (isset($argv[1])) {
    if (($argv[1] == 'start' || $argv[1] == 'stop') && file_exists('/tmp/metern_log.txt')) {
        unlink('/tmp/metern_log.txt');
    }
    if ($argv[1] == 'start') {
        if (is_null($pid)) {
            $command = 'php /srv/http/comapps/sdm_daemon_loop.php' . ' > /dev/null 2>&1 & echo $!;';
            $pid     = exec($command);
            file_put_contents($SCRDIR . '/sdm_daemon.pid', $pid);
        } else {
            echo "sdm_daemon seem to be running as $pid";
        }
    } else if ($argv[1] == 'stop') {
        if (!is_null($pid)) {
            $command = exec("kill -9 $pid > /dev/null 2>&1 &");
        }
        unlink($SCRDIR . '/sdm_daemon.pid');
    } else {
        echo "Usage : sdm_daemon {start | stop}\n";
    }
} else {
    echo "Usage : sdm_daemon {start | stop}\n";
}
?>
comapps/sdm_daemon_loop.php

Code: Select all

<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}

while (true) {
    $dataarray = array();
    $output    = exec('sdm120c -a1 -b9600 -z3 -2 -qpievfg /dev/sdm');
    $dataarray = preg_split('/[[:space:]]+/', $output);
    
    if (!isset($dataarray[6])) {
        $dataarray[6] = 'NOK';
    }
    if ($dataarray[6] == 'OK') { // Make sure the frame is complete before filling the tmp file
        $dataarray[0] = '1_V(' . $dataarray[0] . '*V)';
        $dataarray[1] = '1_P(' . $dataarray[1] . '*W)';
        $dataarray[2] = '1_PF(' . $dataarray[2] . '*F)';
        $dataarray[3] = '1_F(' . $dataarray[3] . '*Hz)';
        $dataarray[4] = '1_IE(' . $dataarray[4] . '*Wh)';
        $dataarray[5] = '1_EE(' . $dataarray[5] . '*Wh)';
        $str          = implode(PHP_EOL, $dataarray);
        file_put_contents('/tmp/metern_log.txt', $str);
    } else {
        $now = time();
        if ($now - filemtime('/tmp/metern_log.txt') >= 5) { // 5 sec
            unlink('/tmp/metern_log.txt');
        }
    }
    usleep(500000);
}
?>
meterN is now too fast, it suck CPU for nothing, i had to put a sleep in houseenergy power ;)

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Sun Apr 17, 2016 1:04 pm

Ermm :?
It happen after several hours running the daemon that sdm120c is stuck and leave the LCK file in place. I open an issue, for now i switch back to direct request..

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest