Ankündigung

Einklappen
Keine Ankündigung bisher.

HTTP Binding Webseite auslesen

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

    HTTP Binding Webseite auslesen

    Hallo,

    ich bin aktuell immer noch mit dem Umstieg von OH2 auf OH3 beschäftigt und jetzt ist das HTTP Binding an der Reihe.

    Dies wird benutz um eine Seite von der UVR1611 auszulesen und Daten bereit zu stellen.

    leider bekomme ich bei meiner aktuellen Konfiguration immer eine Fehlermeldung welche ich nicht interpretieren kann.

    Die Seite sieht so aus.

    Code:
    <!--2.0-->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <style type="text/css">
    body {font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; background-repeat: no-repeat; background-color: transparent; background: transparent; margin: 0px; padding: 0px;}
    #frame {text-align: left; vertical-align: top; position: relative; margin-left: 0;}
    
    /*########## CSS-ID: Positionen der Anzeigeparameter ##########*/
    #pos01 {top: 120px; right: 733px;}
    #pos02 {top: 104px; left: 42px;}
    #pos03 {top: 253px; left: 459px;}
    #pos04 {top: 320px; left: 458px;}
    #pos05 {top: 378px; left: 458px;}
    #pos06 {top: 429px; left: 458px;}
    #pos07 {top: 303px; left: 869px;}
    #pos08 {top: 415px; left: 869px;}
    #pos09 {top: 215px; right: 157px;}
    #pos10 {top: 87px; left: 793px;}
    #pos11 {top: 159px; right: 333px;}
    #pos12 {top: 287px; right: 404px;}
    #pos13 {top: 286px; right: 752px;}
    #pos14 {top: 218px; right: 857px;}
    #pos15 {top: 275px; right: 295px;}
    #pos16 {top: 13px; left: 801px;}
    #pos17 {top: 91px; left: 494px;}
    #pos18 {top: 10px; left: 494px;}
    #pos19 {top: 51px; left: 494px;}
    #pos20 {top: 57px; left: 205px;}
    #pos21 {top: 166px; right: 736px;}
    #pos22 {top: 158px; right: 166px;}
    #pos23 {top: 436px; right: 940px;}
    #pos24 {top: 136px; left: 495px;}
    #pos25 {top: 390px; right: 709px;}
    #pos26 {top: 434px; right: 710px;}
    
    /*########## CSS-Klasse: Darstellung der Anzeigeparameter ##########*/
    .style1 {font-family: Tahoma; font-size: 18px; text-align: right; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
    .style2 {font-family: Tahoma; font-size: 18px; text-align: left; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
    .style3 {font-family: Tahoma; font-size: 20px; text-align: right; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
    
    </style>
    
    <script type="text/javascript">
    <!--
    var Title ="Onlineschema"; // Titeltext im Browserfenster
    var GraphicFile = "GRAFIK.gif"; // Pfad der Grafikdatei
    var Width = "1020px";
    var Height = "760px";
    
    //### Intervallzeit [in Sekunden] f�r eine automatische Aktualisierung der Messwerte: ###
    //### < "30" = keine automatische Aktualisierung ###
    //--------------------------------------------------
    var AutoRefreshTime = "60";
    
    //### Linktext f�r manuelle Aktualisierung der Messwerte: ###
    //### "" = kein Link f�r manuelle Aktualisierung ###
    //--------------------------------------------------
    var RefreshLink ="Werte aktualisieren";
    
    function set_dimenson_para (){
    document.getElementById("frame").style.width = Width;
    document.getElementById("frame").style.hight = Height;
    }
    -->
    </script>
    
    </head>
    <body onload="set_dimenson_para ()">
    <div id="frame">
    
    <!--########## Definitionen der Anzeigeparameter ##########-->
    <div class="style1" id="pos01">33,3°C</div>
    <div class="style2" id="pos02">-3,4°C</div>
    <div class="style2" id="pos03">54,0°C</div>
    <div class="style2" id="pos04">34,7°C</div>
    <div class="style2" id="pos05">32,5°C</div>
    <div class="style2" id="pos06">32,8°C</div>
    <div class="style2" id="pos07">44,3°C</div>
    <div class="style2" id="pos08">30,7°C</div>
    <div class="style1" id="pos09">30,1°C</div>
    <div class="style2" id="pos10">32,7°C</div>
    <div class="style1" id="pos11">25,5°C</div>
    <div class="style1" id="pos12">0%</div>
    <div class="style1" id="pos13">0%</div>
    <div class="style1" id="pos14">39,8°C</div>
    <div class="style1" id="pos15">42,2°C</div>
    <div class="style2" id="pos16">50,7°C</div>
    <div class="style2" id="pos17">665,3KWh</div>
    <div class="style2" id="pos18">0,1KW</div>
    <div class="style2" id="pos19">16L/h</div>
    <div class="style2" id="pos20">21,7°C</div>
    <div class="style3" id="pos21">EIN</div>
    <div class="style3" id="pos22">AUS</div>
    <div class="style3" id="pos23">AUS</div>
    <div class="style2" id="pos24">45MWh</div>
    <div class="style1" id="pos25">21,6°C</div>
    <div class="style1" id="pos26">10%</div>
    
    </div>
    </body>
    </html>​
    Auslzulesen versuche ich sie mit.

    Code:
    Thing http:url:UVR "UVR Abfragen" [baseURL="=http://192.168.179.21/GRAFIK1.htm",refresh=15, timeout=3000, commandMethod="GET",delay=1000] {
            Channels:
             Type string : test "Text" [ stateTransformation="REGEX(.*?id=\"pos12\">(.*?)%.*)]" ]
    }​
    Die Fehlermeldung welche ich bekomme lautet


    Code:
    2023-02-09 10:08:41.656 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Creating request for '=http://192.168.179.21/GRAFIK1.htm' failed: no protocol: =http://192.168.179.21/GRAFIK1.htm
    Kann mir jemand sagen was ich falsch mache?
    Gruß

    Guido

    #2
    Da ist ein `=` zu viel in deinem Thing, so wie das ausschaut.

    Code:
    baseURL="http://192.168.179.21/GRAFIK1.htm"
    müsste das eigentlich heißen.

    Kommentar


      #3
      Zitat von Confectrician Beitrag anzeigen
      Da ist ein `=` zu viel in deinem Thing, so wie das ausschaut.

      Code:
      baseURL="http://192.168.179.21/GRAFIK1.htm"
      müsste das eigentlich heißen.
      Danke das hatte ich übersehen.

      Allerdings wird jetzt ein Teil des Quelltextes in das Item geschrieben.

      Code:
      <!--2.0-->
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="content-type" content="text/html;charset=utf-8" />
      <style type="text/css">
      body {font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; background-repeat: no-repeat; background-color: transparent; background: transparent; margin: 0px; padding: 0px;}
      #frame {text-align: left; vertical-align: top; position: relative; margin-left: 0;}
      
      /*########## CSS-ID: Positionen der Anzeigeparameter ##########*/
      #pos01 {top: 120px; right: 733px;}
      #pos02 {top: 104px; left: 42px;}​
      da hier ja pos12 ja nicht enthalten ist, funktioniert vermutlich das auswerten nicht richtig. Ist das an der Stelle überhaupt der richtige Weg?
      Gruß

      Guido

      Kommentar


        #4
        Die StateTransformation an sich ist schon der richtige weg.

        Man müsste jetzt prüfen, ob der Regex richtig arbeitet oder alternativ könnte man xpath nutzen.
        (Würde ich theoretisch bevorzugen, wenn die website immer gleich aufgebaut ist)

        Hat denn der Regex früher mal so funktioniert oder hast du den neu zusammengebaut?

        Edit:

        Folgender xpath sollte theoretisch ein korrektes Ergebnis liefern.
        Code:
        //div[@id='pos12'][1]/text()
        Xpath Transformation installieren und dann den Kanal laut https://www.openhab.org/addons/bindi...transformation konfigurieren.
        Zuletzt geändert von Confectrician; 09.02.2023, 14:00.

        Kommentar


          #5
          Ich habe das mal probiert, leider ohne Erfolg. Der Inhalt des Items ist in beiden Fällen gleich.

          Code:
          Type string : test "Text" [stateTransformation="XPath:/div[@id='pos12'][1]/text()"]
          }​
          XPhat habe ich natürlich installiert.
          Gruß

          Guido

          Kommentar


            #6
            Vermutlich musst Du XPATH schreiben, nicht XPath.

            Ach so... ich bin mir auch nicht sicher, ob XPath hier überhaupt funktionieren kann, schließlich ist das ja kein XML, was da geparst werden soll.
            Zuletzt geändert von udo1toni; 09.02.2023, 16:19.

            Kommentar


              #7
              Das Xpath sollte laut Anleitung korrekt sein (oder die Anleitung falsch), aber da fehlt auf jeden Fall ein zweiter Slash "/" in deinem Ausdruck vor dem div.
              Der ist wichtig für XPATH.

              Der doppelte Slash sorgt dafür, dass XPATH irgendwo in dem html nach dem div mit der id pos12 sucht.
              Mit einem einfachen Slash muss man genau dem html Baum folgen, um z.B. an untergeordnete Elemente zu kommen.
              So macht das dein Ausdruck für den "text()" part.
              Der XPATH sucht (//) irgendwo nach dem richtigen div und nimmt dann (/) den Text-Inhalt der drinsteht.

              Code:
              stateTransformation="XPath://div[@id='pos12'][1]/text()"

              Kommentar


                #8
                Leider funktioniert das auch nicht.egal ob groß oder klein geschrieben.

                Code:
                2023-02-09 17:42:30.079 [.transform.SingleValueTransformation] - Executing transformation ChannelStateTransformation{pattern='//div[@id='pos12'][1]/text()', serviceName='XPATH'} failed: transformation throws exceptions
                den vormaligen REGEX Code habe ich aus der OH 2 übernommen in der Annahme das dieser sich nicht geändert hat.
                Gruß

                Guido

                Kommentar


                  #9
                  Grundsätzlich würde der REGEX Ausdruck vermutlich noch passen, aber das Format ist ein anderes.
                  Du hattest in OH2 noch das http1 Binding, da wurde das als REGEX(<Ausdruck>) geschrieben. Neu sieht es so aus: REGEX:<Ausdruck>
                  Das hieße für Deine Konfiguration:
                  Code:
                  stateTransformation="REGEX:.*?id=\"pos12\">(.*?)%.*"
                  Alternativ könntest Du es auch so versuchen:
                  Code:
                  stateTransformation="REGEX:.*?id=.pos12.>(\d+?)%.*"
                  Also statt explizit nach Anfürungszeichen zu suchen einfach nach einem beliebigen Zeichen, was immer noch genau genug sein sollte. Dafür aber explizit ausschließlich nach Ziffern, und mindestens einer \d+, das geht natürlich nur falls kein Dezimalpunkt vorkommt.

                  Kommentar


                    #10
                    Leider führen beide codes nicht zum Erfolg.
                    Gibt es einen log an dem ich sehen kann was da flasch läuft?

                    Danke
                    Gruß

                    Guido

                    Kommentar


                      #11
                      Du könntest mal probieren, was Du bekommst, wenn Du den Channel als string Channel definierst und keine Transformation einträgst.

                      Ich habe das gerade hier mal durchgespielt, bei mir funktioniert es einwandfrei.
                      Mein Thing:
                      Code:
                      Thing http:url:test2 "aaaa Test2" [
                          baseURL="http://192.168.179.21/grafik1.htm",
                          refresh=15,
                          timeout=3000
                          ] {
                          Channels:
                              Type string : mytest "Testwert" [stateTransformation="REGEX:.*?id=.pos12.>(.*?)%.*"]
                      }
                      ​
                      Die IP ist bei mir natürlich eine andere. Die commandMethod ist mit GET der Default, spielt hier aber gar keine Rolle, da ja nur Daten abgerufen, aber nicht verändert werden. Das delay sollte keinen Einfluss haben.

                      In Deinem Ausgangspost (und auch bei dem zweiten Auszug aus der html Datei ein paar Posts tiefer) sind allerdings ein paar Zeichen durch die entsprechenden Codes ersetzt, im Einzelnen sind das <, >, & und °,
                      Kannst Du bitte mal schauen, ob das einfach hier beim Einfügen passiert ist, oder ob diese Zeichen tatsächlich so geliefert werden, denn dan passt der REGEX definitiv nicht.

                      Hast Du auch berücksichtigt, dass es beim Ändern bestehender Things und Channel über eine things Datei möglich ist, dass die Änderungen erst nach einem Neustart korrekt geladen werden?
                      Möglicher Workaround: kurz die betreffende UID ändern, speichern, wieder zurück ändern, erneut speichern.
                      Bei Änderung der UID wird das betreffende Objekt (Channel, Thing...) gelöscht und neu angelegt, das erzwingt das erneute Einlesen der Konfiguration.
                      Zuletzt geändert von udo1toni; 10.02.2023, 02:04.

                      Kommentar


                        #12
                        Hallo Udo,

                        das habe ich mal probiert ohne die Transformation steht in dem Item der Text der ganzen webseite drin.
                        Code:
                         
                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                         
                        <html xmlns="http://www.w3.org/1999/xhtml">
                         
                        <head>
                         
                        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
                         
                        <style type="text/css">
                         
                        body {font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; background-repeat: no-repeat; background-color: transparent; background: transparent; margin: 0px; padding: 0px;}
                         
                        #frame {text-align: left; vertical-align:[COLOR=var(--standard-txt)] to[/COLOR]p; position: relative; margin-left: 0;}
                         
                         
                         
                        /*########## CSS-ID: Positionen der Anzeigeparameter ##########*/
                         
                        #pos01 {top: 120px; right: 733px;}
                         
                        #pos02 {top: 104px; left: 42px;}
                         
                        #pos03 {top: 253px; left: 459px;}
                         
                        #pos04 {top: 320px; left: 458px;}
                         
                        #pos05 {top: 378px; left: 458px;}
                         
                        #pos06 {top: 429px; left: 458px;}
                         
                        #pos07 {top: 303px; left: 869px;}
                         
                        #pos08 {top: 415px; left: 869px;}
                         
                        #pos09 {top: 215px; right: 157px;}
                         
                        #pos10 {top: 87px; left: 793px;}
                         
                        #pos11 {top: 159px; right: 333px;}
                         
                        #pos12 {top: 287px; right: 404px;}
                         
                        #pos13 {top: 286px; right: 752px;}
                         
                        #pos14 {top: 218px; right: 857px;}
                         
                        #pos15 {top: 275px; right: 295px;}
                         
                        #pos16 {top: 13px; left: 801px;}
                         
                        #pos17 {top: 91px; left: 494px;}
                         
                        #pos18 {top: 10px; left: 494px;}
                         
                        #pos19 {top: 51px; left: 494px;}
                         
                        #pos20 {top: 57px; left: 205px;}
                         
                        #pos21 {top: 166px; right: 736px;}
                         
                        #pos22 {top: 158px; right: 166px;}
                         
                        #pos23 {top: 436px; right: 940px;}
                         
                        #pos24 {top: 136px; left: 495px;}
                         
                        #pos25 {top: 390px; right: 709px;}
                         
                        #pos26 {top: 434px; right: 710px;}
                         
                         
                         
                        /*########## CSS-Klasse: Darstellung der Anzeigeparameter ##########*/
                         
                        .style1 {font-family: Tahoma; font-size: 18px; text-align: right; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
                         
                        .style2 {font-family: Tahoma; font-size: 18px; text-align: left; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
                         
                        .style3 {font-family: Tahoma; font-size: 20px; text-align: right; font-style: normal; font-weight: bold; color: #000000; position: absolute;}
                         
                         
                         
                        </style>
                         
                         
                         
                        <script type="text/javascript">
                         
                        <!--
                         
                        var Title ="Onlineschema"; // Titeltext im Browserfenster
                         
                        var GraphicFile = "GRAFIK.gif"; // Pfad der Grafikdatei
                         
                        var Width = "1020px";
                         
                        var Height = "760px";
                         
                         
                         
                        //### Intervallzeit [in Sekunden] f�r eine automatische Aktualisierung der Messwerte: ###
                         
                        //### < "30" = keine automatische Aktualisierung ###
                         
                        //--------------------------------------------------
                         
                        var AutoRefreshTime = "60";
                         
                         
                         
                        //### Linktext f�r manuelle Aktualisierung der Messwerte: ###
                         
                        //### "" = kein Link f�r manuelle Aktualisierung ###
                         
                        //--------------------------------------------------
                         
                        var RefreshLink ="Werte aktualisieren";
                         
                         
                         
                        function set_dimenson_para (){
                         
                        document.getElementById("frame").style.width = Width;
                         
                        document.getElementById("frame").style.hight = Height;
                         
                        }
                         
                        -->
                         
                        </script>
                         
                         
                         
                        </head>
                         
                        <body onload="set_dimenson_para ()">
                         
                        <div id="frame">
                         
                         
                         
                        <!--########## Definitionen der Anzeigeparameter ##########-->
                         
                        <div class="style1" id="pos01">33,1&deg;C</div>
                         
                        <div class="style2" id="pos02">0,2&deg;C</div>
                         
                        <div class="style2" id="pos03">35,4&deg;C</div>
                         
                        <div class="style2" id="pos04">32,4&deg;C</div>
                         
                        <div class="style2" id="pos05">32,8&deg;C</div>
                         
                        <div class="style2" id="pos06">33,0&deg;C</div>
                         
                        <div class="style2" id="pos07">43,8&deg;C</div>
                         
                        <div class="style2" id="pos08">30,4&deg;C</div>
                         
                        <div class="style1" id="pos09">38,6&deg;C</div>
                         
                        <div class="style2" id="pos10">50,8&deg;C</div>
                         
                        <div class="style1" id="pos11">39,5&deg;C</div>
                         
                        [B]<div class="style1" id="pos12">0%</div>[/B]
                         
                        <div class="style1" id="pos13">12%</div>
                         
                        <div class="style1" id="pos14">59,9&deg;C</div>
                         
                        <div class="style1" id="pos15">35,7&deg;C</div>
                         
                        <div class="style2" id="pos16">55,6&deg;C</div>
                         
                        <div class="style2" id="pos17">668,4KWh</div>
                         
                        <div class="style2" id="pos18">0,2KW</div>
                         
                        <div class="style2" id="pos19">24L/h</div>
                         
                        <div class="style2" id="pos20">21,9&deg;C</div>
                         
                        <div class="style3" id="pos21">EIN</div>
                         
                        <div class="style3" id="pos22">EIN</div>
                         
                        <div class="style3" id="pos23">EIN</div>
                         
                        <div class="style2" id="pos24">45MWh</div>
                         
                        <div class="style1" id="pos25">48,8&deg;C</div>
                         
                        <div class="style1" id="pos26">25%</div>
                         
                         
                         
                        </div>
                         
                        </body>
                         
                        </html>
                         
                        ​
                        mit der Transformation steht

                        Code:
                        1970-01-01T00:00:00.000+0000
                        drin
                        Also es passiert schon was nur nicht das Richtige. Die Zeile um die es aktuell geht habe ich mal in fett markiert
                        Gruß

                        Guido

                        Kommentar


                          #13
                          Du kannst im Code keine Auszeichnungen verwenden, aber mir ist schon klar, welche Zeile es ist.
                          Letztlich passt der Wert auch, nur wird er leider als Datum ausgegeben,

                          Wenn Du ein String Item mit einem String Channel verknüpfst (und das sollte für die Testphase so sein) musst Du zusätzlich konfigurieren, damit das passiert.
                          Hast Du eventuell in den Metadaten etwas eingetragen, also z.B. State Description? Du könntest auch aus Versehen im Link ein Profile gesetzt haben, auch dort kann man die Formatierung beeinflussen (je nach Profile)

                          Kommentar


                            #14
                            Nein da habe ich eigentlich nichts gemacht.

                            Das Item sieht so aus

                            Code:
                            String UvrPos12 "UVR Pos12 [%s]" {channel="http:url:UVR:test"}
                            Gruß

                            Guido

                            Kommentar


                              #15
                              Meine Empfehlung: Lege einen neuen Channel an (andere ID), ebenso ein neues Item (anderer Name), aber mit den gleichen Einstellungen, schau, ob dieses neue Channel-Itempaar das tut, was es soll.

                              Kommentar

                              Lädt...
                              X