Ankündigung

Einklappen
Keine Ankündigung bisher.

EibLib/Ip & EibNet/IP

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

    #31
    Hi Jean-François,

    Zitat von jef2000 Beitrag anzeigen
    No, there is no trick to know what datatype is transmitted on the bus. This information is not transmitted.
    Thank you for the quick and to-the-point reply. I confirms what I expected

    Zitat von jef2000 Beitrag anzeigen
    If you want to make something generic that fits in the KNX model, you'll have to deal with that.
    OK, I'm learning a bit everyday...

    Nevertheless, I'm still puzzled with what I get.
    A concrete example: dimmer Merten 649315 4x150W
    The status feedback data is 1Byte.
    When I read it with GroupRead, I get "-1124" ?!? ûû that doesn't fit in one Byte !
    So I guess either my test is wrong or some conversion has to be done.
    Any hint ?
    NB: the Visu duly shows "49%" which is the actual state of the brightness. I can't see any link between 49 and 1124.
    Well, after making several tests, I'll try a conclusion
    drop the -1 of -1124, so it's 124
    124 = 49% of 255

    Kommentar


      #32
      Zitat von Warichet Beitrag anzeigen
      When I read it with GroupRead, I get "-1124" ?!? ûû that doesn't fit in one Byte !
      Hi,

      Can you tell a bit more about what you call "GroupRead". Is it the groupread.php script I have written? I don't think so because it's displaying hexadecimal values. Or the groupread example program of eibd? I don't think so, because it's not supposed to return any value. Then what else could it be?

      Regards,

      Jean-François

      Kommentar


        #33
        Zitat von jef2000 Beitrag anzeigen
        Can you tell a bit more about what you call "GroupRead". Is it the groupread.php script I have written?
        Yes.
        I'm using both of your scripts throughout the application and it works fine.

        One minor modification, I've repackaged your code to make it a function to make it re-usable, but don't think it would alter the behaviour, unless I've to cast the return code to a single byte ?

        I use it this way
        Code:
        $status = GroupRead("127.0.0.1",$ga2);
        echo "<!-- Status= ".$status. "-->";
        The end of the function is like this
        Code:
          $con->EIBClose();
          return $return;     // return the EIB status, 0=Off, 1=On, xx-dimmer value
          }
        ?>

        Kommentar


          #34
          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

          Kommentar


            #35
            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
              }
            ?>

            Kommentar


              #36
              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

              Kommentar


                #37
                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.

                Kommentar


                  #38
                  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

                  Kommentar


                    #39
                    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.

                    Kommentar


                      #40
                      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.

                      Kommentar


                        #41
                        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

                        Kommentar


                          #42
                          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.

                          Kommentar


                            #43
                            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

                            Kommentar


                              #44
                              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.

                              Kommentar


                                #45
                                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

                                Kommentar

                                Lädt...
                                X