Closed MechatronikMonkey closed 1 week ago
You have an unexpected closing bracket that break the JSON syntax Correct would be
var msg = string.format(",\"TestValue\":123")
If you were just printing the result from tasmota.read_sensors()
without trying to load it, you would have seen that your JSON was broken
There is no problem wiht tasmota.response_append()
You should better open a discussion instead of an issue when you don't have a qualified bug
Ok that is the problem... dohh ...
I printed the json string over and over again, but didn´t see the incorrect syntax...
Lol, what do you mean I don't have a qualified bug... I just thought it was a bug... I didn't know I needed to qualify somewhere first... Sorry, I am unworthy. Forgive me, honorable Tasmota gods, for I have sinned.
The best way to qualify if it's a bug worth an issue is to first start a discussion If someone say "right, looks like you found a bug" then you're good to go for the Issue 🤣
Enjoy Berry
Beware that while the JSON syntax indeed gets better by keeping those {}
balanced, what you produce is not how a Berry driver is meant to produce sensor values. The appropriate format would be including a name for the sensor object in the JSON, to house individual values, like:
var msg = ',"MyTest":{"TestValue":123}'
As you had no string formatting, no use for string.format
.
But if you had, like a var named myvalue
, you could use a f-string like:
var msg = f',"MyTest":{{"TestValue":{myvalue}}}'
A downside of this easy syntax is that you need to double "your own" {}
in the string.
(I also took the opportunity to improve readability by having '
as string delimiter around the whole string, meaning that then it is no longer needed to escape as \"
).
BTW... I'm not saying can't work without, more like recommending to follow the usual JSON formatting, to be compatible with other tools handling the JSON payloads produced.
The best way to qualify if it's a bug worth an issue is to first start a discussion If someone say "right, looks like you found a bug" then you're good to go for the Issue 🤣
Enjoy Berry
Got it... I open a discussion first in the future...
PROBLEM DESCRIPTION
json.load(tasmota.read_sensors())
returnsnil
aftertasmota.response_append(msg)
in a driverREQUESTED INFORMATION
Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!
Backlog Template; Module; GPIO 255
:Backlog Rule1; Rule2; Rule3
:weblog
to 4 and then, when you experience your issue, provide the output of the Console log:Hello World. nil Hello World. nil Hello World. nil Hello World. nil
class MyTestClass : Driver
end
test_instance = MyTestClass() tasmota.add_driver(test_instance)
def json_append() import string var msg = string.format(",\"TestValue\":123}")
tasmota.response_append(msg)
end