- totalement remanié la structure de mon dépôt, cela commençait à être trop le foutoire ;-(

This commit is contained in:
Christian Zufferey
2018-11-18 10:36:16 +01:00
parent 3bfc2949d2
commit b2b632a6cd
61 changed files with 56 additions and 1214 deletions

8
WEB/u_web_stop.lua Executable file
View File

@@ -0,0 +1,8 @@
--Pour arrêter le petit serveur WEB
print("\nzf20180718.1049")
srv:close()
srv:listen(80, function(conn)
end)
print("\nWEB stopped\n")

51
WEB/web_led_onoff.lua Normal file
View File

@@ -0,0 +1,51 @@
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
--hv20180711.1606
print("Démarrage")
--wifi.sta.disconnect()
--wifi.setmode(wifi.STATION)
--print("set mode=STATION (mode="..wifi.getmode()..")")
--wifi.sta.config{ssid="Hugo", pwd="tototutu"}
wifi.sta.connect()
tmr.alarm(0, 1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
print("Connected! IP: ",wifi.sta.getip())
tmr.stop(0)
end
end)
zLED=0
gpio.mode(zLED, gpio.OUTPUT)
gpio.write(zLED, gpio.HIGH)
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 .. "<!DOCTYPE html><html><body><h1>Hello, this is NodeMCU.</h1><form src=\"/\">Turn PIN <select name=\"pin\" onchange=\"form.submit()\">"
local _on, _off = "", ""
if (_GET.pin == "ON") then
_on = " selected=true"
gpio.write(zLED, gpio.LOW)
elseif (_GET.pin == "OFF") then
_off = " selected=\"true\""
gpio.write(zLED, gpio.HIGH)
end
buf = buf .. "<option" .. _on .. ">ON</option><option" .. _off .. ">OFF</option></select></form></body></html>"
client:send(buf)
end)
conn:on("sent", function(c) c:close() end)
end)

75
WEB/web_oled_decode_url.lua Executable file
View File

@@ -0,0 +1,75 @@
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
print("\nDémarrage hv20180711.1606\n")
hvtime=tmr.create()
wifi.sta.connect()
tmr.alarm(hvtime, 1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
print("Connected! IP: ",wifi.sta.getip())
tmr.stop(hvtime)
end
end)
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 = {}
print("\nNouvelle entrée !")
if (vars ~= nil) then
print("Input: "..vars)
for k, v in string.gmatch(vars, "(%w+)=([%w+-@%%]+)&*") do
_GET[k] = v
print(k..": "..v)
end
end
buf = buf .. "<!DOCTYPE html><html><body><h1>web_oled</h1></br><form name=\"hform\">"
if _GET.hinput=="Valider" then
print((string.gsub(unescape(_GET.htext),"+"," ")))
end
buf = buf .. "<textarea name=\"htext\">hello zuzu</textarea> </br> <input name=\"hinput\" type=\"submit\"></input></form></body></html>"
client:send(buf)
end)
conn:on("sent", function(c) c:close() end)
end)
--source: https://github.com/diegonehab/luasocket/blob/master/src/url.lua
function unescape(s)
return (string.gsub(s, "%%(%x%x)", function(hex)
return string.char(tonumber(hex, 16))
end))
end
--[[
--t1="hello+zuzu+%26+une+belle+%E9cole"
t1="hello+zuzu+%26+une+belle+%E9cole%5Cnun+b%E2teau"
print(string.char(tostring(tonumber("3F", 16))))
print(string.char(63))
print(unescape("%26"))
t3=string.gsub(unescape(t1),"+"," ")
print(t3)
t2="école\ntoto"
print(t2)
]]
--print( string.gsub("hello+zuzu+%26+une+belle+%E9cole%5Cun+b%E2teau","+"," ")
--[[ source OLED:
https://www.google.ch/search?q=nodemcu+lua+oled+display&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjG8ba8ra3cAhVDCpoKHedlDS4Q_AUICigB&biw=1536&bih=828
https://www.hackster.io/kayakpete/esp8266-oled-display-52ae50
http://blog.rl.cx/2017/01/08/bien-d%C3%A9buter-avec-nodemcu/
https://github.com/FredThx/nodemcu_iot/blob/master/i2c_display.lua
https://www.instructables.com/id/NODEMCU-LUA-ESP8266-With-I2C-LCD-128-X-64-OLED-Dis/
]]

51
WEB/web_on_off1.lua Normal file
View File

@@ -0,0 +1,51 @@
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
print("\nDémarrage hv&zf20180718.1041\n")
--wifi.sta.disconnect()
--wifi.setmode(wifi.STATION)
--print("set mode=STATION (mode="..wifi.getmode()..")")
--wifi.sta.config{ssid="Hugo", pwd="tototutu"}
wifi.sta.connect()
tmr.alarm(0, 1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
print("Connected! IP: ",wifi.sta.getip())
tmr.stop(0)
end
end)
zLED=0
gpio.mode(zLED, gpio.OUTPUT)
gpio.write(zLED, gpio.HIGH)
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 .. "<!DOCTYPE html><html><body><h1>Hello, this is NodeMCU.</h1>Turn PIN : </br></br>"
local _on, _off = "", ""
if (_GET.pin == "ON") then
_on = " selected=true"
gpio.write(zLED, gpio.LOW)
elseif (_GET.pin == "OFF") then
_off = " selected=\"true\""
gpio.write(zLED, gpio.HIGH)
end
buf = buf .. "<a href=\"?pin=ON\"><button>ON</button></a> <a href=\"?pin=OFF\"><button>OFF</button></a>"
client:send(buf)
end)
conn:on("sent", function(c) c:close() end)
end)

8
WEB/web_stop.lua Normal file
View File

@@ -0,0 +1,8 @@
--Pour arrêter le petit serveur WEB
print("\nzf20180718.1049")
srv:close()
srv:listen(80, function(conn)
end)
print("\nWEB stopped\n")