Left here for archival purposes.

User avatar
By Pram
#11259
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
Code: Select all--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.."&deg;C</font>&nbsp;</p>";
        buf = buf.."<p><a href=\"?pin=temp\"><button style=\"width:400px;height:200px\"><font size=\"7\">Aktualisieren</font></button></a>&nbsp;</p>";
        buf = buf.."<p><font size=\"7\">LED Status &auml;ndern:</font>&nbsp;</p>";
        buf = buf.."<p><a href=\"?pin=ON\"><button style=\"width:400px;height:200px\"><font size=\"7\">An</font></button></a>&nbsp;<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)
User avatar
By MK1888
#11261 Lesson #1 in troubleshooting: Start with the simplest configuration that works and then move up in complexity.

You have a bunch of things going on. Get a very simple webserver working first. Can you serve HTML to your Safari browser? Like this: <html><body><h1>blah</h1></body></html>

Then add things one at a time until it breaks.

EDIT: By the way...the HTML that you are producing in your last post is not valid. You can't start an HTML page with <font>.
User avatar
By Pram
#11266
MK1888 wrote: Can you serve HTML to your Safari browser? Like this: <html><body><h1>blah</h1></body></html>.

I guess so. So I just do in my case buf = buf.."<html><body><h1>blah</h1></body></html>"; ?
User avatar
By Pram
#11269 Now safari tells me that safari cannot open the site, because the server closed the connection unexpectedly and that the server does not reply