I want to connect the ESP - 01 to a webapi server, which sends data, which contains different information, dynamically in JSON. I want this information to be displayed on the LCD connected to the ESP. I do not know how to decode the JSON data. The server address is 192.168.1.8:8057/api.
OK. I try this:
sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c)
d = c
end )
sk:connect(8095,"192.168.1.8")
sk:send("GET /api/ HTTP/1.1\r\nHost: 192.168.1.8\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
print(d)
and it display result:
{"lowVersion":1,"highVersion":3}
If I try:
sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c)
d = c
end )
sk:connect(8095,"192.168.1.8")
sk:send("GET /api/ HTTP/1.1\r\nHost: 192.168.1.8\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
local t = cjson.decode(d)
print(t.lowVersion)
is display:
test.lua:10: Expected value but found invalid token at character 1
How to display the value "lowVersion" or "highVersion" from JSON?