[gelöst] Regex wird nicht immer ausgelesen

Begonnen von Thoffi1978, 26 Dezember 2020, 12:08:27

Vorheriges Thema - Nächstes Thema

Thoffi1978

Anbei der Screenshot. Ich hoffe, dass dies der richtige ist.

Hoffi

amenomade

Na gut, die "Response" ist aber doch simpel... Ich weiss immer noch nicht wo dieses /div herkommt.

Versuche dann mit
(?s)\/head.*?([-+ ]*[\d\.]+)
oder
(?s)body.*?([-+ ]*[\d\.]+)
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

xenos1984

Ich würde vielleicht noch mal schauen, ob das, was da wie ein Leerzeichen aussieht, wirklich eins ist, und nicht irgendein gleich aussehendes Zeichen wie z.B. ein "non-breaking space" oder ähnliches. In dem Fall würde die RegEx nicht passen und man bräuchte eher sowas:

^[-+\s]*[\d\.]+

amenomade

Zitat von: xenos1984 am 30 Dezember 2020, 17:50:10
Ich würde vielleicht noch mal schauen, ob das, was da wie ein Leerzeichen aussieht, wirklich eins ist, und nicht irgendein gleich aussehendes Zeichen wie z.B. ein "non-breaking space" oder ähnliches. In dem Fall würde die RegEx nicht passen und man bräuchte eher sowas:

^[-+\s]*[\d\.]+
Hast recht
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Thoffi1978

Hallo,
ich habe alle 3 Vorschläge ausprobiert. Die Temperatur wird wohl schon ausgelesen. Der httpbody ist passend gefüllt.
Leider wird der Wert aber nicht in den State übergeben.

Hier die vorgeschlagenen Regex und der passende Log:
^[-+\s]*[\d\.]+
2020.12.31 08:21:47 4 : Temperatur: GetUpdate called (update)
2020.12.31 08:21:47 4 : Temperatur: UpdateTimer called from GetUpdate with cmd next sets timer to call update function in 120.0 sec at 2020-12-31 08:23:47, interval 120
2020.12.31 08:21:47 5 : Temperatur: AddToQueue adds type update to URL http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), no data, no headers, retry 0, initial queue len: 0
2020.12.31 08:21:47 5 : Temperatur: HandleSendQueue called from AddToSendQueue, qlen = 1
2020.12.31 08:21:47 4 : Temperatur: HandleSendQueue sends update with timeout 10 to http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), No Data, No Header
2020.12.31 08:21:47 5 : Temperatur: ReadCallback called from __ANON__
2020.12.31 08:21:47 4 : Temperatur: BodyDecode found charset header and set decoding to utf-8 (bodyDecode was set to auto)
2020.12.31 08:21:47 4 : Temperatur: BodyDecode is decoding the response body as utf-8
2020.12.31 08:21:47 5 : Temperatur: GetCookies is looking for Cookies
2020.12.31 08:21:47 5 : Temperatur: ExtractSid called, context reading, num 0
2020.12.31 08:21:47 4 : Temperatur: checking for redirects, code=200, ignore=0
2020.12.31 08:21:47 4 : Temperatur: no redirects to handle
2020.12.31 08:21:47 5 : Temperatur: Read callback sets LAST_REQUEST to update
2020.12.31 08:21:47 5 : Temperatur: CheckAuth decided no authentication required
2020.12.31 08:21:47 5 : Temperatur: Read starts parsing response to update with defined readings: 01
2020.12.31 08:21:47 5 : Temperatur: ExtractReading state with regex /(?^:^[-+\s]*[\d\.]+)/...
2020.12.31 08:21:47 5 : Temperatur: ExtractReading state did not match
2020.12.31 08:21:47 4 : Temperatur: Read response to update didn't match any Reading
2020.12.31 08:21:47 5 : Temperatur: HandleSendQueue called from ReadCallback, qlen = 0
2020.12.31 08:21:47 5 : Temperatur: HandleSendQueue found no usable entry in queue
2020.12.31 08:21:47 4 : Temperatur: Read callback: request type was update retry 0, header: HTTP/1.0 200 OK Content-type: text/plain; charset=utf-8, body length 5
2020.12.31 08:21:47 5 : Temperatur: Read callback: body + 3.1


^[-+\s]*[\d\.]+
2020.12.31 08:25:47 4 : Temperatur: GetUpdate called (update)
2020.12.31 08:25:47 4 : Temperatur: UpdateTimer called from GetUpdate with cmd next sets timer to call update function in 120.0 sec at 2020-12-31 08:27:47, interval 120
2020.12.31 08:25:47 5 : Temperatur: AddToQueue adds type update to URL http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), no data, no headers, retry 0, initial queue len: 0
2020.12.31 08:25:47 5 : Temperatur: HandleSendQueue called from AddToSendQueue, qlen = 1
2020.12.31 08:25:47 4 : Temperatur: HandleSendQueue sends update with timeout 10 to http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), No Data, No Header
2020.12.31 08:25:47 5 : Temperatur: ReadCallback called from __ANON__
2020.12.31 08:25:47 4 : Temperatur: BodyDecode found charset header and set decoding to utf-8 (bodyDecode was set to auto)
2020.12.31 08:25:47 4 : Temperatur: BodyDecode is decoding the response body as utf-8
2020.12.31 08:25:47 5 : Temperatur: GetCookies is looking for Cookies
2020.12.31 08:25:47 5 : Temperatur: ExtractSid called, context reading, num 0
2020.12.31 08:25:47 4 : Temperatur: checking for redirects, code=200, ignore=0
2020.12.31 08:25:47 4 : Temperatur: no redirects to handle
2020.12.31 08:25:47 5 : Temperatur: Read callback sets LAST_REQUEST to update
2020.12.31 08:25:47 5 : Temperatur: CheckAuth decided no authentication required
2020.12.31 08:25:48 5 : Temperatur: Read starts parsing response to update with defined readings: 01
2020.12.31 08:25:48 5 : Temperatur: ExtractReading state with regex /(?^:(?s)body.*?([-+ ]*[\d\.]+))/...
2020.12.31 08:25:48 5 : Temperatur: ExtractReading state did not match
2020.12.31 08:25:48 4 : Temperatur: Read response to update didn't match any Reading
2020.12.31 08:25:48 5 : Temperatur: HandleSendQueue called from ReadCallback, qlen = 0
2020.12.31 08:25:48 5 : Temperatur: HandleSendQueue found no usable entry in queue
2020.12.31 08:25:47 4 : Temperatur: Read callback: request type was update retry 0, header: HTTP/1.0 200 OK Content-type: text/plain; charset=utf-8, body length 5
2020.12.31 08:25:47 5 : Temperatur: Read callback: body + 3.1


(?s)\/head.*?([-+ ]*[\d\.]+)
2020.12.31 08:27:47 4 : Temperatur: GetUpdate called (update)
2020.12.31 08:27:47 4 : Temperatur: UpdateTimer called from GetUpdate with cmd next sets timer to call update function in 120.0 sec at 2020-12-31 08:29:47, interval 120
2020.12.31 08:27:47 5 : Temperatur: AddToQueue adds type update to URL http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), no data, no headers, retry 0, initial queue len: 0
2020.12.31 08:27:47 5 : Temperatur: HandleSendQueue called from AddToSendQueue, qlen = 1
2020.12.31 08:27:47 4 : Temperatur: HandleSendQueue sends update with timeout 10 to http://Fhem:fhem1234@192.168.2.12/control/rcontrol?action=gettext&message=$(SEN.TIN.CELSIUS), No Data, No Header
2020.12.31 08:27:48 5 : Temperatur: ReadCallback called from __ANON__
2020.12.31 08:27:48 4 : Temperatur: BodyDecode found charset header and set decoding to utf-8 (bodyDecode was set to auto)
2020.12.31 08:27:48 4 : Temperatur: BodyDecode is decoding the response body as utf-8
2020.12.31 08:27:48 5 : Temperatur: GetCookies is looking for Cookies
2020.12.31 08:27:48 5 : Temperatur: ExtractSid called, context reading, num 0
2020.12.31 08:27:48 4 : Temperatur: checking for redirects, code=200, ignore=0
2020.12.31 08:27:48 4 : Temperatur: no redirects to handle
2020.12.31 08:27:48 5 : Temperatur: Read callback sets LAST_REQUEST to update
2020.12.31 08:27:48 5 : Temperatur: CheckAuth decided no authentication required
2020.12.31 08:27:48 5 : Temperatur: UpdateReadingList created list of reading.* nums to parse during getUpdate as 01
2020.12.31 08:27:48 5 : Temperatur: Read starts parsing response to update with defined readings: 01
2020.12.31 08:27:48 5 : Temperatur: ExtractReading state with regex /(?^:(?s)\/head.*?([-+ ]*[\d\.]+))/...
2020.12.31 08:27:48 5 : Temperatur: ExtractReading state did not match
2020.12.31 08:27:48 4 : Temperatur: Read response to update didn't match any Reading
2020.12.31 08:27:48 5 : Temperatur: HandleSendQueue called from ReadCallback, qlen = 0
2020.12.31 08:27:48 5 : Temperatur: HandleSendQueue found no usable entry in queue
2020.12.31 08:27:48 4 : Temperatur: Read callback: request type was update retry 0, header: HTTP/1.0 200 OK Content-type: text/plain; charset=utf-8, body length 5
2020.12.31 08:27:48 5 : Temperatur: Read callback: body + 3.1


Hoffi

amenomade

OK, hab's mit mocky.io getestet. Mit
\n([-+ ]*[\d\.]+)
scheint es zu gehen
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Thoffi1978

#21
Das war´s.

Die Temperatur wird wieder angezeigt.
Der FileLog wird auch beschrieben.


Ein Superherzlichen Dank

Hoffi