Hauptmenü

httpmod regx

Begonnen von UvG, 16 Dezember 2015, 13:01:30

Vorheriges Thema - Nächstes Thema

UvG

Ich versuche als Anfänger hier mal eine 2 Anfrage zu stellen.
Ich habe einen Zugriff auf eine Website (mobile Alerts) und bekomme folgende Antwort:

HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Length: 12896 Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 16 Dec 2015 11:22:56 GMT Connection: close { "success": true, "primarydomain": "www.data199.com", "phoneid": "586364039493", "result": { "devices": [ { "deviceid": "0B080D8F558D", "devicetypeid": 11, "name": "windsensor", "lang": "de", "lastseen": 1450080950, "lowbattery": false, "alertwasactive": false, "settings": { "wsalarmactive": false, "ws": 1.0, "wgalarmactive": false, "wg": 1.0, "wats": 360, "wdnalarmactive": true, "wdnnealarmactive": true, "wdnealarmactive": true, "wdenealarmactive": true, "wdealarmactive": true, "wdesealarmactive": true, "wdsealarmactive": true, "wdssealarmactive": true, "wdsalarmactive": true, "wdsswalarmactive": true, "wdswalarmactive": true, "wdwswalarmactive": true, "wdwalarmactive": true, "wdwnwalarmactive": true, "wdnwalarmactive": true, "wdnnwalarmactive": true }, "measurements": [ { "idx": 9812, "ts": 1450080950, "tx": 512, "c": 1450081022, "pr": false, "ws": 0.5, "wg": 3.4000000000000004, "wd": 7 }, { "idx": 9810, "ts": 1450080528, "tx": 511, "c": 1450080826, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9809, "ts": 1450080106, "tx": 510, "c": 1450080404, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9806, "ts": 1450079684, "tx": 509, "c": 1450079986, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9804, "ts": 1450079261, "tx": 508, "c": 1450079561, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9802, "ts": 1450078838, "tx": 507, "c": 1450079143, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9800, "ts": 1450078417, "tx": 506, "c": 1450078720, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9798, "ts": 1450077994, "tx": 505, "c": 1450078302, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9796, "ts": 1450077571, "tx": 504, "c": 1450077880, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9794, "ts": 1450077150, "tx": 503, "c": 1450077458, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9792, "ts": 1450076727, "tx": 502, "c": 1450077036, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9790, "ts": 1450076305, "tx": 501, "c": 1450076619, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9788, "ts": 1450075882, "tx": 500, "c": 1450076197, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9786, "ts": 1450075461, "tx": 499, "c": 1450075774, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9784, "ts": 1450075038, "tx": 498, "c": 1450075356, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9783, "ts": 1450074616, "tx": 497, "c": 1450074934, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9781, "ts": 1450074193, "tx": 496, "c": 1450074512, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9779, "ts": 1450073771, "tx": 495, "c": 1450074094, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9777, "ts": 1450073349, "tx": 494, "c": 1450073671, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9775, "ts": 1450072927, "tx": 493, "c": 1450073249, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9772, "ts": 1450072504, "tx": 492, "c": 1450072831, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9770, "ts": 1450072082, "tx": 491, "c": 1450072408, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9769, "ts": 1450071659, "tx": 490, "c": 1450071991, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9767, "ts": 1450071237, "tx": 489, "c": 1450071568, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9765, "ts": 1450070815, "tx": 488, "c": 1450071146, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9763, "ts": 1450070393, "tx": 487, "c": 1450070727, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9761, "ts": 1450069970, "tx": 486, "c": 1450070304, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9759, "ts": 1450069548, "tx": 485, "c": 1450069887, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9756, "ts": 1450069125, "tx": 484, "c": 1450069464, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9755, "ts": 1450068704, "tx": 483, "c": 1450069045, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9753, "ts": 1450068281, "tx": 482, "c": 1450068622, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9751, "ts": 1450067859, "tx": 481, "c": 1450068200, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9749, "ts": 1450067436, "tx": 480, "c": 1450067777, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9747, "ts": 1450067014, "tx": 479, "c": 1450067360, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9745, "ts": 1450066591, "tx": 478, "c": 1450066937, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9738, "ts": 1450066169, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9739, "ts": 1450065749, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9740, "ts": 1450065329, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9741, "ts": 1450064909, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9742, "ts": 1450064489, "tx": 477, "c":


folgendes Reading habe ich angelegt:

attr wetterstat readingsName_Windstärke Windstärke
attr wetterstat readingsRegex_Windstärke "measurements": .{2,90}"ws": (\d*\d.\d)

und bekomme kein Ergebnis.
mit Regex:
attr wetterstat readingsRegex_Windstärke "measurements": .*"ws": (\d*\d.\d)

bekomme ich den letzten "ws" Wert, aber der ist nicht relevant.

Die Regx funktioniert mit einem Online regex tester, warum in Fhem nicht.
Habe schon alle möglichen Dokus durch aber wahrscheinlich nicht dei richtige gefunden.

Vielleicht kann einer helfen?

Gruß aus Essen
Ulrich

Muschelpuster

Zitat von: UvG am 16 Dezember 2015, 13:01:30attr wetterstat readingsName_Windstärke Windstärke
attr wetterstat readingsRegex_Windstärke "measurements": .{2,90}"ws": (\d*\d.\d)
und bekomme kein Ergebnis.
Mhh, was willst Du denn aus dem Webinhalt haben?. Kannst Du das mal markieren (Farbe, Fett o.ä.)! Ich finde nämlich nicht, was Du auswerten möchtest...

blinde Grüße
Niels
fhem @ ZBOX mit 1,6MHz Celeron, 4GB RAM & 120GB SSD mit Debian Bullseye # MiLight # Homematic via CCU3 # W&T WebIO # Rademacher DuoFern # ESPeasy # logdb@mysql # configdb@mysql # Shelly @ MQTT2 # go-eCharger mit PV-Überschussladung via DOIF

UvG

HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Length: 12896 Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 16 Dec 2015 11:22:56 GMT Connection: close { "success": true, "primarydomain": "www.data199.com", "phoneid": "586364039493", "result": { "devices": [ { "deviceid": "0B080D8F558D", "devicetypeid": 11, "name": "windsensor", "lang": "de", "lastseen": 1450080950, "lowbattery": false, "alertwasactive": false, "settings": { "wsalarmactive": false, "ws": 1.0, "wgalarmactive": false, "wg": 1.0, "wats": 360, "wdnalarmactive": true, "wdnnealarmactive": true, "wdnealarmactive": true, "wdenealarmactive": true, "wdealarmactive": true, "wdesealarmactive": true, "wdsealarmactive": true, "wdssealarmactive": true, "wdsalarmactive": true, "wdsswalarmactive": true, "wdswalarmactive": true, "wdwswalarmactive": true, "wdwalarmactive": true, "wdwnwalarmactive": true, "wdnwalarmactive": true, "wdnnwalarmactive": true }, "measurements": [ { "idx": 9812, "ts": 1450080950, "tx": 512, "c": 1450081022, "pr": false, "ws": 0.5, "wg": 3.4000000000000004, "wd": 7 }, { "idx": 9810, "ts": 1450080528, "tx": 511, "c": 1450080826, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9809, "ts": 1450080106, "tx": 510, "c": 1450080404, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9806, "ts": 1450079684, "tx": 509, "c": 1450079986, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9804, "ts": 1450079261, "tx": 508, "c": 1450079561, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9802, "ts": 1450078838, "tx": 507, "c": 1450079143, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9800, "ts": 1450078417, "tx": 506, "c": 1450078720, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9798, "ts": 1450077994, "tx": 505, "c": 1450078302, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9796, "ts": 1450077571, "tx": 504, "c": 1450077880, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9794, "ts": 1450077150, "tx": 503, "c": 1450077458, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9792, "ts": 1450076727, "tx": 502, "c": 1450077036, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9790, "ts": 1450076305, "tx": 501, "c": 1450076619, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9788, "ts": 1450075882, "tx": 500, "c": 1450076197, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9786, "ts": 1450075461, "tx": 499, "c": 1450075774, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9784, "ts": 1450075038, "tx": 498, "c": 1450075356, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9783, "ts": 1450074616, "tx": 497, "c": 1450074934, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9781, "ts": 1450074193, "tx": 496, "c": 1450074512, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9779, "ts": 1450073771, "tx": 495, "c": 1450074094, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9777, "ts": 1450073349, "tx": 494, "c": 1450073671, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9775, "ts": 1450072927, "tx": 493, "c": 1450073249, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9772, "ts": 1450072504, "tx": 492, "c": 1450072831, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9770, "ts": 1450072082, "tx": 491, "c": 1450072408, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9769, "ts": 1450071659, "tx": 490, "c": 1450071991, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9767, "ts": 1450071237, "tx": 489, "c": 1450071568, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9765, "ts": 1450070815, "tx": 488, "c": 1450071146, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9763, "ts": 1450070393, "tx": 487, "c": 1450070727, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9761, "ts": 1450069970, "tx": 486, "c": 1450070304, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9759, "ts": 1450069548, "tx": 485, "c": 1450069887, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9756, "ts": 1450069125, "tx": 484, "c": 1450069464, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9755, "ts": 1450068704, "tx": 483, "c": 1450069045, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9753, "ts": 1450068281, "tx": 482, "c": 1450068622, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9751, "ts": 1450067859, "tx": 481, "c": 1450068200, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9749, "ts": 1450067436, "tx": 480, "c": 1450067777, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9747, "ts": 1450067014, "tx": 479, "c": 1450067360, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9745, "ts": 1450066591, "tx": 478, "c": 1450066937, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9738, "ts": 1450066169, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9739, "ts": 1450065749, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9740, "ts": 1450065329, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9741, "ts": 1450064909, "tx": 477, "c": 1450066519, "pr": false, "ws": 0.0, "wg": 0.0, "wd": 11 }, { "idx": 9742, "ts": 1450064489, "tx": 477, "c":

Auswerten möchte ich den grün markierten Wert von "ws": 0,5 .
ws kommt mehrfach vor. mit der 2 regex
attr wetterstat readingsRegex_Windstärke "measurements": .*"ws": (\d*\d.\d)
bekomme ich den letzten Wert "ws": 0.0

Ulrich

UvG

Ich glaube ich habe eine Lösung gefunden. Mit Regex:

attr wetterstat readingsRegex_Windstärke (?s)"measurements": .*? "ws": (\d*\d.\d)

wird mir der richtige Wert von 0.5 ins Reading geschrieben.
Aber warum?

Ulrich

Muschelpuster

Ja, das ist manchmal spannend. Unglücklicherweise gibt es ja Dialekte in den regulären Ausdrücken und ich habe da auch gerade mit dem Dialekt von Perl und FHEM so meine Probleme... Aber Du brauchst also auf jeden Fall das erste Ergebnis von ws.
Was ich z.B. gerade erst beim Schreiben verstanden habe, ist dass  (\d*\d.\d) funktioniert. Eigentlich ist doch \d* beliebig häufiges Auftreten einer Ziffer (auch 0 mal), \d eine Ziffer, der Punkt ein beliebiges Zeichen (und demzufolge natürlich auch ein Punkt) und eben noch mal eine Ziffer. Um wirklich zu schauen, dass da ein Punkt ist, müsste es  (\d*\d\.\d) heißen (Aufheben der Meta-Eigenschaften eines Zeichens).
Ich denke, Du markierst mit .*? einfach so, dass Du das 1. Auftreten haben möchtest. Das Fragezeichen sagt ja eigentlich aus, dass das voranstehende Zeichen 0-1 mal auftreten muss, aber nicht zig mal. Cool, genau so etwas habe ich letztens auch gesucht.

vermutete Grüße
Niels
fhem @ ZBOX mit 1,6MHz Celeron, 4GB RAM & 120GB SSD mit Debian Bullseye # MiLight # Homematic via CCU3 # W&T WebIO # Rademacher DuoFern # ESPeasy # logdb@mysql # configdb@mysql # Shelly @ MQTT2 # go-eCharger mit PV-Überschussladung via DOIF

UvG

Ja FHEM und der Dialekt von Perl ist mir auch oft schleierhaft.

So funktioniert folgende Regex nicht:

(?s)"measurements": (.*?"ws":){5} (\d*\d.\d)

wäre aber interessant um genau den 5 Wert von ws zu bekommen.
Es wäre gut wenn einer erklären könnte was bei Regex geht und was nicht.

Ulrich

UvG

regex muß natürlich eine ) anstelle Smiley sein
(?s)"measurements": (.*?"ws":){5} (\d*\d.\d)

marvin78

Vielleicht verwendest du einfach Code-Tags.