From de6f67c85c3ca117886fca9fd20456d5961fd752 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Thu, 18 Oct 2018 16:57:23 +0200 Subject: [PATCH] =?UTF-8?q?-=20compl=C3=A8tement=20refactorise=20la=20d?= =?UTF-8?q?=C3=A9mo=20de=20web=20serveur=20pour=20le=20workshop.=20Vraimen?= =?UTF-8?q?t=20une=20grande=20avanc=C3=A9e=20dans=20la=20modularit=C3=A9.?= =?UTF-8?q?=20On=20peut=20maintenant=20avoir=20diff=C3=A9rentes=20r=C3=A9p?= =?UTF-8?q?onses=20HTML=20en=20fonction=20des=20GET=20re=C3=A7u=20-=20reno?= =?UTF-8?q?mm=C3=A9=20le=20script=20start=5Fboot=20en=20a=5Fstart=5Fboot?= =?UTF-8?q?=20afin=20qu'il=20se=20trouve=20au=20d=C3=A9but=20des=20fichier?= =?UTF-8?q?s=20sur=20la=20FLASH,=20c'est=20beaucoup=20plus=20simple=20pour?= =?UTF-8?q?=20le=20d=C3=A9marrer=20apr=C3=A8s=20chaque=20restart=20;-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workshop/181015/script1.lua | 13 ------------- .../web_srv/{start_boot.lua => a_start_boot.lua} | 4 ++-- Workshop/181015/web_srv/initz.lua | 6 +++--- Workshop/181015/web_srv/led_job.lua | 13 +------------ Workshop/181015/web_srv/web_get.lua | 6 +++++- Workshop/181015/web_srv/web_html.lua | 10 ++++------ Workshop/181015/web_srv/web_srv.lua | 4 +--- 7 files changed, 16 insertions(+), 40 deletions(-) delete mode 100644 Workshop/181015/script1.lua rename Workshop/181015/web_srv/{start_boot.lua => a_start_boot.lua} (70%) diff --git a/Workshop/181015/script1.lua b/Workshop/181015/script1.lua deleted file mode 100644 index 6cb3532..0000000 --- a/Workshop/181015/script1.lua +++ /dev/null @@ -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 diff --git a/Workshop/181015/web_srv/start_boot.lua b/Workshop/181015/web_srv/a_start_boot.lua similarity index 70% rename from Workshop/181015/web_srv/start_boot.lua rename to Workshop/181015/web_srv/a_start_boot.lua index 46a4183..e6565b8 100644 --- a/Workshop/181015/web_srv/start_boot.lua +++ b/Workshop/181015/web_srv/a_start_boot.lua @@ -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") diff --git a/Workshop/181015/web_srv/initz.lua b/Workshop/181015/web_srv/initz.lua index 97951ca..feb1614 100644 --- a/Workshop/181015/web_srv/initz.lua +++ b/Workshop/181015/web_srv/initz.lua @@ -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) diff --git a/Workshop/181015/web_srv/led_job.lua b/Workshop/181015/web_srv/led_job.lua index 11b19c3..f960175 100644 --- a/Workshop/181015/web_srv/led_job.lua +++ b/Workshop/181015/web_srv/led_job.lua @@ -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 .. "OFFON" diff --git a/Workshop/181015/web_srv/web_get.lua b/Workshop/181015/web_srv/web_get.lua index 926bfd6..ddfd1c6 100644 --- a/Workshop/181015/web_srv/web_get.lua +++ b/Workshop/181015/web_srv/web_get.lua @@ -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 diff --git a/Workshop/181015/web_srv/web_html.lua b/Workshop/181015/web_srv/web_html.lua index e27a5ae..b0c6275 100644 --- a/Workshop/181015/web_srv/web_html.lua +++ b/Workshop/181015/web_srv/web_html.lua @@ -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 = "\n" - buf = buf .. "

Hello, this is NodeMCU. 1142

\n" - + buf = buf .. "

Hello, this is NodeMCU. 1608

\n" buf = buf .. "Usage:

\n" buf = buf .. "pour allumer la LED, http://xxx/?led=on
\n" buf = buf .. "pour éteindre la LED, http://xxx/?led=off
\n" - buf = buf .. "" - end + diff --git a/Workshop/181015/web_srv/web_srv.lua b/Workshop/181015/web_srv/web_srv.lua index 4843fb5..9cb7b73 100644 --- a/Workshop/181015/web_srv/web_srv.lua +++ b/Workshop/181015/web_srv/web_srv.lua @@ -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