Anyway, start at least with a function for the udevice command, code will be lot's smaller and easier to read. Maybe that already shows you where it went wrong:
Code: Select all
#!/usr/bin/php
<?php
$data = array();
inizio:
$x = exec("/usr/local/bin/sdm120c -v -c -p -g -f -e -i -t -q -w3 -z5 /dev/ttyUSB0");
$data = preg_split('/[[:space:]]+/', $x);
if ($data[8] = 'OK') {
$tensione = udevice(1,0,$data[0]);
$corrente = udevice(2,0,$data[1]);
$potenza = $data[2];
$cosfi = udevice(4,0,$data[3]);
//$frequenza_2 = $data[4];
$immessa = udevice(43,0,$data[5]);
$prelevata = udevice(44,0,$data[6]);
$energia = udevice(3,0,$data[7]);
}
sleep(2);
goto inizio;
function udevice($idx,$nvalue,$svalue) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.X.XXX:8080/json.htm?type=command¶m=udevice&idx=$idx&nvalue=$nvalue&svalue=$svalue");
curl_exec($ch);
curl_close($ch);
}
I like to keep my Domoticz and the number of commands as clean and low as possible, I only put the needed data for automation. That garantees a light and fast system.
Tip for the forum: if you use code=php /code instead of code /code the code is colored
