コード例 #1
0
 public function setAction()
 {
     if ($_GET['id'] != "") {
         $str = explode("_", $_GET['id']);
         $lampid = $str[0];
         require_once 'models/homeModel.php';
         $model = new homeModel();
         // get device data
         $device = $model->getDeviceById($lampid);
         $settings = $model->settings();
         if ($str[1] == "on") {
             $lampset = "1";
         } elseif ($str[1] == "off") {
             $lampset = "0";
         }
         echo $lampset;
         $letter = escapeshellarg($this->letter($device['letter']));
         $co = escapeshellarg($device['code']);
         // execute rcswitch-pi
         shell_exec("sudo /home/pi/rcswitch-pi/send {$co} {$letter} {$lampset}");
         if ($str[1] == "on") {
             $espeak = '"schalte ' . $device['device'] . ' an ' . $model->getSarkasmus($settings['sarkasmus']) . '"';
         } else {
             $espeak = '"schalte ' . $device['device'] . ' aus ' . $model->getSarkasmus($settings['sarkasmus']) . '"';
         }
         $model->say($espeak);
         //shell_exec("sudo /usr/bin/espeak -vde+".ESPEAK_voice." " . $espeak . " 2>/dev/null");
         // Set device status
         $setlamp = $model->setDeviceStatus($lampid, $lampset);
         //echo $setlamp;
     }
 }