Neue Version von HTTPMOD mit neuen Features zum Testen

Begonnen von StefanStrobel, 05 Dezember 2015, 08:31:32

Vorheriges Thema - Nächstes Thema

amenomade

@wires.io: Läuft Fhem in einem Container? In einem anderen Thread scheint jemand das gleiche Problem zu haben. Bei ihm läuft Fhem auf einem LXC unter Proxmox.
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

wires.io

Nein, FHEM läuft "direkt" auf Debian.

Was bedeutet eigentlich das hier?

Read callback: Error: read from http://192.168.178.93:8081 timed out

Versucht FHEM hier ein GET auf http://192.168.178.93:8081? Das lässt der Sonoff nämlich nicht zu.

ch.eick

#857
Und schon wieder eine neue Frage :-)

Bei einer Abfrage bekomme ich ein MOSMIX_L_2020091003_P0178.kmz File geliefert. Dies muss jedoch erst entpackt werden:

cat MOSMIX_L_2020091003_P0178.kmz |gzip -d

Kann ich das im HTTPMOD mit einbauen, um dann die xml Datei in readings einzulesen?

EDIT: Momentan ist die komprimierte Datei im httpbody bereits zu sehen

2020.09.10 10:58:13.281 5: HttpUtils response header:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Sep 2020 08:58:13 GMT
Content-Type: application/vnd.google-earth.kmz
Content-Length: 15321
Last-Modified: Thu, 10 Sep 2020 04:27:13 GMT
Connection: close
ETag: "5f59ab21-3bd9"
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000
Accept-Ranges: bytes
2020.09.10 10:58:13.281 4: DWD_Forecast: Read callback: request type was get01 retry 0,
header: HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Sep 2020 08:58:13 GMT
Content-Type: application/vnd.google-earth.kmz
Content-Length: 15321
Last-Modified: Thu, 10 Sep 2020 04:27:13 GMT
Connection: close
ETag: "5f59ab21-3bd9"
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000
Accept-Ranges: bytes, body length 15321
2020.09.10 10:58:13.281 5: DWD_Forecast: Read callback: body
�"*QMOSMIX_L_2020091003_P0178.kml�}]��������aP�


EDIT:
Ich könnte jetzt mit Regex auf QMOSMIX_L_2020091003_P0178.kml reagieren.                                                 <<<< das geht nicht, vermutlich weil es komprimiert ist.
Oder eventuell auf "Content-Type: application/vnd.google-earth.kmz", das zeigt ja bereits das Format an.        <<<< das geht aber


Internals:
   BUSY       0
   CFGFN     
   DEF        https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml 0
   FUUID      5f59e83a-f33f-61a8-ecbe-6a9f4105b5a07b62
   Interval   0
   LASTSEND   1599739799.32837
   MainURL    https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml
   ModuleVersion 3.5.22 - 7.2.2020
   NAME       DWD_Forecast
   NOTIFYDEV  global
   NR         111673
   NTFY_ORDER 50-DWD_Forecast
   STATE      ???
   TRIGGERTIME 0
   TRIGGERTIME_FMT
   TYPE       HTTPMOD
   addr       https://opendata.dwd.de:443
   auth       0
   buf       
   code       200
   compress   1
   conn       
   data       
   displayurl https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml/MOSMIX_L_LATEST_P0178.kmz
   header     
   host       opendata.dwd.de
   httpbody   PK�N*QMOSMIX_L_2020091009_P0178.kml�}]�������

snip.....

�N*Q{#��:tAMOSMIX_L_2020091009_P0178.kmlPKK;

   httpheader HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Sep 2020 12:09:59 GMT
Content-Type: application/vnd.google-earth.kmz
Content-Length: 15218
Last-Modified: Thu, 10 Sep 2020 09:57:20 GMT
Connection: close
ETag: "5f59f880-3b72"
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000
Accept-Ranges: bytes
   httpversion 1.0
   hu_blocking 0
   hu_filecount 39
   hu_port    443
   hu_portSfx
   ignoreredirects 1
   loglevel   4
   path       /weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml/MOSMIX_L_LATEST_P0178.kmz
   protocol   https
   redirects  0
   timeout    2
   url        https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml/MOSMIX_L_LATEST_P0178.kmz
   value      0
   CompiledRegexes:
   OLDREADINGS:
   QUEUE:
   READINGS:
     2020-09-10 14:09:59   Daten           PK�N*QMOSMIX_L_2020091009_P0178.kml�}]��������aP� [���W���|m�_

Die Daten wären nun in einem reading...

�N*Q{#��:tAMOSMIX_L_2020091009_P0178.kmlPKK;
     2020-09-10 14:09:59   P0178           1
   REQUEST:
     data       
     header     
     ignoreredirects 0
     retryCount 0
     type       get01
     url        https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml/MOSMIX_L_LATEST_P0178.kmz
     value      0
   defptr:
     readingBase:
       P0178      reading
     readingNum:
       P0178      01
     readingOutdated:
     requestReadings:
       get01:
         P0178      reading 01
   sslargs:
Attributes:
   DbLogExclude .*
   get01Name  P0178
   get01URL   https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/P0178/kml/MOSMIX_L_LATEST_P0178.kmz
   reading01Name P0178
   reading01Regex vnd.google-earth.kmz
   room       Informationen->Wetter,Strom->Photovoltaik
   showBody   1
   userReadings Daten:P0178.* {InternalVal("DWD_Forecast","httpbody","");;}
 
   verbose    5


Jetzt fehlt noch der Syntax für das Perl interne gunzip/gzip . Das Problem ist, dass ich nicht eine Variable übergeben kann und den Output dann auf STDOUT ausgegeben bekomme.

Das hier sollte von STDIN lesen, aber wie bekomme ich den Inhalt einer Variable im Perl auf STDIN des nächsten Befehls????

gzip "-" => "-"
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

ch.eick

#858
Zitat von: wires.io am 10 September 2020, 11:14:47
Versucht FHEM hier ein GET auf http://192.168.178.93:8081? Das lässt der Sonoff nämlich nicht zu.
Das kannst Du im verbose 5 Log sehen, wenn der Aufruf gemacht wird.

Es wird ein POST gemacht

2020.09.08 20:49:34 5: HttpUtils request header:
POST /zeroconf/switch HTTP/1.0
Host: 192.168.178.93:8081
User-Agent: fhem
Accept-Encoding: gzip,deflate
Content-Length: 46
Content-Type: application/x-www-form-urlencoded


Zeig nochmal ein aktuelles Log mit den set01Header* , die Du jetzt verwendest. Hattest Du meinen Vorschlag auch schon probiert?
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

wires.io

Zitat von: ch.eick am 10 September 2020, 11:20:02
Hattest Du meinen Vorschlag auch schon probiert?

Habe ich:

2020.09.10 11:28:16 5: sonoffdiy: set called with on
2020.09.10 11:28:16 5: sonoffdiy: set found option on in attribute set02Name
2020.09.10 11:28:16 4: sonoffdiy: set will now set on
2020.09.10 11:28:16 5: sonoffdiy: AddToQueue adds type set02 to URL http://192.168.178.93:8081/zeroconf/switch, data { "deviceid": "", "data": { "switch": "on" } }, header Accept: */*
Content-Type: application/x-www-form-urlencoded
charset=utf-8, retry 0, initial queue len: 0
2020.09.10 11:28:16 5: sonoffdiy: HandleSendQueue called, qlen = 1
2020.09.10 11:28:16 4: sonoffdiy: HandleSendQueue sends set02 with timeout 2 to http://192.168.178.93:8081/zeroconf/switch,
data: { "deviceid": "", "data": { "switch": "on" } },
header: Accept: */*
Content-Type: application/x-www-form-urlencoded
charset=utf-8
2020.09.10 11:28:16 5: HttpUtils url=http://192.168.178.93:8081/zeroconf/switch
2020.09.10 11:28:16 4: IP: 192.168.178.93 -> 192.168.178.93
2020.09.10 11:28:16 5: HttpUtils request header:
POST /zeroconf/switch HTTP/1.0
Host: 192.168.178.93:8081
User-Agent: fhem
Accept-Encoding: gzip,deflate
Accept: */*
Content-Type: application/x-www-form-urlencoded
charset=utf-8
Content-Length: 46

2020.09.10 11:28:18 3: sonoffdiy: Read callback: Error: read from http://192.168.178.93:8081 timed out
2020.09.10 11:28:18 4: sonoffdiy: Read callback: request type was set02 retry 0, no headers, no body
2020.09.10 11:28:18 5: sonoffdiy: Read callback: body empty
2020.09.10 11:28:18 4: sonoffdiy: Read found no charset header (bodyDecode was set to auto)
2020.09.10 11:28:18 5: sonoffdiy: GetCookies is looking for Cookies
2020.09.10 11:28:18 5: sonoffdiy: ExtractSid called, context set, num 02
2020.09.10 11:28:18 4: sonoffdiy: no header to look for redirects
2020.09.10 11:28:18 5: sonoffdiy: CheckAuth decided no authentication required

ch.eick

#860
Beim curl Aufruf steht im Header

Content-Type: application/x-www-form-urlencoded; charset=utf-8

Es ist wirklich merkwürdig, aber ich kämpfe auch an einer API, die sehr zickig ist ;-)

EDIT:
Das habe ich auch gerade noch gesehen "HTTP/1.0" bei Dir und "HTTP/1.1  bei curl.
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

wires.io

Wenn ich das richtig interpretiere, steht das in der Antwort vom Sonoff und nicht im Request von curl.

ch.eick

Zitat von: wires.io am 10 September 2020, 11:39:31
Wenn ich das richtig interpretiere, steht das in der Antwort vom Sonoff und nicht im Request von curl.
Okay,

dann wäre noch die HTTP Version
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

wires.io

Zitat von: ch.eick am 10 September 2020, 11:54:04
dann wäre noch die HTTP Version

Yeaaaaaaaaah, danke!!! Das war's! Die ganzen Header brauche ich dann nicht.

ch.eick

Zitat von: wires.io am 10 September 2020, 11:57:29
Yeaaaaaaaaah, danke!!! Das war's! Die ganzen Header brauche ich dann nicht.
Das freut mich, dann ist jetzt wieder Platz für meine Fragen ;-)
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

Esjay

Zitat von: wires.io am 10 September 2020, 11:57:29
Yeaaaaaaaaah, danke!!! Das war's! Die ganzen Header brauche ich dann nicht.

Kannst du bitte nochmal deine komplette Lösung posten?
Bin der Typ von dem amenomade hier spricht:
Zitat von: amenomade am 10 September 2020, 10:51:31
@wires.io: Läuft Fhem in einem Container? In einem anderen Thread scheint jemand das gleiche Problem zu haben. Bei ihm läuft Fhem auf einem LXC unter Proxmox.

https://forum.fhem.de/index.php/topic,114146.0.html

ch.eick

Zitat von: Esjay am 10 September 2020, 12:15:45
Kannst du bitte nochmal deine komplette Lösung posten?
Es war letztendlich die HTTP Version, den Rest des devices habe ich nicht :-)

attr <device> httpVersion 1.1
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

Esjay

#867
Zumindest bekomme ich jetzt schonmal ne Antwort vom Server:

2020.09.10 12:38:48 1:  Logfile gelöscht
2020.09.10 12:38:56 5:  MyDevice: set called with LEDDevice true
2020.09.10 12:38:56 5:  MyDevice: set found option LEDDevice in attribute set01Name
2020.09.10 12:38:56 4:  MyDevice: set will now set LEDDevice -> true
2020.09.10 12:38:56 5:  MyDevice: AddToQueue adds type set01 to URL http://192.168.178.76:8090/json-rpc, data {"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":$val}}}, header Content-Type: application/json, retry 0, initial queue len: 0
2020.09.10 12:38:56 5:  MyDevice: HandleSendQueue called, qlen = 1
2020.09.10 12:38:56 4:  MyDevice: HandleSendQueue sends set01 with timeout 2 to http://192.168.178.76:8090/json-rpc,
data: {"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":true}}},
header: Content-Type: application/json
2020.09.10 12:38:56 5:  HttpUtils url=http://192.168.178.76:8090/json-rpc
2020.09.10 12:38:56 4:  IP: 192.168.178.76 -> 192.168.178.76
2020.09.10 12:38:57 5:  HttpUtils request header:
POST /json-rpc HTTP/1.1
Host: 192.168.178.76:8090
User-Agent: fhem
Accept-Encoding: gzip,deflate
Connection: Close
Content-Type: application/json
Content-Length: 85

2020.09.10 12:38:57 4:  http://192.168.178.76:8090/json-rpc: HTTP response code 200
2020.09.10 12:38:57 5:  HttpUtils http://192.168.178.76:8090/json-rpc: Got data, length: 138
2020.09.10 12:38:57 5:  HttpUtils response header:
HTTP/1.1 200 OK.
Content-Type: application/json
Server: Hyperion Webserver
Date: Thu, 10 Sep 2020 10:38:57 UTC
Content-Length: 138
2020.09.10 12:38:57 4:  MyDevice: Read callback: request type was set01 retry 0,
header: HTTP/1.1 200 OK.
Content-Type: application/json
Server: Hyperion Webserver
Date: Thu, 10 Sep 2020 10:38:57 UTC
Content-Length: 138, body length 138
2020.09.10 12:38:57 5:  MyDevice: Read callback: body
{
    "command": "",
    "error": "Errors during message parsing, please consult the Hyperion Log.",
    "success": false,
    "tan": 0
}

2020.09.10 12:38:57 4:  MyDevice: Read found no charset header (bodyDecode was set to auto)
2020.09.10 12:38:57 5:  MyDevice: GetCookies is looking for Cookies
2020.09.10 12:38:57 5:  MyDevice: ExtractSid called, context set, num 01
2020.09.10 12:38:57 4:  MyDevice: checking for redirects, code=200, ignore=0
2020.09.10 12:38:57 4:  MyDevice: no redirects to handle
2020.09.10 12:38:57 5:  MyDevice: CheckAuth decided no authentication required


Jetzt muss ich nur noch herausfinden, was genau da los ist.

Edit: Hab es

2020.09.10 12:57:57 1:  Logfile gelöscht
2020.09.10 12:58:07 5:  MyDevice: set called with LEDDevice false
2020.09.10 12:58:07 5:  MyDevice: set found option LEDDevice in attribute set01Name
2020.09.10 12:58:07 4:  MyDevice: set will now set LEDDevice -> false
2020.09.10 12:58:07 5:  MyDevice: AddToQueue adds type set01 to URL http://192.168.178.76:8090/json-rpc, data {"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":$val}}, header Content-Type: application/json, retry 0, initial queue len: 0
2020.09.10 12:58:07 5:  MyDevice: HandleSendQueue called, qlen = 1
2020.09.10 12:58:07 4:  MyDevice: HandleSendQueue sends set01 with timeout 2 to http://192.168.178.76:8090/json-rpc,
data: {"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":false}},
header: Content-Type: application/json
2020.09.10 12:58:07 5:  HttpUtils url=http://192.168.178.76:8090/json-rpc
2020.09.10 12:58:07 4:  IP: 192.168.178.76 -> 192.168.178.76
2020.09.10 12:58:08 5:  HttpUtils request header:
POST /json-rpc HTTP/1.1
Host: 192.168.178.76:8090
User-Agent: fhem
Accept-Encoding: gzip,deflate
Connection: Close
Content-Type: application/json
Content-Length: 85

2020.09.10 12:58:08 4:  http://192.168.178.76:8090/json-rpc: HTTP response code 200
2020.09.10 12:58:08 5:  HttpUtils http://192.168.178.76:8090/json-rpc: Got data, length: 71
2020.09.10 12:58:08 5:  HttpUtils response header:
HTTP/1.1 200 OK.
Content-Type: application/json
Server: Hyperion Webserver
Date: Thu, 10 Sep 2020 10:58:08 UTC
Content-Length: 71
2020.09.10 12:58:08 4:  MyDevice: Read callback: request type was set01 retry 0,
header: HTTP/1.1 200 OK.
Content-Type: application/json
Server: Hyperion Webserver
Date: Thu, 10 Sep 2020 10:58:08 UTC
Content-Length: 71, body length 71
2020.09.10 12:58:08 5:  MyDevice: Read callback: body
{
    "command": "componentstate",
    "success": true,
    "tan": 0
}

2020.09.10 12:58:08 4:  MyDevice: Read found no charset header (bodyDecode was set to auto)
2020.09.10 12:58:08 5:  MyDevice: GetCookies is looking for Cookies
2020.09.10 12:58:08 5:  MyDevice: ExtractSid called, context set, num 01
2020.09.10 12:58:08 4:  MyDevice: checking for redirects, code=200, ignore=0
2020.09.10 12:58:08 4:  MyDevice: no redirects to handle
2020.09.10 12:58:08 5:  MyDevice: CheckAuth decided no authentication required


Hatte noch eine Klammer zu viel.

Danke für den Hinweis zur Http Version.

wires.io

#868
Zitat von: Esjay am 10 September 2020, 12:15:45
Kannst du bitte nochmal deine komplette Lösung posten?

S.u. - es fehlt aber noch, dass der "state" aktualisiert wird, wenn ich schalte. Benötige ich dazu "notify" oder geht das auch einfacher?

defmod sonoffdiy HTTPMOD none 0
attr sonoffdiy userattr get01Data get01Method:GET,POST,PUT get01Name get01NoArg:0,1 get01URL reading01Name reading01Regex set01Data set01Name set01NoArg:0,1 set01URL set02Data set02Name set02NoArg:0,1 set02URL
attr sonoffdiy get01Data { "deviceid": "", "data": { } }
attr sonoffdiy get01Method POST
attr sonoffdiy get01Name state
attr sonoffdiy get01NoArg 1
attr sonoffdiy get01URL http://192.168.178.93:8081/zeroconf/info
attr sonoffdiy httpVersion 1.1
attr sonoffdiy reading01Name state
attr sonoffdiy reading01Regex "switch":"([\w\.]+)
attr sonoffdiy set01Data { "deviceid": "", "data": { "switch": "off" } }
attr sonoffdiy set01Name off
attr sonoffdiy set01NoArg 1
attr sonoffdiy set01URL http://192.168.178.93:8081/zeroconf/switch
attr sonoffdiy set02Data { "deviceid": "", "data": { "switch": "on" } }
attr sonoffdiy set02Name on
attr sonoffdiy set02NoArg 1
attr sonoffdiy set02URL http://192.168.178.93:8081/zeroconf/switch
attr sonoffdiy timeout 2

ch.eick

So, ich habe hier noch mal aktualisiert https://forum.fhem.de/index.php/topic,45176.msg1084262.html#msg1084262.
Da geht es um die Komprimierten Daten in einem reading und wie ich die entpackt bekomme???
RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick