Example #1
0
 public function index()
 {
     $seconds = 2;
     $micro = $seconds * 1000000;
     $this->load->model('analog_model');
     $myFile = "/var/www/relay_framework/daemontest1.txt";
     $fh = fopen($myFile, 'a') or die("Can't open file");
     $stringData = "File updated at: " . $sResponse . "\n";
     fwrite($fh, $stringData);
     fclose($fh);
     $this->load->model('home_model');
     list($sIpAddress, $sPortNo) = $this->home_model->getSettings();
     if ($sIpAddress == '') {
         if (IP_ADDRESS) {
             $sIpAddress = IP_ADDRESS;
         }
     }
     //Check for Port Number constant
     if ($sPortNo == '') {
         if (PORT_NO) {
             $sPortNo = PORT_NO;
         }
     }
     if ($sIpAddress == '' || $sPortNo == '') {
     } else {
         $sResponse = get_rlb_status();
         $aAP = array($sResponse['AP0'], $sResponse['AP1'], $sResponse['AP2'], $sResponse['AP3']);
         $aAP = array(0, 1, 0, 1);
         $sValves = $sResponse['valves'];
         $sRelays = $sResponse['relay'];
         $sPowercenter = $sResponse['powercenter'];
         $aResult = $this->analog_model->getAllAnalogDevice();
         $iResultCnt = count($aResult);
         for ($i = 0; $i < $iResultCnt; $i++) {
             if ($aResult[$i] != '') {
                 $aDevice = explode('_', $aResult[$i]);
                 if ($aDevice[1] != '') {
                     if ($aDevice[1] == 'R') {
                         $sNewResp = replace_return($sRelays, $aAP[$i], $aDevice[0]);
                         onoff_rlb_relay($sNewResp);
                     }
                     if ($aDevice[1] == 'P') {
                         $sNewResp = replace_return($sPowercenter, $aAP[$i], $aDevice[0]);
                         onoff_rlb_powercenter($sNewResp);
                     }
                     if ($aDevice[1] == 'V') {
                         $sNewResp = replace_return($sValves, $aAP[$i], $aDevice[0]);
                         onoff_rlb_valve($sNewResp);
                     }
                 }
             }
         }
         usleep($micro);
     }
 }
Example #2
0
 public function removePumpDetails()
 {
     // Set default HTTP response of 'ok'
     $aResponse = array();
     $aResponse['code'] = 0;
     $aResponse['status'] = 404;
     $aResponse['data'] = NULL;
     $sformat = isset($_REQUEST['format']) ? $_REQUEST['format'] : '';
     // Get response Format (json,xml,html etc.)
     $sAuth = isset($_REQUEST['auth']) ? $_REQUEST['auth'] : '';
     // Check if Authentication is required.
     $this->isAuthenticationRequired = $sAuth;
     // Optionally require connections to be made via HTTPS
     if ($this->isHTTPSRequired && $_SERVER['HTTPS'] != 'on') {
         $aResponse['code'] = 2;
         $aResponse['status'] = $aApiResponseCode[$aResponse['code']]['HTTP Response'];
         $aResponse['data'] = $aApiResponseCode[$aResponse['code']]['Message'];
         // Return Response to browser. This will exit the script.
         $this->webResponse($sformat, $aResponse);
     }
     if ($this->isAuthenticationRequired) {
         //START : Authorisation
         $sUsername = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
         // Get the username of webservice
         $sPassword = isset($_REQUEST['password']) ? $_REQUEST['password'] : '';
         // Get the password of webservice
         $this->webAuthorisation($sUsername, $sPassword, $sformat);
         // Check if username and password is valid.
         // END : Authorisation
     }
     $iPumpNumber = trim($_REQUEST['pn']);
     if ($iPumpNumber == '') {
         $aResponse['code'] = 5;
         $aResponse['status'] = $this->aApiResponseCode[$aResponse['code']]['HTTP Response'];
         $aResponse['data'] = 'Please enter valid Pump Number!';
         $this->webResponse($sformat, $aResponse);
     }
     if ($iPumpNumber > 2) {
         $aResponse['code'] = 5;
         $aResponse['status'] = $this->aApiResponseCode[$aResponse['code']]['HTTP Response'];
         $aResponse['data'] = 'Please enter pump number less than 3!';
         $this->webResponse($sformat, $aResponse);
     }
     if ($iPumpNumber != '') {
         $this->load->model('home_model');
         $sResponse = get_rlb_status();
         // Get the relay borad response from server.
         $sValves = $sResponse['valves'];
         // Valve Devices.
         $sRelays = $sResponse['relay'];
         // Relay Devices.
         $sPowercenter = $sResponse['powercenter'];
         // Power Center Devices.
         //Pump device Status
         $sPump = array($sResponse['pump_seq_0_st'], $sResponse['pump_seq_1_st'], $sResponse['pump_seq_2_st']);
         if ($sPump[$iPumpNumber] > 0) {
             $aPumpDetails = $this->home_model->getPumpDetails($i);
             //Variable Initialization to blank.
             $sPumpNumber = '';
             $sPumpType = '';
             $sPumpSubType = '';
             $sPumpSpeed = '';
             $sPumpFlow = '';
             $sPumpClosure = '';
             $sRelayNumber = '';
             if (is_array($aPumpDetails) && !empty($aPumpDetails)) {
                 foreach ($aPumpDetails as $aResultEdit) {
                     $sPumpNumber = $aResultEdit->pump_number;
                     $sPumpType = $aResultEdit->pump_type;
                     $sPumpSubType = $aResultEdit->pump_sub_type;
                     $sPumpSpeed = $aResultEdit->pump_speed;
                     $sPumpFlow = $aResultEdit->pump_flow;
                     $sPumpClosure = $aResultEdit->pump_closure;
                     $sRelayNumber = $aResultEdit->relay_number;
                 }
             }
             $iPumpStatus = 0;
             if ($sPumpType != '' && $sPumpClosure == '1') {
                 if ($sPumpType == '12' || $sPumpType == '24') {
                     if ($sPumpType == '24') {
                         $sNewResp = replace_return($sRelays, $iPumpStatus, $sRelayNumber);
                         onoff_rlb_relay($sNewResp);
                     } else {
                         if ($sPumpType == '12') {
                             $sNewResp = replace_return($sPowercenter, $iPumpStatus, $sRelayNumber);
                             onoff_rlb_powercenter($sNewResp);
                         }
                     }
                 } else {
                     if (preg_match('/Emulator/', $sPumpType)) {
                         $sNewResp = '';
                         $sNewResp = $sRelayName . ' ' . $iPumpStatus;
                         onoff_rlb_pump($sNewResp);
                         if ($sPumpType == 'Emulator12') {
                             $sNewResp12 = replace_return($sPowercenter, $iPumpStatus, $sRelayNumber);
                             onoff_rlb_powercenter($sNewResp12);
                         }
                         if ($sPumpType == 'Emulator24') {
                             $sNewResp24 = replace_return($sRelays, $iPumpStatus, $sRelayNumber);
                             onoff_rlb_relay($sNewResp24);
                         }
                     } else {
                         if (preg_match('/Intellicom/', $sPumpType)) {
                             $sNewResp = '';
                             $sNewResp = $sRelayName . ' ' . $iPumpStatus;
                             onoff_rlb_pump($sNewResp);
                             if ($sPumpType == 'Intellicom12') {
                                 $sNewResp12 = replace_return($sPowercenter, $iPumpStatus, $sRelayNumber);
                                 onoff_rlb_powercenter($sNewResp12);
                             }
                             if ($sPumpType == 'Intellicom24') {
                                 $sNewResp24 = replace_return($sRelays, $iPumpStatus, $sRelayNumber);
                                 onoff_rlb_relay($sNewResp24);
                             }
                         }
                     }
                 }
             }
         }
     }
     //Remove Pump Details From database.
     $this->home_model->removePump($iPumpNumber);
     //Remove the address associated with the pump on the relay board.
     $Pump = 'pm' . $iPumpNumber;
     removePumpAddress($Pump);
     $aResponse['code'] = 1;
     $aResponse['status'] = $this->aApiResponseCode[$aResponse['code']]['HTTP Response'];
     $aResponse['data'] = "Pump removed Succesfully!";
     // Return Response to browser. This will exit the script.
     $this->webResponse($sformat, $aResponse);
     exit;
 }
Example #3
0
 public function updateStatusOnOff()
 {
     $sResponse = get_rlb_status();
     //$sResponse      =   array('valves'=>'0120','powercenter'=>'0000','time'=>'','relay'=>'0000');
     $sValves = $sResponse['valves'];
     $sRelays = $sResponse['relay'];
     $sPowercenter = $sResponse['powercenter'];
     $sTime = $sResponse['time'];
     $sName = $this->input->post('sName');
     $sStatus = $this->input->post('sStatus');
     $sDevice = $this->input->post('sDevice');
     $sNewResp = '';
     if ($sDevice == 'R') {
         $sNewResp = replace_return($sRelays, $sStatus, $sName);
         onoff_rlb_relay($sNewResp);
     }
     if ($sDevice == 'P') {
         $sNewResp = replace_return($sPowercenter, $sStatus, $sName);
         onoff_rlb_powercenter($sNewResp);
     }
     if ($sDevice == 'V') {
         //echo $sStatus;
         $sNewResp = replace_return($sValves, $sStatus, $sName);
         onoff_rlb_valve($sNewResp);
     }
     if ($sDevice == 'PS') {
         $sNewResp = '';
         if ($sStatus == '0') {
             $sNewResp = $sName . ' ' . $sStatus;
         } else {
             if ($sStatus == '1') {
                 $this->load->model('home_model');
                 $aPumpDetails = $this->home_model->getPumpDetails($sName);
                 foreach ($aPumpDetails as $aResultPumpDetails) {
                     $sType = '';
                     if ($aResultPumpDetails->pump_type == '2') {
                         $sType = $aResultPumpDetails->pump_type . ' ' . $aResultPumpDetails->pump_speed;
                     } elseif ($aResultPumpDetails->pump_type == '3') {
                         $sType = $aResultPumpDetails->pump_type . ' ' . $aResultPumpDetails->pump_flow;
                     }
                     $sNewResp = $sName . ' ' . $sType;
                 }
             }
         }
         onoff_rlb_pump($sNewResp);
     }
     exit;
 }