Chat freely about anything...

User avatar
By ac21
#10468 Hey guys... :D


I'm trying to create a remote control for my thermostat.
In my project when my phone is connected to the same wifi network as the ESP then everything works but when i switch it to cell data it doesn't. any idea's?

Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("XXX","XXXXXXX")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
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.."<h1> A/C Control panel </h1>";
        buf = buf.."<p> <a href=\"?pin=AC\"><button>Ac</button>";
        buf = buf.."<p> <a href=\"?pin=Heat\"><button>Heat</button>";
        buf = buf.."<p> <a href=\"?pin=OFF\"><button>OFF</button>";
        local _on,_off = "",""
        if(_GET.pin == "AC")then
              gpio.write(led1, gpio.HIGH);
               gpio.write(led2, gpio.LOW);
        --elseif(_GET.pin == "OFF1")then
             -- gpio.write(led1, gpio.LOW);
        elseif(_GET.pin == "Heat")then
              gpio.write(led2, gpio.HIGH);
              gpio.write(led1, gpio.LOW);
        elseif(_GET.pin == "OFF")then
              gpio.write(led2, gpio.LOW);
              gpio.write(led1, gpio.LOW);
        end
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)

Modified Code from Rui Santos
http://randomnerdtutorials.com/esp8266-web-server/
Capture.PNG


As far as how the thermostat project is going i took apart my honeywell unit and it has a complicated(heat-off-cool) switch, i was hoping it was a on off on switch but its a slider type with 20 pins and to reproduce its function would require 8 relays :o
User avatar
By MK1888
#10818 192.168.x.x is your local nework. When you turn off WiFi from your phone it no longer is connected to your LAN.

To access your ESP from outside your LAN you have to set your router up to port-forward requests and then use your router's public IP address.