dpwhittaker wrote:Does it help if you put connection:close inside the connection:on("sent", callback)?
Isn't it ?
I now have a slighltly different code, but it still does not work with safari, only with firefox.
The Code:
init.lua
--include
require('ds18b20')
--wifi settings
--cfg={}
--cfg.ssid="nodeduino"
--cfg.pwd=""
--setup wifi ap
wifi.setmode(wifi.SOFTAP)
--wifi.ap.config(cfg)
wifi.ap.config({ssid="NODEDUINO",pwd=""})
print(wifi.ap.getip())
--in/outpus
led = 4
gpio.mode(led, gpio.OUTPUT)
tempp = 3
ds18b20.setup(tempp)
--variables
--ledstat = 0
--get temperature & store
t1=ds18b20.read()
t1=ds18b20.read()
--main
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<font size=\"12\">Nodeduino Beispiel</font>";
buf = buf.."<p><font size=\"7\">Temperatur: "..t1.."°C</font> </p>";
buf = buf.."<p><a href=\"?pin=temp\"><button style=\"width:400px;height:200px\"><font size=\"7\">Aktualisieren</font></button></a> </p>";
buf = buf.."<p><font size=\"7\">LED Status ändern:</font> </p>";
buf = buf.."<p><a href=\"?pin=ON\"><button style=\"width:400px;height:200px\"><font size=\"7\">An</font></button></a> <a href=\"?pin=OFF\"><button style=\"width:400px;height:200px\"><font size=\"7\">Aus</font></button></a></p>";
local _on,_off = "",""
if(_GET.pin == "temp")then
t1=ds18b20.read()
t1=ds18b20.read()
elseif(_GET.pin == "ON")then
gpio.write(led, gpio.HIGH);
elseif(_GET.pin == "OFF")then
gpio.write(led, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)