Im having some trouble with simple http get requests.
Example :
init.lua
wifi_name = "apname"
wifi_password = "appassword"
server_ip = "192.168.1.1"
server_port = 80
server_host = "zxy.com"
server_path = "/temps.php"
refresh_interval = 10000
dofile('main.lua')
join_wifi()
mainthingie()
main.lua
function join_wifi()
wifi.setmode(wifi.STATION)
wifi.sta.config(wifi_name,wifi_password)
end
function http_send_temp(sensor, temp)
conn=net.createConnection(net.TCP, 0)
conn:on("connection", function()
conn:send("GET "..server_path.."&sensor_id="..sensor.."&temp="..temp.." HTTP/1.1\r\nHost: "..server_host.."\r\n".."Connection: close\r\nAccept: */*\r\n\r\n")
conn:close()
end)
conn:connect(server_port, server_ip)
end
function mainthingie()
tmr.alarm(0, refresh_interval, 1,function()
http_send_temp("test1",50)
http_send_temp("test2",55)
end)
end
In mainthingie(), when i call http_send_temp() once -> works like a charm. When i do it twice, only last request is really made.
I was hoping to send multiple temperatures (ds18b20) to server, each in its own get request.
My guess is to wait that first request to be completed and only after that i could do it again. How can i accomplish that?
-Thanks