예제 #1
0
 public static function getJsonRpc()
 {
     if (config::byKey('market::address') == '') {
         throw new Exception(__('Aucune addresse n\'est renseignée pour le market', __FILE__));
     }
     if (config::byKey('market::username') != '' && config::byKey('market::password') != '') {
         $params = array('username' => config::byKey('market::username'), 'password' => config::byKey('market::password'), 'password_type' => 'sha1', 'jeedomversion' => jeedom::version(), 'hwkey' => jeedom::getHardwareKey(), 'addrComplement' => config::byKey('externalComplement'), 'information' => array('nbMessage' => message::nbMessage(), 'hardware' => method_exists('jeedom', 'getHardwareName') ? jeedom::getHardwareName() : ''));
         if (config::byKey('market::allowDNS') != 1) {
             $params['addr'] = config::byKey('externalAddr');
             $params['addrProtocol'] = config::byKey('externalProtocol');
             $params['addrPort'] = config::byKey('externalPort');
         }
         $jsonrpc = new jsonrpcClient(config::byKey('market::address') . '/core/api/api.php', '', $params);
     } else {
         $jsonrpc = new jsonrpcClient(config::byKey('market::address') . '/core/api/api.php', '', array('jeedomversion' => jeedom::version(), 'hwkey' => jeedom::getHardwareKey()));
     }
     $jsonrpc->setCb_class('market');
     $jsonrpc->setCb_function('postJsonRpc');
     return $jsonrpc;
 }
예제 #2
0
<?php

$URL_JEEDOM = "http://adresse IP du raspberry/jeedom";
$API_KEY = "cle API";
require 'jsonrpcClient.class.php';
// recherche mot cle JEEDOM
//if (strncmp($argv[1],"JEEDOM ",7)==0) {
$jsonrpc = new jsonrpcClient($URL_JEEDOM . '/core/api/jeeApi.php', $API_KEY);
$message = substr($argv[1], 7);
if ($jsonrpc->sendRequest('interact::tryToReply', array('query' => $message))) {
    print_r($jsonrpc->getResult());
} else {
    echo $jsonrpc->getError();
}
//} else {
//   echo "-1";
//}
예제 #3
0
 /**
  * Call for an action on the device identified by $deviceId.
  * @return string Json formated action status.
  */
 public function action($deviceId, $actionName, $actionParam = null)
 {
     //file_put_contents('/usr/share/nginx/www/iss-domo/export.log', $actionName);
     //action for Jeedom
     if (Config::get('hardware.jeedom') == 1) {
         //*** For Scenes Jeedom***
         if ($actionName == 'launchScene') {
             $arraydeviceId = explode("-", $deviceId);
             $deviceId = $arraydeviceId[0];
             // Curl function
             $url = Config::get('jeedom.jeedom_url') . "?apikey=" . Config::get('jeedom.api_key') . "&type=scenario&id={$deviceId}&action=start";
             $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false);
             $CURL = curl_init();
             curl_setopt_array($CURL, $options);
             $content = curl_exec($CURL);
             curl_close($CURL);
             // End curl function
         }
         include_once 'jsonrpcClient.class.php';
         $fulldata = $this->getjeedomfull();
         if (isset($fulldata['result'])) {
             $test = 'eqLogic_id';
             $cmd = null;
             list($infos, $device_equip) = self::recherche($fulldata, $deviceId, $cmd, $test);
         }
         if (isset($infos)) {
             if (($device_equip == 'BeNeXt.BuiltInDimmer' or $device_equip == 'fibaro.fgd211') and $actionName == 'setLevel') {
                 $test = 'id';
                 $cmd = 'Intensité';
                 list($ids, $autre) = self::recherche($fulldata, $infos, $cmd, $test);
                 if (isset($ids)) {
                     $jsonrpc = new jsonrpcClient(Config::get('jeedom.jeedom_url'), Config::get('jeedom.api_key'));
                     if ($actionParam == 100) {
                         $actionParam = 99;
                     }
                     $jsonrpc->sendRequest('cmd::execCmd', array('id' => $ids, 'options' => array('slider' => $actionParam)));
                 }
             } else {
                 switch ($actionName) {
                     case 'setStatus':
                         if ($actionParam == 1) {
                             $test = 'id';
                             $cmd = 'On';
                             list($ids, $autre) = self::recherche($fulldata, $infos, $cmd, $test);
                         } elseif ($actionParam == 0) {
                             $test = 'id';
                             $cmd = 'Off';
                             list($ids, $autre) = self::recherche($fulldata, $infos, $cmd, $test);
                         }
                         break;
                     case 'setLevel':
                         if ($actionParam == 0) {
                             $test = 'id';
                             $cmd = 'Down';
                             list($ids, $autre) = self::recherche($fulldata, $infos, $cmd, $test);
                         } elseif ($actionParam == 100) {
                             $test = 'id';
                             $cmd = 'Up';
                             list($ids, $autre) = self::recherche($fulldata, $infos, $cmd, $test);
                         }
                         break;
                 }
                 if (isset($ids)) {
                     $jsonrpc = new jsonrpcClient(Config::get('jeedom.jeedom_url'), Config::get('jeedom.api_key'));
                     $jsonrpc->sendRequest('cmd::execCmd', array('id' => $ids));
                 }
             }
         }
         $infos = null;
         $ids = null;
     }
     // action for Domoticz
     if (Config::get('hardware.domoticz') == 1) {
         //*** For switchs, Dimmer, Lock ***
         if ($actionName == 'setStatus' or $actionName == 'pulseShutter') {
             if (strpos($deviceId, 'noroom')) {
                 $arraydeviceId = explode("-", $deviceId);
                 $deviceId = $arraydeviceId[0];
             }
             $actionName = 'setStatus' == $actionName ? 'switchlight' : $actionName;
             $actionParam = '0' == $actionParam ? 'Off' : 'On';
             $client = $this->getClient();
             $request = $client->getClient()->createRequest('GET', get_url(Config::get('iss-domo.domoticz_url'), "json.htm?type=command&param={$actionName}&idx={$deviceId}}&switchcmd={$actionParam}"));
             $response = $request->send();
             $input = $response->json();
             // convert to app format
             $output = array('success' => 'OK' === $input['status'] ? true : false, 'errormsg' => 'ERR' === $input['status'] ? 'An error occured' : '');
             return Response::json($output);
         }
         //*** For Dimmer, Blinds ***
         if ($actionName == 'setLevel') {
             if (strpos($deviceId, 'noroom')) {
                 $arraydeviceId = explode("-", $deviceId);
                 $deviceId = $arraydeviceId[0];
             }
             $actionName = 'setLevel' == $actionName ? 'switchlight' : $actionName;
             $actionParam = '0' == $actionParam ? 'On' : 'Off';
             $client = $this->getClient();
             $request = $client->getClient()->createRequest('GET', get_url(Config::get('iss-domo.domoticz_url'), "json.htm?type=command&param={$actionName}&idx={$deviceId}}&switchcmd={$actionParam}"));
             $response = $request->send();
             $input = $response->json();
             // convert to app format
             $output = array('success' => 'OK' === $input['status'] ? true : false, 'errormsg' => 'ERR' === $input['status'] ? 'An error occured' : '');
             return Response::json($output);
         }
         //*** For Scenes in Rooms***
         if ($actionName == 'launchScene' and is_numeric($deviceId)) {
             $actionName = 'launchScene' == $actionName ? 'switchscene' : $actionName;
             $actionParam = '0' == $actionParam ? 'Off' : 'On';
             $client = $this->getClient();
             $request = $client->getClient()->createRequest('GET', get_url(Config::get('iss-domo.domoticz_url'), "json.htm?type=command&param={$actionName}&idx={$deviceId}}&switchcmd={$actionParam}"));
             $response = $request->send();
             $input = $response->json();
             // convert to app format
             $output = array('success' => 'OK' === $input['status'] ? true : false, 'errormsg' => 'ERR' === $input['status'] ? 'An error occured' : '');
             return Response::json($output);
         }
         //*** For Scenes in No Rooms***
         if ($actionName == 'launchScene' and strpos($deviceId, 'noroomscene')) {
             $arraydeviceId = explode("-", $deviceId);
             $deviceId = $arraydeviceId[0];
             $actionName = 'launchScene' == $actionName ? 'switchscene' : $actionName;
             $actionParam = '0' == $actionParam ? 'Off' : 'On';
             $client = $this->getClient();
             $request = $client->getClient()->createRequest('GET', get_url(Config::get('iss-domo.domoticz_url'), "json.htm?type=command&param={$actionName}&idx={$deviceId}}&switchcmd={$actionParam}"));
             $response = $request->send();
             $input = $response->json();
             // convert to app format
             $output = array('success' => 'OK' === $input['status'] ? true : false, 'errormsg' => 'ERR' === $input['status'] ? 'An error occured' : '');
             return Response::json($output);
         }
     }
     //*** For MOVIES from XBMC ***
     if (Config::get('hardware.xbmc') == 1 and Config::get('xbmc.xbmc_movies') == 1) {
         // Launch Movie to XBMC where type command launchScene
         if ($actionName == 'launchScene' and strpos($deviceId, 'xbmove')) {
             //What is the id of the movie
             $arraydeviceId = explode("-", $deviceId);
             $deviceId = $arraydeviceId[0];
             //Clear Xbmc playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = Config::get('xbmc.clear_playlist');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
             //Add movie ($deviceId) to Playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = array('request' => '{"jsonrpc":"2.0","id":1,"method":"Playlist.Add","params":{"playlistid":0,"item":{"movieid":' . $deviceId . '}}}');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
             //Play Xbmc playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = Config::get('xbmc.play_playlist');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
         }
     }
     //*** For SONGS from XBMC ***
     if (Config::get('hardware.xbmc') == 1 and Config::get('xbmc.xbmc_songs') == 1) {
         // Launch Songs to XBMC where type command launchScene
         if ($actionName == 'launchScene' and strpos($deviceId, 'xbsong')) {
             //What is the id of the song
             $arraydeviceId = explode("-", $deviceId);
             $deviceId = $arraydeviceId[0];
             //Clear Xbmc playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = Config::get('xbmc.clear_playlist');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
             //Add song ($deviceId) to Playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = array('request' => '{"jsonrpc":"2.0","id":1,"method":"Playlist.Add","params":{"playlistid":0,"item":{"songid":' . $deviceId . '}}}');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
             //Play Xbmc playlist (id=0)
             $client = $this->getClient()->getClient();
             $request = $client->createRequest('GET', Config::get('xbmc.xbmc_url'));
             $q = $request->getQuery();
             $params = Config::get('xbmc.play_playlist');
             foreach ($params as $k => $v) {
                 $q->set($k, $v);
             }
             $response = $request->send();
         }
     }
     //*** For movies from NAS ***
     // TEST NOT IMPEMENTED
     /**if(Config::get('hardware.nas') == 1){
     		if($actionName == 'launchScene'){
     		$arraydeviceId = explode("-", $deviceId);
     		$deviceId = $arraydeviceId[0];
     		// Sequence pour se rendre depuis freebox player dans le repertoire de notre nas
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=home'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=red'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=right&long=true'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		sleep(3);
     		//On est dans les disques
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		sleep(1);
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		sleep(1);
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down&long=true'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=up'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		sleep(5);
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     		$response = $request->send();
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		sleep(5);
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     		//Nous sommes dans le repertoire de notre nas
     		sleep(5);
     		$nbr_file = 1;
     		while ($nbr_file <= $deviceId)
     			{
         		$client = $this->getClient();
     			$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=down'));
     			$response = $request->send();
         		$nbr_file++;
         		sleep(0.5);
     			}
     		$client = $this->getClient();
     		$request = $client->getClient()->createRequest('GET', get_url('http://hd1.freebox.fr/pub', 'remote_control?code='.Config::get('freebox.remote_code').'&key=ok'));
     		$response = $request->send();
     
     		}
     		}**/
 }