HowtoIotSicurezza Informatica

Esp8266 LUA Webserver. Controlliamo due led .

Esp8266 LUA Webserver

Controlliamo 2 led con LUA e Esp8266-01

esp8266-01 la mia borad per programmazione autocostruita
esp8266-01 la mia borad per programmazione autocostruita

 

 

E’ stato uno dei miei primi “programmi” per Esp8266 con controllo di stato …… ( risposta per @luigi71 @flavia @marco98 @telephys)

Esp8266 viene impostato come AP con le seguenti caratteristiche:

Sid = myssid

Password = password

Ip: 192.168.1.254

riga e riga1 servono a identificare lo status delle porte.

Dovrebbe funzionare tutto … e Buon Esp8266 !!

 

Download file : link per scaricare il file init.lua.txt

rinomina il file in .lua e upload su esp8266-01

—————————————————————————————–

wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid=”myssid”,pwd=”password”})
wifi.ap.setip({ip=”192.168.1.254″,netmask=”255.255.255.0″,gateway=”192.168.1.254″})
print(wifi.ap.getip())

riga = “Non So – Resettato/On Now”
riga1 = “Non So – Resettato/On Now”

led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)

— Apro connessione
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> Flash By AiutoComputerHelp </h1>”;
buf = buf..”<h2> ip = 192.168.1.254</h2>”;
buf = buf..”<p>Porta 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\”?pin=ON1\”><button>ON</button></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\”?pin=OFF1\”><button>OFF</button></a></p>”;
buf = buf..”<p>Porta 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\”?pin=ON2\”><button>ON</button></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=\”?pin=OFF2\”><button>OFF</button></a></p>”;
buf = buf..”<h2> Status Attuale</h2>”

local _on,_off = “”,””
if(_GET.pin == “ON1”)then
gpio.write(led1, gpio.HIGH);
riga = “Porta 1 ON”;
elseif(_GET.pin == “OFF1”)then
gpio.write(led1, gpio.LOW);
riga = “Porta 1 OFF”;
elseif(_GET.pin == “ON2”)then
gpio.write(led2, gpio.HIGH);
riga1 = “Porta 2 ON”;
elseif(_GET.pin == “OFF2”)then
gpio.write(led2, gpio.LOW);
riga1 = “Porta 2 OFF”;
end

buf = buf..riga;
buf = buf..”<h2> </h2>”;
buf = buf..riga1;

client:send(buf);
client:close();

collectgarbage();

end)

end)

—————————————————————————————–

 

G.P