03.09.2020, 08:34
(03.09.2020, 08:25)admin Wrote: decode will just stop the script if JSON is not valid. pdecode should be used if you want your script to continue in case of an error, this is sometimes more convenient if you want to log the error. The most correct approach is to check that the decoded data is a table and it contains all the required fields.OK understood.
Code:if type(data) == 'table' and type(data.indicator) == 'table' then
log(data.indicator.short_name)
end
This is how it is done in the script that I am modifying for Openweather, I can do it here too.
One last question, if the value in example [1] which is 105.43 is wh and I want it in kWh, I divide it by 1000, like this grp.write ('32 / 2/21 ', data.indicator.values [ 1] .value / 1000), the problem is the DPT of the object, since I see that the largest for this case is 14. 4 bytes of decimal number. The problem is that it only gives me 3 of the 5 decimal places I need. How could I do it, pass it to a string for example?
Thank you very much for clarifying my doubts.