Page 1 of 1

To get GlobalVar

Posted: Mon Jun 02, 2014 10:15 pm
by Pik
Hello,

I use few specific globalvars in Domotiga.
I created my own web page to read Domotiga status based on Domotiga PHP page. Working fine.

First I use this code (extract from functions.php):

Code: Select all

function do_xmlrpc($request) {
   global $rpc_connect;
   global $use_curl;

   if ( $use_curl == "yes" ) {
      $ch = curl_init($rpc_connect);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
      curl_setopt($ch, CURLOPT_POSTFIELDS, "$request");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $context = curl_exec($ch);
      if ( curl_error($ch) == "" ) {
         curl_close($ch);
         return xmlrpc_decode($context,"UTF-8");
      } else {
         curl_close($ch);
         die ("<h2>Cannot connect to the DomotiGa server!</h2>");
      }
   } else {
      $context = stream_context_create(array('http' => array('method' => "POST",'header' =>"Content-Type: text/xml",'content$
      if ($file = @file_get_contents($rpc_connect, false, $context)) {
         $file=str_replace("i8","double",$file);
         return xmlrpc_decode($file, "UTF-8");
      } else {
         die ("<h2>Cannot connect to the DomotiGa server!</h2>");
      }
   }
}
No change for this function (just for reference).


Based on this, I created a function to get Globalvar list :

Code: Select all

// Get Globalvar list
function get_globalvar_list() {
   $request = xmlrpc_encode_request("globalvar.list",null);
   $response = do_xmlrpc($request);
   if (xmlrpc_is_fault($response)) {
       trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
   } else {
      $index=0;
      foreach($response AS $item) {
      list($retarr[$index]['globalvarname'], $retarr[$index]['globalvarvalue']) = explode (';;', $item);
      $index++;
      }
   if (isset($retarr)) {
         return $retarr;
   } else {
         return FALSE;
         }
   }
}
This is working fine but I get only globalvar name. As you can see in code above, I try to read value but nothing to read.
I used print_r($response) to see the array and there is no value... only a globalvar name. So I think I have to use globalvar.get to read the value.. isn't it ?

Question :
How to get/read a globalvar in PHP ?
I tried to use Globalvar.get but with no real success !

I found this page http://www.domotiga.nl/projects/domotig ... igaversion but I don't understand how to use this globalvar.get method...

Could you help me to understand how to use this method ?

Thanks a lot in advance for your support.

Regards.

Re: To get GlobalVar

Posted: Sun Jun 15, 2014 4:29 pm
by emvee
How to get/read a globalvar in PHP ?
I tried to use Globalvar.get but with no real success !
I have no experience with PHP but looking at the Domotiga sources I think globalvar.get (without Capital) must return a list of all global variables with their values.
What kind of error do you get when you try globalvar.get?

Re: To get GlobalVar

Posted: Tue Jun 17, 2014 2:22 pm
by uAlex73
Also have a look in the tes-tool directory, here is a perl script which shows the functionality of the json-rpc server:

test-tools/json-rpc/json-rpc.pl

Re: To get GlobalVar

Posted: Tue Jun 17, 2014 7:13 pm
by Pik
Hello,

Thanks.
Further to Capital letter : I tried and no change.

I'll have a look into test-tool... I keep in touch with you... later as busy this week...

Best regards.

Re: To get GlobalVar

Posted: Tue Jun 24, 2014 5:41 pm
by Pik
Hello,

So I tried again and again but I don't find the good PHP code. Nevermind, later, perhpas with more experience, I'll be able to write this code.

Regards.