To get GlobalVar

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

Post Reply
Pik
Starting Member
Starting Member
Posts: 33
Joined: Sun Apr 13, 2014 2:14 pm

To get GlobalVar

Post 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.
emvee
Starting Member
Starting Member
Posts: 24
Joined: Sat Jan 18, 2014 1:42 pm

Re: To get GlobalVar

Post 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?
uAlex73
Member
Member
Posts: 218
Joined: Sun Jan 01, 2012 3:42 pm
Contact:

Re: To get GlobalVar

Post 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
DomotiGa / Z-Wave / RFXCom / Visonic PowerMaster / Home Assistant / Zigbee2MQTT / DSMR Reader / Toon1 (rooted)
Pik
Starting Member
Starting Member
Posts: 33
Joined: Sun Apr 13, 2014 2:14 pm

Re: To get GlobalVar

Post 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.
Pik
Starting Member
Starting Member
Posts: 33
Joined: Sun Apr 13, 2014 2:14 pm

Re: To get GlobalVar

Post 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.
Post Reply

Return to “DomotiGa Forum”