To get GlobalVar

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

To get GlobalVar

Postby Pik » Mon Jun 02, 2014 9:15 pm

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.
Pik
Starting Member
Starting Member
 
Posts: 33
Joined: April 2014

Re: To get GlobalVar

Postby emvee » Sun Jun 15, 2014 3:29 pm

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?
emvee
Starting Member
Starting Member
 
Posts: 24
Joined: January 2014

Re: To get GlobalVar

Postby uAlex73 » Tue Jun 17, 2014 1:22 pm

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
DomotiGa / Z-Wave / RFXCom / Visonic PowerMaster
uAlex73
Member
Member
 
Posts: 215
Joined: January 2012

Re: To get GlobalVar

Postby Pik » Tue Jun 17, 2014 6:13 pm

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.
Pik
Starting Member
Starting Member
 
Posts: 33
Joined: April 2014

Re: To get GlobalVar

Postby Pik » Tue Jun 24, 2014 4:41 pm

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.
Pik
Starting Member
Starting Member
 
Posts: 33
Joined: April 2014


Return to DomotiGa Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron