- complètement refactorise la démo de web serveur pour le workshop. Vraiment une grande avancée dans la modularité.

On peut maintenant avoir différentes réponses HTML en fonction des GET reçu
- renommé le script start_boot en a_start_boot afin qu'il se trouve au début des fichiers sur la FLASH, c'est beaucoup
plus simple pour le démarrer après chaque restart ;-)
This commit is contained in:
Christian Zufferey
2018-10-18 16:57:23 +02:00
parent 3d2e7363ec
commit de6f67c85c
7 changed files with 16 additions and 40 deletions

View File

@@ -1,13 +0,0 @@
-- Exemple de programme à ne PAS faire sur NodeMCU Lua script
-- programme pour faire clignoter une LED avec un rapport on/off
--zf20181004.1430
zLED=0
gpio.mode(zLED, gpio.OUTPUT)
while true do
gpio.write(zLED, 0)
tmr.delay(1000*500)
gpio.write(zLED, 1)
tmr.delay(1000*500)
end

View File

@@ -1,6 +1,6 @@
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf181018.1116 \n")
print("\n a_start_boot.lua zf181018.1624 \n")
--dofile("wifi_ap_stop.lua")
--dofile("wifi_cli_conf.lua")
@@ -9,7 +9,7 @@ dofile("wifi_cli_start.lua")
dofile("led_job.lua")
dofile("web_srv.lua")
--dofile("flash_led_xfois.lua")
dofile("flash_led_xfois.lua")

View File

@@ -1,7 +1,7 @@
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
-- autrement en attendant 8 secondes cela démarre start_boot
print("\n init.lua zf181017.1026\n")
print("\n init.lua zf181018.1623\n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
@@ -10,7 +10,7 @@ initalarme=tmr.create()
function hvbouton()
gpio.trig(zswitch, "none")
tmr.unregister(initalarme)
dofile("start_boot.lua")
dofile("a_start_boot.lua")
-- dofile("start_job.lua")
end
@@ -18,6 +18,6 @@ gpio.trig(zswitch, "both", hvbouton)
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("start_boot.lua")
dofile("a_start_boot.lua")
-- dofile("start_job.lua")
end)

View File

@@ -1,6 +1,6 @@
--Petit script pour la gestion de la LED, juste pour comprendre la prog ;-)
print("\n led_job.lua zf181018.1104 \n")
print("\n led_job.lua zf181018.1616 \n")
zLED=0
gpio.mode(zLED, gpio.OUTPUT)
@@ -19,14 +19,3 @@ end
led_on()
led_off()
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" .. _off .. ">OFF</option><option" .. _on .. ">ON</option></select></form></body></html>"

View File

@@ -1,12 +1,16 @@
-- petit script pour la gestion du GET du serveur web
print("\n web_get.lua zf181018.1142 \n")
print("\n web_get.lua zf181018.1649 \n")
function web_get()
if (_GET.led == "on") then
led_on()
html_home()
elseif (_GET.led == "off") then
led_off()
html_home()
else
html_home()
end
end

View File

@@ -1,16 +1,14 @@
-- petit script pour le HTML du serveur web
print("\n web_html.lua zf181018.1142 \n")
print("\n web_html.lua zf181018.1621 \n")
--Partie HTML et CSS pour la page web
function web_html()
function html_home()
buf = "<!DOCTYPE html><html><body><meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>\n"
buf = buf .. "<h1>Hello, this is NodeMCU. 1142 </h1>\n"
buf = buf .. "<h1>Hello, this is NodeMCU. 1608 </h1>\n"
buf = buf .. "Usage: <br><br>\n"
buf = buf .. "pour allumer la LED, http://xxx/?led=on<br>\n"
buf = buf .. "pour éteindre la LED, http://xxx/?led=off<br>\n"
buf = buf .. "</body></html>"
end

View File

@@ -1,6 +1,6 @@
-- petit script de serveur WEB Wifi
print("\n web_srv.lua zf181018.1031 \n")
print("\n web_srv.lua zf181018.1610 \n")
dofile("web_get.lua")
dofile("web_html.lua")
@@ -29,8 +29,6 @@ srv:listen(80, function(conn)
end
end
web_get()
web_html()
--print("send html...")
client:send(buf)
buf=nil
end