DrozmotiX / ioBroker.wled

IoBroker integration to WLED project
https://github.com/Aircoookie/WLED
MIT License
28 stars 14 forks source link

WLED adapter gets confused when WLED-firmware contains usermods/extended json info #171

Closed jlegen closed 3 years ago

jlegen commented 3 years ago

my WLEDs do have the usermod "usermod_Fix_unreachable_netservices" enabled, to keep them connected (without, the web ui stops responding after some minutes being idle). This mod does extend the json info object (as it is intended), with the little 'speciality' that this extension contains some (seemingly properly quoted) HTML. I think the json result is valid, at least common parsers do not complain, and results do look proper; however, WLED-adapter throws warnings which look like as if the request is not properly parsed.

The json request result (/json/info): {"ver":"0.11.1","vid":2101130,"leds":{"count":150,"rgbw":false,"wv":false,"pin":[2],"pwr":250,"maxpwr":4000,"maxseg":12,"seglock":false},"str":false,"name":"WLED-2","udpport":21324,"live":false,"lm":"","lip":"","ws":0,"fxcount":118,"palcount":56,"wifi":{"bssid":"78:8A:20:B7:0D:74","rssi":-64,"signal":72,"channel":1},"fs":{"u":49,"t":1024,"pmt":1615056140},"arch":"esp8266","core":"2_7_4_7","lwip":1,"freeheap":21048,"uptime":1883032,"u":{"&#x26A1; Ping fix pings<span style=\"display:block;padding-left:25px;\">Delay <input type=\"number\" min=\"5\" max=\"300\" value=\"30\" onchange=\"requestJson({PingDelay:parseInt(this.value)});\">sec</span>":[62762],"&#x26A1; Reconnects":[1]},"opt":127,"brand":"WLED","product":"FOSS","mac":"483fda7eae39"}

WLED adapter 0.5.6 in iobroker log: 2021-03-26 21:21:56.792 - ESC[33mwarnESC[39m: wled.0 (12313) Used invalid characters: wled.0.483fda7eae39._info.u.&#x26A1; Ping fix pings<span style="display:block;padding-left:25px;">Delay <input type="number" min="5" max="300" value="30" onchange="requestJson({PingDelay:parseInt(this.value)});">sec</span> changed to wled.0.483fda7eae39._info.u.&#x26A1_ Ping fix pings_span style=_display:block_padding-left:25px_Delay _input type=_number_ min=_5_ max=_300_ value=_30_ onchange=_requestJson({PingDelay:parseInt(this.value)})_sec_/span_ 2021-03-26 21:21:56.805 - ESC[33mwarnESC[39m: wled.0 (12313) State "wled.0.483fda7eae39._info.u.&#x26A1; Ping fix pings<span style="display:block;padding-left:25px;">Delay <input type="number" min="5" max="300" value="30" onchange="requestJson({PingDelay:parseInt(this.value)});">sec</span>" has no existing object, this might lead to an error in future versions 2021-03-26 21:21:56.806 - ESC[33mwarnESC[39m: wled.0 (12313) Used invalid characters: wled.0.483fda7eae39._info.u.&#x26A1; Reconnects changed to wled.0.483fda7eae39._info.u.&#x26A1_ Reconnects

Not sure if this is related to the fact that usermods are also using the "u:" key, though on root level; the existing "u:" is in "fs:" scope... Perhaps this could somehow be fixed in WLED adapter? Adapter version is 0.5.6, JS controller 3.2.16

DutchmanNL commented 3 years ago

can you re-test with 0.5.7 please ?

DutchmanNL commented 3 years ago

this should ben fixed in WLED as the JSON makes no sense at all with an attribute like this :

"u": { "⚡ Ping fix pings<span style=\"display:block;padding-left:25px;\">Delay <input type=\"number\" min=\"5\" max=\"300\" value=\"30\" onchange=\"requestJson({PingDelay:parseInt(this.value)});\">sec": [ 62762 ],

as u see the key value contains HTML formatted values

jlegen commented 3 years ago

sorry, not sure what you mean; as i already mentioned - the original JSON (as posted above) is valid according to RFC 8259. Can be easily checked with any JSON vaildator, e.g. https://jsonformatter.curiousconcept.com/. Screenshot would be a bit too big for posting here, i think... :) Unfortunately, testing WLED adapter 0.5.7 will take a while, since i have to re-activate that installation for this; has been a while since i used that... ;)

DutchmanNL commented 3 years ago

sorry, not sure what you mean; as i already mentioned - the original JSON (as posted above) is valid according to RFC 8259. Can be easily checked with any JSON vaildator, e.g. https://jsonformatter.curiousconcept.com/. Screenshot would be a bit too big for posting here, i think... :) Unfortunately, testing WLED adapter 0.5.7 will take a while, since i have to re-activate that installation for this; has been a while since i used that... ;)

the JSON itself is a valid format,, but unusable... in the logic we transfer JSON keys to ioBroker states meaning

{key:value}

as the key here is an HTML format, it can't be translated to a proper state format. We expect a key and value and not value combined in a key so in stead of one HTML sting each value should be a separate set like :

{"u":
{ "Key_1":
"attr1": value,
"attr2": value,
}
}
jlegen commented 3 years ago

Ok, got it, thanks; so perhaps this should be noted somewhere, that usermods with GUI extensions are not supported because of this...

DutchmanNL commented 3 years ago

Ok, got it, thanks; so perhaps this should be noted somewhere, that usermods with GUI extensions are not supported because of this...

or I need to know how this key are generated to just filter them out here in the adapter :) Already did something similar here for a value PID, maybe I need to do that more generic

https://github.com/DrozmotiX/ioBroker.wled/commit/42a948b6864b681e01a867056e1d29b808614c2b#diff-58417e0f781b6656949d37258c8b9052ed266e2eb7a5163cad7b0863e6b2916aR712

but need examples how it looks like :D

DutchmanNL commented 3 years ago

fixed in 0.6.x