コード例 #1
0
ファイル: Present.php プロジェクト: rukavina/Octopus
    /**
     * 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
ファイル: Sensor.php プロジェクト: rukavina/Octopus
    /**
     * 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";
         }
    }
コード例 #4
0
ファイル: x10_command.php プロジェクト: rukavina/Octopus
#!/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);
コード例 #5
0
ファイル: Switch.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){
     return Octopus_X10_Command::getInstance($bootstrap->getOptions())
             ->execute($command, $device->address,null,false);
 }
コード例 #6
0
ファイル: Service.php プロジェクト: rukavina/Octopus
 /**
  * constructor
  *
  * @param array $config
  */
 private function __construct($config) {
     require_once('amqplib/amqp.inc');
     $this->config = $config;
     $this->commander = Octopus_X10_Command::getInstance($config);
 }