OPEN 3 TXT FILE on different server
Posted: Wednesday 26 July 2017 12:16
Hi all! I have 3 Solar inverter and I have a script to read and push to domoticz the data.
This is my script and work
Now I Have to open the second url and redo the exact procedure ( username and password are the same ) and redo the procedure for the third. But I don't know how. At the end I have to sum the three value and push them to domoticz But I miss how I can open the second and third url into the same php file. Any help? 
This is my script and work
Code: Select all
#!/usr/bin/php
<?php
##### LOGIN SUNWAY INVERTER #####
$url = 'http://192.168.0.51/data/inverter.txt';
$login = 'customer';
$password = '00000000';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);
#### ELEBORATING DATA #####
$results = explode('#', $result);
$actualPower = filter_var($results[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
$dailyPower = filter_var($results[7],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
$totalPower = filter_var($results[10],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
#### WATT TO KWATT #####
$actualKPower= $actualPower * 1000;
$dailyKPower=$dailyPower * 1000;
$totalKPower=$totalPower * 1000;
##### STOP AT NIGHT #####
if (empty($totalPower)) die ;
##### PUSH DATA TO DOMOTICZ #####
file_get_contents( "http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=79&nvalue=0&svalue={$actualKPower};{$totalKPower}" );
### ALL ABOVE WORKS Code: Select all
$SumActual = $actualKPower1 + $actualKPower2 + $actualKPower3;
$SumKTotal = $totalKPower1 + $totalKPower2 + $totalKPower3;
##### PUSH DATA TO DOMOTICZ #####
file_get_contents( "http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=82&nvalue=0&svalue={$SumActual};{$SumKTotal}” );