Systemd-Journal process

Talks about metering
TonyP62
Posts: 97
Joined: Fri May 01, 2015 11:07 pm

Re: Systemd-Journal process

Post by TonyP62 » Fri Nov 24, 2017 7:29 pm

jeanmarc wrote:
Mon Nov 20, 2017 7:38 pm
Why don't you use a com daemon ? It's more efficient to read a file instead of querying each time the sdm command.
Because i am using a modified version of the comapps from the italian 123solar forum called SolarJessie.

Now i want install 123Solar & MeterN into a new Raspberry Pi3 with the comapps of your site on Raspbian Stretch . I hope there are not problems with this release because use PHP7 .

I'm sure that com_daemon is better then querying sdm120c every time but SolarJessie was build in this way and it' very simple for us configuring a pre-build image. SolarJessie has allowed me to configure 3 friend's installations in few minutes.
But now i want experiment this new one.
Thanks for all.

Best Regards,
Tony

123Solar site
MeterN site

flane
Posts: 86
Joined: Mon Aug 11, 2014 7:22 am

Re: Systemd-Journal process

Post by flane » Sun Nov 26, 2017 1:31 pm

is it possible with com_daemon.php reading multiple counters?

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

Re: Systemd-Journal process

Post by jeanmarc » Sun Nov 26, 2017 6:46 pm

Sure, you can add any requests of the loop.

flane
Posts: 86
Joined: Mon Aug 11, 2014 7:22 am

Re: Systemd-Journal process

Post by flane » Mon Nov 27, 2017 4:17 pm

Sorry Jeanmarc,
but how can i add more counters to com_daemon_loop?

$dataarray is for a single counter (1_V , 1_P .....)

Code: Select all

        $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)';

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

Re: Systemd-Journal process

Post by jeanmarc » Mon Nov 27, 2017 5:57 pm

Code: Select all

$output1    = exec('sdm120c -a1 -b9600 -z3 -2 -qpievfg /dev/sdm1');
$dataarray1 = preg_split('/[[:space:]]+/', $output1);

$output2    = exec('sdm120c -a2 -b9600 -z3 -2 -qpievfg /dev/sdm2');
$dataarray2 = preg_split('/[[:space:]]+/', $output2);

$output3    = exec('acomapp /dev/whatever');
and so on ;)
Mind that it could be that fast to read values into /dev/shm/ that you may put some delay or mN will eat you CPU.

flane
Posts: 86
Joined: Mon Aug 11, 2014 7:22 am

Re: Systemd-Journal process

Post by flane » Wed Nov 29, 2017 10:07 am

ok, but should I rewrite this part for each counter ($dataarray1, $dataarray2, .......) ?

Code: Select all

    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('/dev/shm/metern_log.txt', $str);
If I have 10 counters? :?

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

Re: Systemd-Journal process

Post by jeanmarc » Wed Nov 29, 2017 10:51 am

You can either start 10 independent daemons :)

flane
Posts: 86
Joined: Mon Aug 11, 2014 7:22 am

Re: Systemd-Journal process

Post by flane » Wed Nov 29, 2017 11:48 am

Start 10 independent daemons, can create tails on the bus and slow down the readings.
Reading the counters with a single daemon avoids this problem.

pooler485 reads counters in sequence.

Command:

Code: Select all

pooler485 2,3,4,5,6,7,8,9 9600 /dev/ttyUSB0 > /dev/null 2>/dev/null &

Code: Select all

#!/bin/bash
# pooler485.sh

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

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

while [ true ]; do

    ID=0
    POWER=""
    ENERGY=""
	CHECK=""

    for ADDRESS in $ADDR_ARR
    do
    #((ID++))
    ID=$ADDRESS
	CMD="sdm120c -a ${ADDRESS} -b ${BAUD_RATE} -z 10 -i -p -v -c -f -g -P N -w 10 -j 10 -d 0 -q ${DEVICE}"

    #echo $CMD
    
    VALUE=`$CMD`
    VOLTAGE=$(echo ${VALUE}   | awk '{print $1}')
	CURRENT=$(echo ${VALUE}   | awk '{print $2}')
	POWER=$(echo ${VALUE}     | awk '{print $3}')
	FACTOR=$(echo ${VALUE}    | awk '{print $4}')
	FREQUENCY=$(echo ${VALUE} | awk '{print $5}')
	ENERGY=$(echo ${VALUE}    | awk '{print $6}')
	CHECK=$(echo ${VALUE} 	  | awk '{print $7}')
	
	if [ "$CHECK" = "OK" ]; then
		echo -e "$ID($POWER*W)\n$ID($ENERGY*Wh)\n${ID}_1($VOLTAGE*V)\n${ID}_2($CURRENT*A)\n${ID}_3($FREQUENCY*Hz)\n${ID}_4($FACTOR*F)" > /dev/shm/metern${ADDRESS}.txt
    else
        if [ -f /dev/shm/metern${ADDRESS}.txt ]; then
            POWER="0.00"
            ENERGY=`sed -n '2p' /dev/shm/metern${ADDRESS}.txt`
			VOLTAGE="0.00"
			CURRENT="0.00"
			FREQUENCY="0.00"
			FACTOR="0.00"
            echo -e "$ID($POWER*W)\n$ENERGY\n${ID}_1($VOLTAGE*V)\n${ID}_2($CURRENT*A)\n${ID}_3($FREQUENCY*Hz)\n${ID}_4($FACTOR*F)" > /dev/shm/metern${ADDRESS}.txt
        fi
    fi
    sleep 1

    done

done  

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

Re: Systemd-Journal process

Post by jeanmarc » Wed Nov 29, 2017 12:01 pm

You can either request sdm120c via a loop in your pooler485 script (for ADDRESS in $ADDR_ARR) or via the loop in com_daemon_loop.php.
The request time should be the same.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest