示例#1
0
    /**
     * Execute on Event
     *
     * @param array $event
     * @param Application_Model_Trigger $triggerObject
     */
    public function execute($event,$triggerObject){
        $address = $triggerObject->settings_data['address'];
        $cameraAddress = $triggerObject->settings_data['camera'];
        
        $eventAddress = $event['house'] . $event['device'];
        if($eventAddress != $address || ($event['type'] != 'On' && $event['type'] != 'Off') ||
            $event['direction'] != 'Tx' || $event['medium'] != 'PL'){
            return false;
        }
        $present = ($event['type'] == 'On')? true: false;

        echo "Running trigger $triggerObject->name\n";
        //save flag to db
        Application_Model_VariableMapper::getInstance()->set('present',(string)$present);

        $commander = Octopus_X10_Command::getInstance(Zend_Registry::get('config')->toArray());
        
        if($present){
            //if present turn off camera
            $commander->execute('off', $cameraAddress);
        }
        else{
            //if not present turn on camera
            $commander->execute('on', $cameraAddress);
        }
    }
示例#2
0
文件: Lamp.php 项目: rukavina/Octopus
    /**
     * Execute hook
     * 
     * @param string $command
     * @param mixed $bootstrap
     * @param Application_Model_Device $device
     * @param array $parameters
     */
    protected function _internalExecute($command,$bootstrap,$device,$parameters){
        if($command == 'xdim'){
            if(!isset ($parameters['intesity']) || $parameters['intesity'] == 0){
                $command = 'off';
            }
            else{
                $intesity = round(($parameters['intesity'] / 100) * 63);

                if(!$device->status_data['on']){
                    //fire on first
                    Octopus_X10_Command::getInstance($bootstrap->getOptions())
                                    ->execute("on", $device->address,null,false);

                    $device->status_data['on'] = 1;
                }
                $device->status_data['intesity'] = $parameters['intesity'];
                
                //update in DB
                Application_Model_DeviceMapper::getInstance()->updateDevice($device);

                return Octopus_X10_Command::getInstance($bootstrap->getOptions())
                    ->execute('xdim', $device->address,$intesity,false);
            }
        }

        return Octopus_X10_Command::getInstance($bootstrap->getOptions())
                ->execute($command, $device->address,null,false);
    }
示例#3
0
 /**
  * returns singleton instance of Octopus_X10_Command
  *
  * @param array $config
  * @return Octopus_X10_Command
  */
 public static function getInstance(array $config = null)
 {
     if(self::$_instance === null)
     {
         self::$_instance = new self($config);
     }
     return self::$_instance;
 }
示例#4
0
    /**
     * parse read string into events array
     *
     * @param string $text
     * @return array
     */
    protected function parseEvents($text){
        $text .= "\n";
        $events = array();
        $matches = array();
        $regex = "/([0-9]{2})\/([0-9]{2}) ([0-9]{2})\:([0-9]{2})\:([0-9]{2}) ([T,R]x) ([PL|RF]{2}) House(Unit)*: ([A-F]{1})([0-9]{0,2})( Func: (.*))*/";
        $matchResult = preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
        echo "\nMatch result: $matchResult\n";
        if($matchResult > 0){
            foreach ($matches as $match) {
                $type = isset($match['12'])? $match['12']:"";
                $house = $match['9'];
                $device = $match['10'];
                $time = mktime($match['3'], $match['4'], $match['5'], $match['1'], $match['2'], date("Y"));

                if($type == ''){
                    //address selector - not function
                    $this->selectedDevices[$house] = $device;
                }
                else{
                    $fParts = array();
                    if(preg_match("/(.*)\(([0-9]+)\)/", $type, $fParts) > 0){
                        $type = $fParts[1];
                        $param = $fParts[2];
                    }
                    else{
                        $param = null;
                    }
                    //function generate event
                    $event = array(
                        "type"      => $type,
                        "time"      => $time,
                        "direction" => $match['6'],
                        "medium"    => $match['7'],
                        "house"     => $house,
                        "device"    => ($device != "")?$device:$this->selectedDevices[$house]
                    );
                    if($param != null){
                        $event['parameter'] = $param;
                    }
                    //attach status
                    $event['status'] = $this->commander->getStatus();
                    $this->status = $event['status'];
                    
                    echo "Found Event: \n==============\n";
                    print_r($event); echo "\n\n";
                    $events[] = $event;
                }
            }
        }
        return $events;
    }
示例#5
0
    /**
     * Execute on Event
     *
     * @param array $event
     * @param Application_Model_Trigger $triggerObject
     */
    public function execute($event,$triggerObject){
        $address = $triggerObject->settings_data['address'];
        $lampAddress = $triggerObject->settings_data['lamp'];

        $eventAddress = $event['house'] . $event['device'];
        if($eventAddress != $address || $event['type'] != 'On' ||
            $event['direction'] != 'Tx' || $event['medium'] != 'PL'){
            return false;
        }
        $present = Application_Model_VariableMapper::getInstance()->get('present');
        if(!isset ($present)){
            $present = false;
        }
        else{
            $present = (bool)$present;
        }
        //do nothing if present
        if($present){
            return false;
        }

        $now = time();
        $lastExecuted = isset ($triggerObject->status_data['executed'])?$triggerObject->status_data['executed']:0;
        //do nothing in next 5 minutes
        if($now < ($lastExecuted + 5 * 60)){
            return false;
        }
        $triggerObject->status_data['executed'] = $now;
        Application_Model_TriggerMapper::getInstance()->save($triggerObject);

        $config = Zend_Registry::get('config')->toArray();

        echo "Running trigger $triggerObject->name\n";
        //turn on lamp to see them better
        $commander = Octopus_X10_Command::getInstance($config);
        $commander->execute('on', $lampAddress);
        //wait 2 seconds to make a shoot
        sleep(2);
        $img1 = file_get_contents($config['camera']['url']);
        sleep(1);
        $img2 = file_get_contents($config['camera']['url']);
        //send email
        $smtpConnection = new Zend_Mail_Transport_Smtp($config['mail']['smtp']['server'],
                $config['mail']['smtp']['params']);
        $mail = new Zend_Mail();
        $at1 = $mail->createAttachment($img1);
        $at1->type        = 'image/jpg';
        $at1->filename    = 'shoot1.jpg';
        $at2 = $mail->createAttachment($img2);
        $at2->type        = 'image/jpg';
        $at2->filename    = 'shoot2.jpg';

        $mail->setBodyText('Octopus Notification sensor detection')
            ->setFrom('*****@*****.**', 'Octopus')
            ->addTo('*****@*****.**', 'Milan Rukavina')
            ->setSubject('Octopus Notification sensor detection');
         //Send
         try {
            $mail->send($smtpConnection);
            echo "trigger $triggerObject->name email sent! \n";
         }
         catch (Exception $e) {
            echo "Error sending email: " . $e->getMessage() . "\n";
         }
    }
示例#6
0
#!/usr/bin/php5
<?php
/**
 * php x10_command.php --function=on --address=A1 --param=5
 */

$cliOptions = array(
    'function|f=s' => 'X10 function: on, off, dim, bright...',
    'address|a=s' => 'Device address',
    'parameter|p-i' => 'Optional function parameter'
);

include_once 'include/bootstrap.php';

$commander = Octopus_X10_Command::getInstance($configuration->toArray());

if($getopt->getOption("function") == "status"){
    $output = $commander->getStatus();
}
else{
    $output = $commander->execute($getopt->getOption("function"), $getopt->getOption("address"),$getopt->getOption("parameter"));
}


print_r($output);
示例#7
0
 /**
  * Execute hook
  *
  * @param string $command
  * @param mixed $bootstrap
  * @param Application_Model_Device $device
  * @param array $parameters
  */
 protected function _internalExecute($command,$bootstrap,$device,$parameters){
     return Octopus_X10_Command::getInstance($bootstrap->getOptions())
             ->execute($command, $device->address,null,false);
 }