Neue Version von HTTPMOD mit neuen Features zum Testen

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

Vorheriges Thema - Nächstes Thema

StefanStrobel

Hallo Sailor,

das würde ich mit einer Perl-Expression machen.
reading01Expr ...
Da dann eine passende Regex Ersetzung.

Gruss
   Stefan

gestein

Hallo Stefan,

Ja, das würde das erklären.

Aber ich habe im DEF des Devices folgendes:
defmod Twinkly_icicle_144 HTTPMOD http://192.168.0.144/xled/v1/led/mode 120

Und damit sollte es doch gehen.
Gerade eben probiert.
Das Device vom Netz genommen.
2min später wird LAST_ERROR gesetzt, aber nicht das Reading mode.

Oder habe ich da was übersehen?
Danke im Voraus
Lg, Gerhard

Hier noch ein list des Devices:
Internals:
   BUSY       0
   DEF        http://192.168.0.144/xled/v1/led/mode 120
   FUUID      61b3c75a-f33f-7e14-24ce-2fd106acddd5228a
   FVERSION   98_HTTPMOD.pm:0.247080/2021-07-06
   Interval   120
   LastAuthTry 2021-12-14 20:32:33
   MainURL    http://192.168.0.144/xled/v1/led/mode
   ModuleVersion 4.1.10 - 6.7.2021
   NAME       Twinkly_icicle_144
   NOTIFYDEV  global
   NR         4423
   NTFY_ORDER 50-Twinkly_icicle_144
   STATE      effect
   TYPE       HTTPMOD
   httpbody   
   sid        Pb+Pjj+8Lao=
   value     
   CompiledRegexes:
   HttpUtils:
     NAME       
     addr       http://192.168.0.144:80
     auth       0
     data       
     displayurl http://192.168.0.144/xled/v1/led/mode
     header     X-Auth-Token: Pb+Pjj+8Lao=
     host       192.168.0.144
     httpversion 1.0
     ignoreredirects 1
     loglevel   4
     path       /xled/v1/led/mode
     protocol   http
     redirects  0
     timeout    2
     url        http://192.168.0.144/xled/v1/led/mode
     sslargs:
   QUEUE:
   READINGS:
     2021-12-14 21:18:36   LAST_ERROR      connect to http://192.168.0.144:80 timed out
     2021-12-14 20:28:25   bytes_per_led   4
     2021-12-14 21:16:36   code            1000
     2021-12-14 05:58:39   color_config_blue 0
     2021-12-14 05:58:39   color_config_green 0
     2021-12-14 05:58:39   color_config_hue 0
     2021-12-14 05:58:39   color_config_red 0
     2021-12-14 05:58:39   color_config_saturation 0
     2021-12-14 05:58:39   color_config_value 0
     2021-12-14 05:58:39   color_config_white 255
     2021-12-14 20:28:25   copyright       LEDWORKS 2021
     2021-12-14 20:28:25   device_name     Twinkly_41FB2D
     2021-12-10 23:02:41   effects_number  5
     2021-12-14 20:28:25   flash_size      64
     2021-12-14 20:28:25   frame_rate      24
     2021-12-14 20:28:25   fw_family       G
     2021-12-14 20:28:25   hardware_version 302
     2021-12-14 20:28:25   hw_id           41fb2c
     2021-12-14 20:28:25   led_profile     RGBW
     2021-12-14 20:28:25   led_type        12
     2021-12-14 20:28:25   mac             98:cd:ac:41:fb:2d
     2021-12-14 20:28:25   max_supported_led 510
     2021-12-14 20:28:25   measured_frame_rate 28.57
     2021-12-14 21:16:36   mode            effect
     2021-12-14 20:28:25   movie_capacity  5285
     2021-12-14 20:28:25   number_of_led   190
     2021-12-10 23:23:07   preset_id       1
     2021-12-14 20:28:25   product_code    TWI190SPP
     2021-12-14 20:28:25   product_name    Twinkly
     2021-12-14 21:16:36   shop_mode       0
     2021-12-10 23:23:07   unique_id       00000000-0000-0000-0000-000000000002
     2021-12-10 23:02:41   unique_ids_0    00000000-0000-0000-0000-000000000001
     2021-12-10 23:02:41   unique_ids_1    00000000-0000-0000-0000-000000000002
     2021-12-10 23:02:41   unique_ids_2    00000000-0000-0000-0000-000000000003
     2021-12-10 23:02:41   unique_ids_3    00000000-0000-0000-0000-000000000004
     2021-12-10 23:02:41   unique_ids_4    00000000-0000-0000-0000-000000000005
     2021-12-14 20:28:25   uptime          17475487
     2021-12-14 20:28:25   uuid            BD8A63F3-2E83-46F0-AA49-7742948025E6
     2021-12-14 20:28:25   wire_type       4
   REQUEST:
     context    reading
     data       
     header     X-Auth-Token: $sid
     ignoreredirects 0
     num        unknown
     retryCount 0
     type       update
     url        http://192.168.0.144/xled/v1/led/mode
   defptr:
     readingBase:
       bytes_per_led get
       code       reading
       color_config_blue reading
       color_config_green reading
       color_config_hue reading
       color_config_red reading
       color_config_saturation reading
       color_config_value reading
       color_config_white reading
       copyright  get
       device_name get
       flash_size get
       frame_rate get
       fw_family  get
       hardware_version get
       hw_id      get
       led_profile get
       led_type   get
       mac        get
       max_supported_led get
       measured_frame_rate get
       mode       reading
       movie_capacity get
       number_of_led get
       product_code get
       product_name get
       shop_mode  reading
       uptime     get
       uuid       get
       wire_type  get
     readingNum:
       bytes_per_led 01
       code       unknown
       color_config_blue unknown
       color_config_green unknown
       color_config_hue unknown
       color_config_red unknown
       color_config_saturation unknown
       color_config_value unknown
       color_config_white unknown
       copyright  01
       device_name 01
       flash_size 01
       frame_rate 01
       fw_family  01
       hardware_version 01
       hw_id      01
       led_profile 01
       led_type   01
       mac        01
       max_supported_led 01
       measured_frame_rate 01
       mode       unknown
       movie_capacity 01
       number_of_led 01
       product_code 01
       product_name 01
       shop_mode  unknown
       uptime     01
       uuid       01
       wire_type  01
     readingOutdated:
     readingSubNum:
     requestReadings:
       get01:
         bytes_per_led get 01
         code       get 01
         copyright  get 01
         device_name get 01
         flash_size get 01
         frame_rate get 01
         fw_family  get 01
         hardware_version get 01
         hw_id      get 01
         led_profile get 01
         led_type   get 01
         mac        get 01
         max_supported_led get 01
         measured_frame_rate get 01
         movie_capacity get 01
         number_of_led get 01
         product_code get 01
         product_name get 01
         uptime     get 01
         uuid       get 01
         wire_type  get 01
       set01:
         code       set 01
         mode       set 01
       update:
         code       reading unknown
         color_config_blue reading unknown
         color_config_green reading unknown
         color_config_hue reading unknown
         color_config_red reading unknown
         color_config_saturation reading unknown
         color_config_value reading unknown
         color_config_white reading unknown
         mode       reading unknown
         shop_mode  reading unknown
   helper:
     bm:
       CODE(0x398a9b0):
         cnt        1
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        13.12. 13:32:31
         max        0.00277400016784668
         tot        0.00277400016784668
         mAr:
           HASH(0xa59ea78)
           Twinkly_icicle_144 HTTPMOD http://192.168.0.144/xled/v1/led/mode 120
       CODE(0x398ab78):
         cnt        26
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        13.12. 23:38:00
         max        3.29017639160156e-05
         tot        0.00024724006652832
         mAr:
           HASH(0xa59ea78)
           HASH(0x1d75a68)
       CODE(0x3a4bc28):
         cnt        17
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        13.12. 13:32:50
         max        0.0157580375671387
         tot        0.0852327346801758
         mAr:
           set
           Twinkly_icicle_144
           reading01MaxAge
           120
       CODE(0x3b10a50):
         cnt        385
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        13.12. 21:47:06
         max        0.00991296768188477
         tot        0.279318809509277
         mAr:
           HASH(0xa59ea78)
           Twinkly_icicle_144
           mode
           effect
       CODE(0x3b25858):
         cnt        39
         dmx        -1000
         dtot       0
         dtotcnt    0
         mTS        13.12. 13:25:38
         max        0.00928401947021484
         tot        0.0214970111846924
         mAr:
           HASH(0xa59ea78)
           Twinkly_icicle_144
           Gestalt
   lastpoll:
     Gestalt    1639510104.23615
Attributes:
   comment    https://forum.fhem.de/index.php/topic,93197.msg1004834.html#msg1004834
   devStateIcon off:general_aus movie|demo:general_an rt:rc_SETUP
   enableControlSet 1
   event-on-change-reading .*
   eventMap   /mode off:aus/mode color:an/
   extractAllJSON 1
   get01Name  Gestalt
   get01Poll  1
   get01PollDelay 3600
   get01URL   http://192.168.0.144/xled/v1/gestalt
   get02Header1 Content-Type: application/json
   get02Header2 X-Auth-Token: $sid
   get02Name  MQTT
   get02URL   http://192.168.0.144/xled/v1/mqtt/config
   get03Header1 Content-Type: application/json
   get03Header2 X-Auth-Token: $sid
   get03Name  LED-Effects
   get03URL   http://192.168.0.144/xled/v1/led/effects
   get04Header1 Content-Type: application/json
   get04Header2 X-Auth-Token: $sid
   get04Name  LED-Effect_current
   get04URL   http://192.168.0.144/xled/v1/led/effects/current
   group      Twinkly
   icon       christmas_lights
   reAuthRegex Invalid.Token
   reading01MaxAge 120
   reading01MaxAgeReplacement offline
   reading01MaxAgeReplacementMode text
   reading01Name mode
   replacement01Mode expression
   replacement01Regex %%mode%%
   requestHeader01 X-Auth-Token: $sid
   room       Weihnachten,0_Testing
   set01Data  {%%mode%%}
   set01Hint  off,color,demo,effect,movie,playlist,rt
   set01Name  mode
   set01Replacement01Value {my $value = InternalVal($name, "value", "");
my $ret = "\"mode\":\"$value\""; ##{"mode":"$val"%%effect%%}

if ($value eq "effect") {
$ret .= ",\"effect_id\":".ReadingsVal($name,"preset_id","0");
}
return $ret;
}
   set01TextArg 1
   set01URL   http://192.168.0.144/xled/v1/led/mode
   set02Data  {"broker_host":"node02.myqtthub.com","broker_port":8883,"client_id":"E8DB840EDCA1","user":"steiner","keep_alive_interval":60}
   set02Name  set_MQTT
   set02TextArg 1
   set02URL   http://192.168.0.144/xled/v1/mqtt/config
   set03Data  {"mode":"node02.myqtthub.com"}
   set03Name  set_Mode
   set03TextArg 1
   set03URL   http://192.168.0.144/xled/v1/led/mode
   setHeader1 Content-Type: application/json
   setHeader2 X-Auth-Token: $sid
   setParseResponse 1
   showBody   1
   showError  1
   sid01Data  {"challenge": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8="}
   sid01IdJSON authentication_token
   sid01URL   http://192.168.0.144/xled/v1/login
   sid02Header X-Auth-Token: $sid
   sid02URL   http://192.168.0.144/xled/v1/verify
   sidHeader1 Content-Type: application/json
   stateFormat mode
   userattr   get01PollDelay:0,1 sid02Data sid2Header sidHeader2
   webCmd     an:aus


Sailor

Hallo Stefan

Zitat von: StefanStrobel am 14 Dezember 2021, 17:52:15
das würde ich mit einer Perl-Expression machen.
reading01Expr ...
Da dann eine passende Regex Ersetzung.

Also attr OS_Tide_Stadesand reading01Expr s/ /<BR>/ funktioniert leider nicht.
(""Space" soll durch "<BR>" ersetzt werden.

Das Reading wird leer.

Gruß
    Sailor
******************************
Man wird immer besser...

StefanStrobel

Hallo Sailor,

das Ergebnis Deiner Expression wird als Wert verwendet.
So wie Du es angegeben hast, kann es also nicht klappen. s/ /<BR>/ alleine gibt keinen sinnvoll Wert zurück.
Probier doch mal so was wie

$val =~ s/ /<br>/g; $val

Gruss
   Stefan

Sailor

Hallo Stefan

Zitat von: StefanStrobel am 21 Dezember 2021, 21:06:37
Probier doch mal so was wie

Das hat hingehauen!


$val =~ s/ +/<br>/g;
$val =~ s/<br>CET/ CET/g;
$val



HW: 27.12.2021
21:24 CET
3.35


Danke

   Gruß
        Sailor
******************************
Man wird immer besser...

ch.eick

Hallo zusammen,

Beim ModBus habe ich bereits den userreadings modifier monotonic verwendet.
Hier im HTTPMOD bekomme ich dazu jedoch eine Fehlermeldung.

Für den ersten Test wollte ich es dann so einbauen, jedoch scheint die Funktion monotonic im HTTPMOD Modul nicht integriert zu sein.
Kann ich das noch anders aufrufen?

SW_Statistic_Yield_Total_test:SW_Statistic_Yield_Total.* monotonic {round(ReadingsVal("$NAME","Statistic_Yield_Total",0)+ReadingsVal("WR_2_API","Statistic_Yield_Total",0),0)},

Error evaluating WR_1_API userReading SW_Statistic_Yield_Total_test: Undefined subroutine &main::monotonic called at (eval 2244259) line 1.


VG
   Christian
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

StefanStrobel

Hallo Christian,

monotonic ist weder im Modbus-Modul noch in HTTPMOD integriert. Die Userreadings sollten unabhängig vom Modul sein.
Eigentlich sollte das Problem anderswo zu suchen sein.
Vielleicht kann jemand anders da helfen?

Gruss
   Stefan

ch.eick

#1132
Zitat von: StefanStrobel am 25 Januar 2022, 17:50:07
Hallo Christian,

monotonic ist weder im Modbus-Modul noch in HTTPMOD integriert. Die Userreadings sollten unabhängig vom Modul sein.
Eigentlich sollte das Problem anderswo zu suchen sein.
Vielleicht kann jemand anders da helfen?

Gruss
   Stefan
Oh, dann muss ich woanders suchen.

EDIT: Das hat sich erledigt, ich hatte mich etwas beim Testen verrant. Es läuft doch.

Danke
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

FhemPiUser

Hallo Zusammen,
ich habe eine Frage zu HTTPMOD: Kann man damit auch Formularfelder ausfüllen bzw. Cookies setzen?
Beispiel: Ich möchte gerne den aktuellen Stromtarif von Vattenfall als Reading haben. Die Webseite https://www.vattenfall.de/stromtarife benötigt aber einmalig die Eingabe von PLZ und Verbrauch, was dann als Cookie gespeichert wird, bevor man den Tarif sieht. Gibt es da eine Möglichkeit mit HTTPMOD?
Danke

t1me2die

#1134
Moin zusammen,

in der Vergangenheit habe ich gerne aus dem Internals meiner HTTPMOD Devices den "httpheader" verwendet um auf einem Blick zu sehen, wie der HTTP Code war und ob es ggf. Fehler gab.
Gibt es dieses Internal nicht mehr?

Gruß
Mathze

@Edit: Antwort gefunden unter: https://forum.fhem.de/index.php/topic,45176.msg1095872.html#msg1095872
Hab nun meinen Code diesbezüglich umgebaut.

l-j-silver

Hallo Zusammen,

ich versuche seit einiger Zeit die Daten meiner Heizung (JSON) mit diesen Modul HTTPMOD auszulesen.

Dabei sehe ich im Log immer folgende Meldung (Ausgabe ist gekürzt):

2022.03.06 21:50:18 4: Pelletronic: Read callback: request type was update retry 0,
header: HTTP/1.1 200 OK
Connection: close
Date: Sun, 6 Mar 2022 20:50:21 GMT
Content-length: 2563, body length 2563
2022.03.06 21:50:18 5: Pelletronic: Read callback: body

"hk1":{
  "L_roomtemp_act":0,
  "name":"Heizk�rper",
  "oekomode":0,
  "autocomfort":-1,
  "autocomfort_sunset":0,
  "autocomfort_sunrise":0
},
"ww1":{
  "L_statetext":"Zeit au�erhalb Zeitprogramm|Anforderung Aus",
},
   "error":{
   }
}

2022.03.06 21:50:18 4: Pelletronic: BodyDecode is not decoding the response body (charset not found, bodyDecode set to none)
2022.03.06 21:50:18 4: Pelletronic: error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 433 (before "\x{fffd}r", \n  "oek...") at lib/FHEM/HTTPMOD/Utils.pm line 678.



Hier noch der Code wie ich die Heizung eingebunden habe:

define Pelletronic HTTPMOD http://192.168.0.15:4321/XXXX/all
setuuid Pelletronic 622517fa-f33f-5730-d6ed-c470d534fd6ade04
attr Pelletronic bodyDecode none
attr Pelletronic reading01JSON pu1_L_tpo_act
attr Pelletronic reading01Name PufferOben
attr Pelletronic reading01OExpr $val/10
attr Pelletronic reading02JSON pu1_L_tpm_act
attr Pelletronic reading02Name PufferMitte
attr Pelletronic reading02OExpr $val/10
attr Pelletronic reading03JSON pe1_L_temp_act
attr Pelletronic reading03Name Kesseltemperatur
attr Pelletronic reading03OExpr $val/10
attr Pelletronic room Heizraum
attr Pelletronic verbose 5


Bei einigen scheint es wohl zu klappen, aber ich habe verm. Probleme mit den Umlauten.

Kann mir jemand ein Tipp geben, wie ich das Problem lösen kann?

Vielen Dank.

Grüße Toni

Der_Matze

Hallo Toni,
ich habe den Code von HTTPMOD/Utils.pm etwas erweitert, da meine Enthärtungsanlage auch mit Umlauten antwortet.
Zeile 33 um 'encode_utf8' erweitert

use Encode          qw(decode encode encode_utf8);

Zeile 678

my $decoded = eval { decode_json(encode_utf8($buffer)) };

Dann klappts auch mit den Umlauten.

Gruß
Matze

StefanStrobel

Hallo Matze und Toni,

dafür gibt es in HTTPMOD bereits diverse Attribute:
Zitat
(get|set|reading)[0-9]*Decode
            defines an encoding to be used in a call to the perl function decode to convert the raw data string read from the device to a reading.
            This can be used if the device delivers strings in an encoding like cp850 instead of utf8.
            If your reading values contain Umlauts and they are shown as strange looking icons then you probably need to use this feature.
            Using this attribute for a set command only makes sense if you want to parse the HTTP response to the HTTP request that the set command sent by defining the attribute setXXParseResponse.
(get|set|reading)[0-9]*Encode
            defines an encoding to be used in a call to the perl function encode to convert the data string read from the device to a reading.
            This can be used if the device delivers strings in an encoding like cp850 and after decoding it you want to reencode it to e.g. utf8.
            When the attribute bodyDecode is not set to 'none' then this encoding attribute defaults to utf8.
            If your reading values contain Umlauts and they are shown as strange looking icons then you probably need to modidify this attribute.
            Using this attribute for a set command only makes sense if you want to parse the HTTP response to the HTTP request that the set command sent by defining the attribute setXXParseResponse.
bodyDecode
            defines an encoding to be used in a call to the perl function decode to convert the raw http response body data string
            read from the device before further processing / matching
            If you have trouble matching special characters or if your reading values contain Umlauts
            and they are shown as strange looking icons then you might need to use this feature.
            If this attribute is set to 'auto' then HTTPMOD automatically looks for a charset header and decodes the body acordingly.
            If no charset header is found, the body will remain undecoded.

Gruss
   Stefan

StefanStrobel

Hallo FhemPiUser,

wenn Du Formulare ausfüllst, dann wird vom Browser ein entsprechender HTTP-Request an den Server geschickt Den musst Du Dir nur ansehen und in HTTPMOD nachbauen.
Wenn es mehrere variable Felder sind dann helfen die replacements von HTTPMOD.

Gruss
   Stefan

l-j-silver

Hallo Stefan,

das habe ich auch schon gelesen. Leider bin ich daraus nicht schlau geworden.
Daher habe ich auch den Beitrag verfasst.
Ich hatte gehofft, dass mir jemand sagen kann, was ich am Besten ändern sollte.

Vielen Dank.

Grüße Toni