{'access_token'}; curl_close($chauth); //Get servicelocation $chserviceloc = curl_init(''); curl_setopt($chserviceloc, CURLOPT_HEADER, 0); $headers = array('Authorization: Bearer ' . $access); curl_setopt($chserviceloc, CURLOPT_HTTPHEADER, $headers); curl_setopt($chserviceloc, CURLOPT_AUTOREFERER, true); curl_setopt($chserviceloc, CURLOPT_URL, 'https://app1pub.smappee.net/dev/v1/servicelocation'); curl_setopt($chserviceloc, CURLOPT_RETURNTRANSFER, 1); curl_setopt($chserviceloc, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($chserviceloc, CURLOPT_VERBOSE, 1); curl_setopt($chserviceloc, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($chserviceloc, CURLOPT_SSL_VERIFYPEER, false); $resserviceloc = curl_exec($chserviceloc); $objserviceloc = json_decode($resserviceloc,true); $serviceLocationId = $objserviceloc['serviceLocations'][0]['serviceLocationId']; curl_close($chserviceloc); $chconsumption = curl_init(''); curl_setopt($chconsumption, CURLOPT_HEADER, 0); $headers = array('Authorization: Bearer ' . $access); curl_setopt($chconsumption, CURLOPT_HTTPHEADER, $headers); curl_setopt($chconsumption, CURLOPT_AUTOREFERER, true); curl_setopt($chconsumption, CURLOPT_URL, 'https://app1pub.smappee.net/dev/v1/servicelocation/'.$serviceLocationId.'/consumption?aggregation=1&from='.$timefrom.'000&to='.$timeto.'000'); curl_setopt($chconsumption, CURLOPT_RETURNTRANSFER, 1); curl_setopt($chconsumption, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($chconsumption, CURLOPT_VERBOSE, 1); curl_setopt($chconsumption, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($chconsumption, CURLOPT_SSL_VERIFYPEER, false); $resconsumption = curl_exec($chconsumption); $objconsumption = json_decode($resconsumption,true); $consumptions = $objconsumption['consumptions']; $i = 0; foreach ( $consumptions as $item ) { $timestamp = $consumptions[$i]['timestamp']; $consumption = $consumptions[$i]['consumption']*12; $solar = $consumptions[$i]['solar']*12; $epoch = $timestamp/1000; $cleandate = date('Y-m-d H:i:s ', $epoch); $date = date('Ymd', $epoch); $time = date('H:i', $epoch); if($consumptionly == 1) { $pvoutputurl = 'http://pvoutput.org/service/r2/addstatus.jsp?d='.$date.'&t='.$time.'&v4='.$consumption.'&sid='.$systemid.'&key='.$apikey.''; } if($consumptionly == 0) { $pvoutputurl = 'http://pvoutput.org/service/r2/addstatus.jsp?d='.$date.'&t='.$time.'&v4='.$consumption.'&v2='.$solar.'&sid='.$systemid.'&key='.$apikey.''; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$pvoutputurl); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec ($ch); curl_close ($ch); $i++; } curl_close($chconsumption); ?>