FHEM Forum

FHEM => Sonstiges => Thema gestartet von: Oli_t am 16 August 2019, 10:39:49

Titel: HTTPMOD unerwartetes Ergebnis / Comexio Anbindung Onewire Fühler
Beitrag von: Oli_t am 16 August 2019, 10:39:49
Hallo,

ich möchte gerne einen Wert aus einem anderen Server per HTTP auslesen. Dazu habe ich mir ein Gerät "Aussentemperatur" per HTTPMOD erstellt:


Internals:
   BUSY       0
   CFGFN     
   DEF        https://*******@192.168.0.35/api/?action=get&onewire=OT5 60
   FUUID      5d5641c0-f33f-c6cc-fbef-53883a93958371db
   Interval   60
   LASTSEND   1565943915.88193
   MainURL    https://*******@192.168.0.35/api/?action=get&onewire=OT5
   ModuleVersion 3.5.9 - 13.2.2019
   NAME       Aussentemperatur
   NOTIFYDEV  global
   NR         11434
   NTFY_ORDER 50-Aussentemperatur
   STATE      0
   TRIGGERTIME 1565943975.87433
   TRIGGERTIME_FMT 2019-08-16 10:26:15
   TYPE       HTTPMOD
   addr       https://192.168.0.35:443
   auth       1
   buf       
   code       200
   compress   1
   conn       
   data       
   displayurl https://*******@192.168.0.35/api/?action=get&onewire=OT5
   header     
   host       192.168.0.35
   httpbody   14.31
   httpheader HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Connection: close
Date: Fri, 16 Aug 2019 08:17:59 GMT
Server: comexio
   httpversion 1.1
   hu_blocking 0
   hu_filecount 90
   hu_port    443
   hu_portSfx
   ignoreredirects 0
   loglevel   4
   path       /api/?action=get&onewire=OT5
   protocol   https
   pwd        *******
   redirects  0
   timeout    2
   url        https://*******@192.168.0.35/api/?action=get&onewire=OT5
   user       *******
   value      0
   QUEUE:
   READINGS:
     2019-08-16 10:25:17   LAST_ERROR     
     2019-08-16 10:25:17   LAST_REQUEST    update
     2019-08-16 10:17:56   MATCHED_READINGS temp
     2019-08-16 10:17:56   UNMATCHED_READINGS
     2019-08-16 10:17:56   temp            HTTP/1.1 200 OK
   REQUEST:
     data       
     header     
     ignoreredirects 0
     retryCount 0
     type       update
     url        https://*******@192.168.0.35/api/?action=get&onewire=OT5
     value      0
   defptr:
     readingBase:
       temp       reading
     readingNum:
       temp       01
     readingOutdated:
     requestReadings:
       update:
         temp       reading 01
   sslargs:
Attributes:
   enableControlSet 1
   httpVersion 1.1
   reading01Name temp
   reading01Regex (.*)
   showBody   1
   showError  1
   showMatched 1
   userattr   reading01Name reading01Regex


Als Regex habe ich (.*) eingetragen. Scheinbar habe ich da zu einfach gedacht: Es kommt dann nämlich nur "HTTP/1.1 200 OK" als Wert zurück. Wenn ich in den "httpbody" gucke, steht da aber der Wert, den ich eigentlich gerne hätte. Was mache ich falsch ? Dieses Gerät liefert wirklich nur den Wert als Antwort zurück. Kann es daran liegen ? Fehlen HTTPMOD die HTTP-Header ?

Viele Grüße,

Oli
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 12:02:03
ändere die regex auf "(?s)(.*)" und zeige, was im reading temp steht.
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 17:00:38
Hallo Frank,
leider findet er dann gar keinen Match. Das Reading bleibt leer und im Log kommt: "Aussentemperatur: Read response to update didn't match any Reading". Spasseshalber habe ich die URL mal mit curl angefunkt: wie erwartet kommt da der richtige Wert zurück  ::)
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 17:29:32
ohne anführungszeichen?
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 17:34:21
Ah, ich Dummerchen natürlich !  :-[


temp


HTTP/1.1 200 OK
Set-Cookie: comexio_session_id=gnsbtfi3qdtu0ilfjejs39u804; expires=Fri, 23-Aug-2019 15:23:26 GMT; path=/
Set-Cookie: comexio_session_id=gnsbtfi3qdtu0ilfjejs39u804; expires=Fri, 23-Aug-2019 15:23:26 GMT; path=/
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
Content-Type: text/plain; charset=utf-8
X-Powered-By: COMEXIO
Content-Length: 7
Connection: close
Date: Fri, 16 Aug 2019 15:23:26 GMT
Server: comexio

19.875


Da merkt man, dass ich noch nicht oft mit Regex zu tun hatte  ;D
Wie bekomme ich jetzt den "Vorspann" weg ?
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 17:54:01
probiere: "(?s).*([0-9.]+)$"
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 18:04:09
Leider findet er dann Nichts. Auch ohne Anführungszeichen  ;)
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 18:32:26
ok, 2 versuch. :)
(?s).*?([0-9.]+)$
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 18:39:45
Nö, kann er auch nicht matchen. Kann man den Header nicht einfach abschneiden?
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 18:47:43
und dies?
(?s)([0-9.]+)$

Zitatabschneiden
du meinst alles einsammeln und im 2. schritt den string kürzen?
geht auch, aber es muss auch mit regex funktionieren.  ;)
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 18:52:16
Das findet leider auch Nichts.
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 18:59:13
seltsam. zeig noch mal ein list.
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 19:14:50


Internals:
   BUSY       0
   CFGFN     
   DEF        https://*******@192.168.0.35/api/?action=get&onewire=OT5 30
   FUUID      5d56c685-f33f-07f4-a156-abeb89e82df9479c
   Interval   30
   LASTSEND   1565975137.66192
   MainURL    https://*******@192.168.0.35/api/?action=get&onewire=OT5
   ModuleVersion 3.5.9 - 13.2.2019
   NAME       Aussentemperatur
   NOTIFYDEV  global
   NR         3536
   NTFY_ORDER 50-Aussentemperatur
   STATE      ???
   TRIGGERTIME 1565975167.66073
   TRIGGERTIME_FMT 2019-08-16 19:06:07
   TYPE       HTTPMOD
   addr       https://192.168.0.35:443
   auth       1
   buf       
   code       200
   compress   1
   conn       
   data       
   displayurl https://*******@192.168.0.35/api/?action=get&onewire=OT5
   header     
   host       192.168.0.35
   httpbody   18.437
   httpheader HTTP/1.1 200 OK
Set-Cookie: comexio_session_id=dao3ukvgdeupki4a47bl0aehm5; expires=Fri, 23-Aug-2019 17:05:40 GMT; path=/
Set-Cookie: comexio_session_id=dao3ukvgdeupki4a47bl0aehm5; expires=Fri, 23-Aug-2019 17:05:40 GMT; path=/
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
Content-Type: text/plain; charset=utf-8
X-Powered-By: COMEXIO
Content-Length: 7
Connection: close
Date: Fri, 16 Aug 2019 17:05:40 GMT
Server: comexio
   httpversion 1.1
   hu_blocking 0
   hu_filecount 163
   hu_port    443
   hu_portSfx
   ignoreredirects 0
   loglevel   4
   path       /api/?action=get&onewire=OT5
   protocol   https
   pwd        *******
   redirects  0
   timeout    2
   url        https://*******@192.168.0.35/api/?action=get&onewire=OT5
   user       *******
   value      0
   QUEUE:
   READINGS:
     2019-08-16 19:04:42   LAST_ERROR      https://*******@192.168.0.35/api/?action=get&onewire=OT5: Can't connect(2) to https://192.168.0.35:443:  SSL wants a read first
     2019-08-16 19:05:39   LAST_REQUEST    update
     2019-08-16 19:05:39   MATCHED_READINGS
     2019-08-16 19:05:39   UNMATCHED_READINGS temp
     2019-08-16 19:00:12   temp            1
   REQUEST:
     data       
     header     
     ignoreredirects 0
     retryCount 0
     type       update
     url        https://*******@192.168.0.35/api/?action=get&onewire=OT5
     value      0
   defptr:
     readingBase:
       temp       reading
     readingNum:
       temp       01
     readingOutdated:
     requestReadings:
       update:
         temp       reading 01
   sslargs:
Attributes:
   enableControlSet 1
   httpVersion 1.1
   reading01Name temp
   reading01Regex (?s)([0-9.]+)$
   showBody   1
   showError  1
   showMatched 1
   userattr   reading01Name reading01Regex


Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: frank am 16 August 2019, 19:41:25
(?s)([0-9.]+).$
(?s)(......)$
Titel: Antw:HTTPMOD unerwartetes Ergebnis
Beitrag von: Oli_t am 16 August 2019, 21:38:40
Das Obere funktioniert !   ;D
Krass ! Wie findet man Sowas ?
Titel: Antw:HTTPMOD unerwartetes Ergebnis / Comexio Anbindung Onewire Fühler
Beitrag von: frank am 16 August 2019, 22:03:28
dann gibt es also noch ein verstecktes zeichen am schluss.

zum testen probiere mal "regex101.com".