Kann man in Httpmod den response vom device manipulieren?

Begonnen von bicmac, 17 Juni 2020, 09:23:54

Vorheriges Thema - Nächstes Thema

bicmac

Hi,

ich habe ein Device welches ich mit HTTPMOD abfrage.
Die Antwort vom Device ist prinzipiell ein JSON.
Jedoch enthält sie auch 2 Zeilen (eine am Anfang und eine am Ende) welches HTTPMOD dazu bringen das ganze nicht als JSON zu erkennen.

Kann ich in der Antwort vom Device irgendwie die erste und letzte Zeile automatisch löschen lassen?



/*-secure-
{ updates : {
mode_a1 : "Disarm",
mode_a2 : "Disarm",
battery : "Normal",
tamper : "Close",
interference : "Normal",
ac_activation : "Normal",
rssi : "14",
sig_gsm : "N/A"
},
forms : {
pcondform1 : {
mode : "4",
f_arm : "0"
},
pcondform2 : {
mode : "4",
f_arm : "0"
}
}
}
*/



MadMax-FHEM

Es gibt einige Attribute mit Ersetzen und auch das hier:

Zitat
preProcessRegex
can be used to fix a broken HTTP response before parsing. The regex should be a replacement regex like s/match/replacement/g and will be applied to the buffer.

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

bicmac

Zitat von: MadMax-FHEM am 17 Juni 2020, 09:29:53
Es gibt einige Attribute mit Ersetzen und auch das hier:

Gruß, Joachim

Danke.
Jetzt habe ich die erste und letzte Zeile rausgenommen. Jedoch sagt er noch immer das es kein gültiges JSON ist.

Laut meinem JSON Validator müssen wohl die keys auch noch in Hochkomma. Wo bekomem ich das denn zusätzlich noch rein?

Hier mal der Body wie er jetzt ist und der Regex. Ich bin leide rnicht der Regexpexperte.


attr Alarmanlage preProcessRegex s!^/\*-secure-\n(.*)\*/!$1!s


{ updates : {
mode_a1 : "Disarm",
mode_a2 : "Disarm",
battery : "Normal",
tamper : "Close",
interference : "Normal",
ac_activation : "Normal",
rssi : "15",
sig_gsm : "N/A"
},
forms : {
pcondform1 : {
mode : "4",
f_arm : "0"
},
pcondform2 : {
mode : "4",
f_arm : "0"
}
}
}

MadMax-FHEM

Ich bin jetzt auch kein RegEx-Experte :-\

Es gibt weitere "Replace"-Attribute, siehe commandref bzw. "Device-specific Help"...

Evtl. postest du mal ein list deines HTTPMOD

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

bicmac



Internals:
   BUSY       0
   CFGFN     
   DEF        http://192.168.2.15/action/panelCondGet 3600
   FUUID      5ee9c122-f33f-236c-7b9b-9b275a84d1a14647
   Interval   3600
   LASTSEND   1592390651.05744
   MainURL    http://192.168.2.15/action/panelCondGet
   ModuleVersion 3.5.22 - 7.2.2020
   NAME       Alarmanlage
   NOTIFYDEV  global
   NR         27689
   NTFY_ORDER 50-Alarmanlage
   STATE      ???
   TRIGGERTIME 1592394237.64035
   TRIGGERTIME_FMT 2020-06-17 13:43:57
   TYPE       HTTPMOD
   addr       http://192.168.2.15:80
   auth       1
   code       200
   compress   1
   conn       
   data       
   displayurl http://192.168.2.15/action/panelCondGet
   header     
   host       192.168.2.15
   httpbody   { updates : {
mode_a1 : "Disarm",
mode_a2 : "Disarm",
battery : "Normal",
tamper : "Close",
interference : "Normal",
ac_activation : "Normal",
rssi : "15",
sig_gsm : "N/A"
},
forms : {
pcondform1 : {
mode : "4",
f_arm : "0"
},
pcondform2 : {
mode : "4",
f_arm : "0"
}
}
}

   httpheader HTTP/1.0 200 OK
Server: httpd
Pragma: no-cache
Cache-control: no-cache
Expires: 0
Content-Type: application/json; charset=ISO-8859-1
   httpversion 1.0
   hu_blocking 0
   hu_filecount 21
   hu_port    80
   hu_portSfx
   ignoreredirects 1
   loglevel   4
   path       /action/panelCondGet
   protocol   http
   redirects  0
   timeout    2
   url        http://192.168.2.15/action/panelCondGet
   value      0
   CompiledRegexes:
   OLDREADINGS:
   QUEUE:
   REQUEST:
     data       
     header     
     ignoreredirects 0
     retryCount 0
     type       update
     url        http://192.168.2.15/action/panelCondGet
     value      0
   defptr:
     readingBase:
       Zone1      reading
       reading01  reading
     readingNum:
       Zone1      01
       reading01  01
     readingOutdated:
     requestReadings:
       update:
         Zone1      reading 01
         reading01  reading 01
   sslargs:
Attributes:
   DbLogExclude .*
   enableControlSet 1
   preProcessRegex s!^/\*-secure-\n(.*)\*/!$1!s
   showBody   1
   showError  1
   verbose    0


MadMax-FHEM

Ich sehe nicht, dass du schon versuchst was zu "extrahieren"!?

Was passiert bei: attr Alarmanlage extractAllJason 1

Gibt es da Fehler?
Gut, könnte nat. sein weil es scheint wohl tatsächlich kein gültiges Json zu sein... :-\

Ansonsten wie geschrieben gibt es weitere (Pro-Extrakt) "Ersetz-Attribute"...

Evtl. hilft das: https://regex101.com/

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)