Ankündigung

Einklappen
Keine Ankündigung bisher.

EibLib/Ip & EibNet/IP

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Warichet
    antwortet
    Zitat von jef2000 Beitrag anzeigen
    You can also replace it by require_once('eibclient.php'); to be sure it doesn't try to include it multiple times.
    I've streamlined the code a bit and put "require_once" everywhere I could (even where it doesn't make sense )
    I works
    I have a (almost) decent Visu on the phone now.

    Merci Jean-François

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von mkoegler Beitrag anzeigen
    First parameter is an EIBD connection
    I did a cut & paste of the function cacheread and tried to use it as described. But I get

    PHP Fatal error: Call to undefined function gaddrparse() in /srv/www/htdocs/Cisco/interieur/premier/chambre-amis/eclairage-plafond.php on line 75
    I'm not sure I may use it "as is", maybe it expects some environment ?
    I tried to add "require('eibclient.php');" but it has other side effects.

    Zitat von mkoegler Beitrag anzeigen
    send.php contains code for sending. If you want to adapt the application to your installation, you need to modify config.php.
    OK, I might resort to this solution if I get stuck. But I'm a bit reluctant as the interface with the Cisco phone isn't very easy and my application is almost finished (besides refreshing the KNX status to display the current icone)

    Thank you for your help

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von jef2000 Beitrag anzeigen

    From the error message you receive, I would say that the second parameter of GroupRead function doesn't contain a correctly formatted group address.
    There is no reason to suspect the parameter, as it is the same used in the first call.... until I realize I've made a big mistake
    The second call to GroupRead is issued from within another function and I thought the parameters are inherited from the main script. Not true in PHP.
    I declared the variables as "global" within the calling function, but then I got again the original error messages.
    So I applied again both of your previous suggestions, no luck. The original error message is back again:
    PHP Fatal error: Cannot redeclare class EIBBuffer in /usr/share/php5/eib
    client.php on line 28
    Thank you for your help.

    Einen Kommentar schreiben:


  • jef2000
    antwortet
    Zitat von Warichet Beitrag anzeigen
    This happens when I add a second call to GroupRead, like:
    $MyStat=GroupRead("127.0.0.1",$ga2);
    Hi,

    From the error message you receive, I would say that the second parameter of GroupRead function doesn't contain a correctly formatted group address. This parameter must contain a group address with the format "x/y/z".

    The message "Undefined offset: 1 in /usr/share/php5/GroupRead.php on line 8" says that the second parameter doesn't contain any '/' character.
    The message "Undefined offset: 2 in /usr/share/php5/GroupRead.php on line 8" says that the second parameter only contains one '/' character.
    Just add a print("GA: $ga2"); before the call to GroupRead and you will see what's wrong.

    Regards,

    Jean-François

    Einen Kommentar schreiben:


  • mkoegler
    antwortet
    Zitat von Warichet Beitrag anzeigen
    But would you be so kind to point me to a description of the expected params ?
    First parameter is an EIBD connection


    Code:
    $connection = new EIBConnection("hostname");
    // If you don't have enabled Group Cache (eg. with EIBD command line switch), you need to enable
    $connection->EIB_Cache_Enable ();
    The connection can be used in all parts of your script. The second parameter is the group address (eg. "1/1/1"). The third parameter $age is a little bit more complex.

    Let me first start with the function of group cache: It keeps the last telegram for all group addresses, so that you can query the state of a group object without any delay. If there isn't any value for a group object, EIBD request it via A_GroupValue_Read.

    To simplify the interface, EIBD has no knowlege about the objects. It is the responsibility of the application to know, if a group object is suitable for querying. Eg: EIBD will provide you the last value of a up/down dimmer button, although it does not make any sense.

    $age provides greater control over the result. if it is 0, you get the last cached value. Else: It provides the last cached value, if its not older than $age seconds. If its older than $age, it requests a new value from the bus.

    In many cases 0 should work. A age > 0 can be used to reduce bus load.

    For interpreting the result (errors!!), please look at fetchstats in contrib/eibdvis/layout.php. It decodes the 3 error codes. Otherwise it returns the raw value. elements.php contains code to interpret this value for some common devices.

    send.php contains code for sending. If you want to adapt the application to your installation, you need to modify config.php. It creates containers ("rooms") and puts devices into them. Look at the _construct functions in elements.php for the parameter for the various devices. The first addresses ($*addr) contain the group addresses for sending telegrams to. Then the addresses for querying the state ($*stateaddr) follow. In simple installation both can be the same group address. $*age can be used the control the fetch interval.

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von mkoegler Beitrag anzeigen
    For an example look at function cacheread in contrib/eibdvis/help.php, BCU SDK sources.
    Thank you for the pointer.
    function cacheread ($con, $addr, $age = 0)
    But would you be so kind to point me to a description of the expected params ?

    Sorry to be a pain

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Hi,
    Zitat von jef2000 Beitrag anzeigen
    Can you give the exact error message you get?
    Here it is. It's a bit confusing.
    PHP Fatal error: Cannot redeclare class EIBBuffer in /usr/share/php5/eibclient.php on line 28
    This happens when I add a second call to GroupRead, like:
    $MyStat=GroupRead("127.0.0.1",$ga2);
    NB: Obviously, I didn't touch the eibclient.php
    Removing the second instance cures the problem, this makes me think I'm performing something illegal, like reading from a closed port, or opening something already open etc

    Zitat von jef2000 Beitrag anzeigen
    The only thing I see is to move the require('eibclient.php'); line outside of the function. (at the beginning of the file, for example).
    I've done it, no luck
    PHP Notice: Undefined offset: 2 in /usr/share/php5/GroupRead.php on line 8
    Zitat von jef2000 Beitrag anzeigen
    You can also replace it by require_once('eibclient.php').
    I've done it, no luck
    PHP Notice: Undefined offset: 1 in /usr/share/php5/GroupRead.php on line 8
    Thank you very much for your kind help.

    Einen Kommentar schreiben:


  • jef2000
    antwortet
    Hi,

    Can you give the exact error message you get?

    The only thing I see is to move the require('eibclient.php'); line outside of the function. (at the beginning of the file, for example). You can also replace it by require_once('eibclient.php'); to be sure it doesn't try to include it multiple times.

    Regards,

    Jean-François

    Einen Kommentar schreiben:


  • mkoegler
    antwortet
    Zitat von Warichet Beitrag anzeigen
    It seems that it's not allowed to call the "groupread" function several times in the the same script, probably due to some initialization stuff that should only happen once.
    Try switching to the group cache (EIB_Cache_Read_Sync). Then EIBD will do the whole thing for you.

    For an example look at function cacheread in contrib/eibdvis/help.php, BCU SDK sources.

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von jef2000 Beitrag anzeigen

    I tried to write a couple of examples with the php interface to see how it works.
    groupread.php
    Hi,

    It seems that it's not allowed to call the "groupread" function several times in the the same script, probably due to some initialization stuff that should only happen once.

    Any hint as to where to cut ?

    Thank you.

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von mkoegler Beitrag anzeigen
    I hope, you have noticed contrib/eibdvis in the BCU SDK sources. It is my PHP demo for our demonstation system.
    No, I missed it
    Thank you for the pointer

    Einen Kommentar schreiben:


  • mkoegler
    antwortet
    Zitat von Warichet Beitrag anzeigen
    Pointing me to a piece of PHP code, with a practical example of the client library usage would be appreciated, especially the syntax of using a BCU1.
    So far, I've only found PHP samples making use of IP.
    I hope, you have noticed contrib/eibdvis in the BCU SDK sources. It is my PHP demo for our demonstation system.

    Einen Kommentar schreiben:


  • jef2000
    antwortet
    Hi,

    Now it's clear. The -1 comes from here:
    Zitat von Warichet Beitrag anzeigen
    Code:
      $return=-1;
    And the rest ( "124" ) from here:
    Zitat von Warichet Beitrag anzeigen
    Code:
            $return=$return.$buf[$i];
    The code above is a concatenation of the previous value of "$return" (here -1) with $buf[$i] which contains the next byte of the message received from bus (here 124).

    As you discovered it, 124 is the dimmer status value with 0=0% and 255=100% . (124 * 100/255 = 48,6 ~= 49)

    Regards,

    Jean-François

    Einen Kommentar schreiben:


  • Warichet
    antwortet
    Zitat von jef2000 Beitrag anzeigen
    explain what you do with variable $return before returning it.
    I haven't touched your code very much (would really be unable to do it )

    Zitat von jef2000 Beitrag anzeigen
    How do you "cast the return code to a single byte" ?
    So far, I didn't, as I wasn't really aware of the cause of the problem.

    Code:
    <?php
    function GroupRead($ip,$ga)   // credit: Jef2000
      {
      require('eibclient.php');   // see php.ini for inlude_path=/usr/share/php5
      $return=-1;
      $con = new EIBConnection($ip);
      $dest = split('/', $ga);
      $dest_addr = (($dest[0] & 0x01f) << 11) | (($dest[1] & 0x07) << 8) | (($dest[2] & 0xff));
      if ($con->EIBOpenT_Group ($dest_addr, 0) == -1) exit("Connect failed");
      $data = chr(0).chr(0);
      $len = $con->EIBSendAPDU($data);
      if ($len == -1) exit("Request failed");
      // print("Send request"."\n");
     
      while (1)
        {
        $data = new EIBBuffer();
        $src = new EIBAddr();
        $len = $con->EIBGetAPDU_Src($data, $src);
        if ($len == -1) exit("Read failed");
        if ($len < 2) exit("Invalid Packet");
        $buf = unpack("C*", $data->buffer);
        if ($buf[1] & 0x3 || ($buf[2] & 0xC0) == 0xC0)
          {
          printf("Error: Unknown APDU: %02X%02X\n", $buf[1], $buf[2]);
          }
        else if (($buf[2] & 0xC0) == 0x40)
          {
          if ($len == 2)
            {
            // printf ("%02X\n", $buf[2] & 0x3F);
            $return=$buf[2] & 0x3F;
            }
          else
            {
            for ($i=3; $i<=$len; $i++)
            /* printf ("%02X", $buf[$i]);
            printf ("\n");
            */
            $return=$return.$buf[$i];
            }
          break;
          }
        }
      $con->EIBClose();
      return $return;     // return the EIB status, 0=Off, 1=On, xx-dimmer value
      }
    ?>

    Einen Kommentar schreiben:


  • jef2000
    antwortet
    Zitat von Warichet Beitrag anzeigen
    The end of the function is like this
    Code:
      $con->EIBClose();
      return $return;     // return the EIB status, 0=Off, 1=On, xx-dimmer value
      }
    ?>
    Could you post more code? Especially to explain what you do with variable $return before returning it. How do you "cast the return code to a single byte" ?

    Regards,

    Jean-François

    Einen Kommentar schreiben:

Lädt...
X