Example #1
0
 public static function GetEstCurrentData($ipaddress, $port, array $ids)
 {
     $sid = '';
     for ($i = 0; $i < count($ids); $i++) {
         $sid += $ids[$i] . ',';
     }
     $url = 'http://' . $ipaddress . ':' . $port . '/crq?req=current&type=b&n1=' . $sid . '&json=1';
     $code = \Est\Emax::RequestToUrl('GET', $url);
 }
Example #2
0
 public function GetStationData()
 {
     $id = Input::get('station');
     $station = $this->GetStationById($id);
     $date = Input::get('date');
     $data = new \stdClass();
     $rows = array();
     if (!isset($station)) {
         return json_encode($data);
     }
     $dt = $this->GetFormatDate($date);
     $emax = new \Est\Emax("http://10.32.18.32:8181", "admin", "admin");
     $res = $emax->GetTableData(urldecode($station), $dt);
     $data->total = count($res->Values);
     //$data->balance=$res->balance;
     foreach ($res->Values as $value) {
         $row = new \stdClass();
         $row->section = "--";
         $name = explode('\\', $value->Name);
         $row->name = $name[count($name) - 1];
         $row->sn = isset($value->SN->Val->Val) ? $value->SN->Val->Val : '--';
         $row->ki = $value->KI;
         $row->ku = $value->KU;
         $time = $value->Plus->MaxPow->T->T;
         $row->p_maxpow_date = sprintf("%d-%02d-%02d %02d:%02d:%02d", $time[0], $time[1], $time[2], $time[3], $time[4], $time[5]);
         $row->p_maxpow = $this->CheckQualityData($value->Plus->MaxPow);
         $row->p_EnargyPrevMonth = $this->CheckQualityData($value->Plus->EnargyPrevMonth);
         $row->p_CounterFromStartMonth = $this->CheckQualityData($value->Plus->CounterFromStartMonth);
         $row->p_EnergyFromStartMonth = $this->CheckQualityData($value->Plus->EnergyFromStartMonth);
         $row->p_EnergyByLastDay = $this->CheckQualityData($value->Plus->EnergyByLastDay);
         $row->p_CounterFromStartDay = $this->CheckQualityData($value->Plus->CounterFromStartDay);
         $time = $value->Minus->MaxPow->T->T;
         $row->m_maxpow_date = sprintf("%d-%02d-%02d %02d:%02d:%02d", $time[0], $time[1], $time[2], $time[3], $time[4], $time[5]);
         $row->m_maxpow = $this->CheckQualityData($value->Minus->MaxPow);
         $row->m_EnargyPrevMonth = $this->CheckQualityData($value->Minus->EnargyPrevMonth);
         $row->m_CounterFromStartMonth = $this->CheckQualityData($value->Minus->CounterFromStartMonth);
         $row->m_EnergyFromStartMonth = $this->CheckQualityData($value->Minus->EnergyFromStartMonth);
         $row->m_EnergyByLastDay = $this->CheckQualityData($value->Minus->EnergyByLastDay);
         $row->m_CounterFromStartDay = $this->CheckQualityData($value->Minus->CounterFromStartDay);
         array_push($rows, $row);
     }
     $data->rows = $rows;
     $data->balance = $res->Balance;
     $cc = json_encode($data);
     return $cc;
 }
Example #3
0
 public static function RequestToUrl($method, $uri, $data = null, array $headers = null, $timeout = null, $userAgent = null)
 {
     try {
         // Create the stream context options array with the required method offset.
         $options = array('method' => strtoupper($method));
         // If data exists let's encode it and make sure our Content-type header is set.
         if (isset($data)) {
             // If the data is a scalar value simply add it to the stream context options.
             if (is_scalar($data)) {
                 $options['content'] = $data;
             } else {
                 $options['content'] = http_build_query($data);
             }
             if (!isset($headers['Content-type'])) {
                 $headers['Content-type'] = 'application/x-www-form-urlencoded';
             }
             $headers['Connection'] = 'Keep-Alive';
             //$headers['X-Requested-With']='XMLHttpRequest';
             $headers['Content-length'] = strlen($options['content']);
         }
         // Build the headers string for the request.
         $headerString = null;
         if (isset($headers)) {
             foreach ($headers as $key => $value) {
                 $headerString .= $key . ': ' . $value . "\r\n";
             }
             // Add the headers string into the stream context options array.
             $options['header'] = trim($headerString, "\r\n");
         }
         // If an explicit timeout is given user it.
         if (isset($timeout)) {
             $options['timeout'] = (int) $timeout;
         }
         // If an explicit user agent is given use it.
         if (isset($userAgent)) {
             $options['user_agent'] = $userAgent;
         }
         // Ignore HTTP errors so that we can capture them.
         $options['ignore_errors'] = 1;
         // Create the stream context for the request.
         $context = stream_context_create(array('http' => $options));
         // Open the stream for reading.
         $stream = fopen($uri, 'r', false, $context);
         if (!$stream) {
             return Emax::ResolveResult(array('headers' => null, 'code' => 503, 'value' => 'Сервис по указанному адресу недоступен'));
         }
         $metadata = stream_get_meta_data($stream);
         preg_match('/[0-9]{3}/', array_shift($metadata['wrapper_data']), $matches);
         $headval = Emax::parseMetaData($metadata['wrapper_data']);
         $reader = null;
         if ($headval['Content-Length'] != 0) {
             $reader = stream_get_contents($stream, $headval['Content-Length']);
         }
         fclose($stream);
         return Emax::ResolveResult(array('headers' => $headval, 'code' => $matches[0], 'value' => $reader));
     } catch (Exception $e) {
         return Emax::ResolveResult(array('headers' => $headval, 'code' => $e->getCode(), 'value' => $e->getMessage()));
     }
 }