Bien refactorisé et simplifié les exemples pour le Workshop NodeMCU

This commit is contained in:
Christian Zufferey
2020-07-17 18:06:46 +02:00
parent b46db00735
commit 5f864b0d3d
37 changed files with 190 additions and 459 deletions

View File

@@ -1,24 +1,22 @@
-- Programme qui allume la led bleue quand on appuie le bouton flash
-- zf181011.1749
print("\n btn_led.lua zf200302.2356 \n")
print("\n btn_led.lua zf200717.1659 \n")
zledbleue=0 --led bleue
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED,gpio.OUTPUT)
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
function zbtn()
if gpio.read(zswitch)==0 then
zled_state="ON"
gpio.write(zledbleue, gpio.LOW)
if gpio.read(zswitch) == 0 then
zled_state = "ON"
gpio.write(zLED, gpio.LOW)
else
zled_state="OFF"
gpio.write(zledbleue, gpio.HIGH)
gpio.write(zLED, gpio.HIGH)
end
print("btn_led: "..zled_state)
disp_send()
if disp_send ~= nil then disp_send() end
end
gpio.trig(zswitch, "both", zbtn)

View File

@@ -1,32 +0,0 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
print("\n flash_led_xfois.lua zf200302.2316 \n")
zLED=0
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
function blink_LED ()
if nbfois >= xfois then
print(nbfois)
nbfois = 0
else
if gpio.read(zLED)==gpio.HIGH then
gpio.write(zLED, gpio.LOW)
ztmr_LED:alarm(zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
gpio.write(zLED, gpio.HIGH)
nbfois = nbfois+1
ztmr_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
end
end
xfois =2
blink_LED ()

View File

@@ -1,7 +1,7 @@
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
-- 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 zf190808.1537\n")
print("\n init.lua zf200717.1625\n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
@@ -11,7 +11,6 @@ function hvbouton()
gpio.trig(zswitch, "none")
initalarme:unregister()
dofile("start_boot.lua")
-- dofile("start_job.lua")
end
gpio.trig(zswitch, "both", hvbouton)
@@ -19,5 +18,4 @@ gpio.trig(zswitch, "both", hvbouton)
initalarme:alarm(8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("start_boot.lua")
-- dofile("start_job.lua")
end)

View File

@@ -1,10 +1,13 @@
-- Scripts à charger au moment du boot afin de pouvoir travailler avec le robot à distance
print("\n start_boot.lua zf200302.2351 \n")
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf200717.1647 \n")
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED,gpio.OUTPUT)
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
dofile("wifi_ap_stop.lua")
dofile("wifi_cli_conf.lua")
dofile("wifi_cli_start.lua")
dofile("web_cli.lua")
dofile("btn_led.lua")
dofile("flash_led_xfois.lua")
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)

View File

@@ -1,8 +1,7 @@
-- Petit script pour envoyer quelque chose sur un serveur WEB
print("\n web_cli.lua zf200302.2357 \n")
print("\n web_cli.lua zf200717.1707 \n")
function disp_send()
-- http.get("http://192.168.4.1/?line1="..zlength.."m", nil, function(code, data)
print("web_cli: "..zled_state)
http.get("http://192.168.4.1/?pin="..zled_state, nil, function(code, data)
if (code < 0) then

View File

@@ -1,10 +0,0 @@
-- Démarre le WIFI en mode AP
print("\n wifi_ap_stop.lua zf180824.2000 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.SOFTAP then
wifi.setmode(wifi.NULLMODE)
elseif zmodewifi == wifi.STATIONAP then
wifi.setmode(wifi.STATION)
end
print("WIFI AP arrêté")

View File

@@ -1,4 +0,0 @@
-- Petit script pour configurer le client WIFI du NodeMCU
print("\n wifi_cli_conf.lua zf200303.1533 \n")
wifi.sta.config{ssid="NodeMCU btn 3a:2b:78:04:2d:2d", pwd="12345678", save=true}

View File

@@ -1,14 +1,8 @@
-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM
print("\n wifi_cli_start.lua zf180824.2000 \n")
-- Petit script pour connecter le NodeMCU sur un AP Wifi
print("\n wifi_cli_start.lua zf200717.1650 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI mode CLI only")
wifi.setmode(wifi.STATION)
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP+CLI")
wifi.setmode(wifi.STATIONAP)
end
wifi.sta.autoconnect(1)
wifi.sta.config{ssid="btn_led", pwd="12345678"}
wifi.setmode(wifi.STATION)
wifi.sta.connect()
dofile("wifi_get_ip.lua")

View File

@@ -1,5 +1,5 @@
-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi
print("\n wifi_get_ip.lua zf200303.0000 \n")
print("\n wifi_get_ip.lua zf200717.1652 \n")
wifitimer1=tmr.create()
wifitimer1:alarm(1000, tmr.ALARM_AUTO , function()
@@ -8,6 +8,6 @@ wifitimer1:alarm(1000, tmr.ALARM_AUTO , function()
else
wifitimer1:unregister()
dofile("wifi_info.lua")
dofile("flash_led_xfois.lua")
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
end
end)

View File

@@ -1,28 +1,45 @@
-- Petit script pour afficher les infos actuel du WIFI
print("\n wifi_info.lua zf180824.2000 \n")
print("\n wifi_info.lua zf200106.1803 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI OFF")
elseif zmodewifi == wifi.STATION then
print("WIFI mode CLI")
print("Connected IP:\n",wifi.sta.getip())
do
function wifi_info()
local zmodewifi=wifi.getmode()
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
if zmodewifi == wifi.NULLMODE then
print("WIFI OFF")
elseif zmodewifi == wifi.STATION then
print("WIFI mode CLI")
print("Connected IP:\n",wifi.sta.getip())
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
end
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP")
print("AP MAC:\n\t"..wifi.ap.getmac())
print("AP IP:\n\t"..wifi.ap.getip())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP")
print("Connected IP:\n",wifi.sta.getip())
do
print("Current client config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid)
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP\n")
print("CLIENT IP:\n",wifi.sta.getip())
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
print("Current CLIENT config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid.."\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
end
print("AP MAC: "..wifi.ap.getmac())
print("AP IP: "..wifi.ap.getip())
wifi_info=nil
end
wifi_info()

View File

@@ -1,32 +0,0 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
print("\n flash_led_xfois.lua zf200302.2316 \n")
zLED=0
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
function blink_LED ()
if nbfois >= xfois then
print(nbfois)
nbfois = 0
else
if gpio.read(zLED)==gpio.HIGH then
gpio.write(zLED, gpio.LOW)
ztmr_LED:alarm(zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
gpio.write(zLED, gpio.HIGH)
nbfois = nbfois+1
ztmr_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
end
end
xfois =2
blink_LED ()

View File

@@ -1,7 +1,7 @@
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
-- 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 zf190808.1537\n")
print("\n init.lua zf200717.1625\n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
@@ -11,7 +11,6 @@ function hvbouton()
gpio.trig(zswitch, "none")
initalarme:unregister()
dofile("start_boot.lua")
-- dofile("start_job.lua")
end
gpio.trig(zswitch, "both", hvbouton)
@@ -19,5 +18,4 @@ gpio.trig(zswitch, "both", hvbouton)
initalarme:alarm(8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("start_boot.lua")
-- dofile("start_job.lua")
end)

View File

@@ -1,9 +1,13 @@
-- Scripts à charger au moment du boot afin de pouvoir travailler avec le robot à distance
print("\n start_boot.lua zf181015.1643 \n")
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf200717.1647 \n")
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED,gpio.OUTPUT)
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
dofile("wifi_cli_stop.lua")
dofile("wifi_ap_start.lua")
dofile("web_led_onoff.lua")
dofile("flash_led_xfois.lua")
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)

View File

@@ -1,28 +1,7 @@
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
--Petit serveur WEB pour allumer/éteindre une LED en mode serveur WIFI
print("\n web_led_onoff.lua zf181015.1622 \n")
print("\n web_ledstate_onoff.lua zf200717.1734 \n")
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)
@@ -37,18 +16,21 @@ srv:listen(80, function(conn)
_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 = "", ""
buf = "<!DOCTYPE html><html><body><h1>Hello, this is NodeMCU.</h1>"
buf = buf .. "<form src=\"/\">Turn PIN <select name=\"pin\" onchange=\"form.submit()\">"
local state_on, state_off = "", ""
if (_GET.pin == "ON") then
_on = " selected=\"true\""
state_on = " selected=\"true\""
gpio.write(zLED, gpio.LOW)
elseif (_GET.pin == "OFF") then
_off = " selected=\"true\""
state_off = " selected=\"true\""
gpio.write(zLED, gpio.HIGH)
elseif (_GET.pin == "zuzu") then
print("hello zuzu")
end
buf = buf .. "<option" .. _off .. ">OFF</option><option" .. _on .. ">ON</option></select></form></body></html>"
buf = buf .. "<option" .. state_off .. ">OFF</option><option" .. state_on .. ">ON</option></select></form>"
buf = buf .. "</body></html>"
client:send("HTTP/1.1 200 OK\r\n\r\n")
client:send(buf)
end)
conn:on("sent", function(c) c:close() end)

View File

@@ -1,13 +1,10 @@
-- Démarre le WIFI en mode AP
print("\n wifi_ap_start.lua zf180824.2000 \n")
print("\n wifi_ap_start.lua zf200717.1610 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI mode AP only")
wifi.setmode(wifi.SOFTAP)
elseif zmodewifi == wifi.STATION then
print("WIFI mode AP+CLI")
wifi.setmode(wifi.STATIONAP)
end
wifi.ap.config({ ssid = "NodeMCU ".."btn "..wifi.ap.getmac(), pwd = "12345678" })
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ ssid = "btn_led", pwd = "12345678" })
dofile("wifi_info.lua")
--wifi.ap.config({ ssid = "NodeMCU ".."btn "..wifi.ap.getmac(), pwd = "12345678" })

View File

@@ -1,4 +0,0 @@
-- Petit script pour configurer le client WIFI du NodeMCU
print("\n wifi_cli_conf.lua zf200302.2300 \n")
wifi.sta.config{ssid="xxx", pwd="xxx", save=true}

View File

@@ -1,10 +0,0 @@
-- Démarre le WIFI en mode AP
print("\n wifi_cli_stop.lua zf180824.2000 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.STATION then
wifi.setmode(wifi.NULLMODE)
elseif zmodewifi == wifi.STATIONAP then
wifi.setmode(wifi.SOFTAP)
end
print("WIFI CLI arrêté")

View File

@@ -1,12 +0,0 @@
-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi
print("\n wifi_get_ip.lua zf200302.2258 \n")
wifitimer1=tmr.create()
wifitimer1:alarm(1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
wifitimer1:unregister()
dofile("wifi_info.lua")
end
end)

View File

@@ -1,16 +0,0 @@
a=0.5
b=3
print(a*b)
print(a+b)
c=a*b
print("la valeur de c est: ",c)
gpio.mode(0,gpio.OUTPUT)
if c>=3 then
gpio.write(0,0)
else
gpio.write(0,1)
end

View File

@@ -1,24 +0,0 @@
-- Programme qui allume la led bleue quand on appuie le bouton flash
-- zf181011.1749
print("\n btn_led.lua zf200302.2356 \n")
zledbleue=0 --led bleue
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
function zbtn()
if gpio.read(zswitch)==0 then
zled_state="ON"
gpio.write(zledbleue, gpio.LOW)
else
zled_state="OFF"
gpio.write(zledbleue, gpio.HIGH)
end
print("btn_led: "..zled_state)
--disp_send()
end
gpio.trig(zswitch, "both", zbtn)

View File

@@ -1,16 +0,0 @@
-- Scripts à charger au moment du boot
print("\n a_start_boot.lua zf200302.2315 \n")
dofile("wifi_ap_stop.lua")
dofile("wifi_cli_conf.lua")
dofile("wifi_cli_start.lua")
dofile("led_job.lua")
dofile("web_srv.lua")
dofile("flash_led_xfois.lua")

View File

@@ -1,12 +1,11 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
print("\n flash_led_xfois.lua zf200302.2316 \n")
print("\n flash_led_xfois.lua zf200717.1748 \n")
zLED=0
zLED=4
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
function blink_LED ()
@@ -14,7 +13,7 @@ function blink_LED ()
print(nbfois)
nbfois = 0
else
if gpio.read(zLED)==gpio.HIGH then
if gpio.read(zLED) == gpio.HIGH then
gpio.write(zLED, gpio.LOW)
ztmr_LED:alarm(zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else

View File

@@ -1,43 +0,0 @@
-- a simple telnet server
print("\ntelnet_srv.lua zf180906.0904 \n")
-- restart server if needed
if telnet_srv ~= nil then
telnet_srv:close()
end
telnet_srv = net.createServer(net.TCP, 180)
telnet_srv:listen(23, function(socket)
local fifo = {}
local fifo_drained = true
local function sender(c)
if #fifo > 0 then
c:send(table.remove(fifo, 1))
else
fifo_drained = true
end
end
local function s_output(str)
table.insert(fifo, str)
if socket ~= nil and fifo_drained then
fifo_drained = false
sender(socket)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
socket:on("receive", function(c, l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
socket:on("disconnection", function(c)
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
socket:on("sent", sender)
print("Welcome to NodeMCU world.")
end)
print("Telnet server running...\nUsage: telnet -r ip\n")

View File

@@ -1,51 +0,0 @@
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
print("\n web_led_onoff.lua zf181018.1031 \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><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" .. _off .. ">OFF</option><option" .. _on .. ">ON</option></select></form></body></html>"
client:send(buf)
end)
conn:on("sent", function(c) c:close() end)
end)

View File

@@ -1,15 +0,0 @@
-- Petit script pour démarrer le mode configuration WIFI du NodeMCU
print("\n wifi_cnf_start.lua zf180906.1610 \n")
print("\nwifi config http://192.168.4.1\n")
--dofile("wifi_ap_stop.lua")
--dofile("wifi_cli_stop.lua")
srv:close()
telnet_srv:close()
--wificnftimer1=tmr.create()
--tmr.alarm(wificnftimer1, 3000, tmr.ALARM_SINGLE, function()
print("coucou")
enduser_setup.start()
--end)

View File

@@ -1,7 +1,7 @@
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
-- 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 zf200302.2255\n")
print("\n init.lua zf200717.1625\n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
@@ -10,14 +10,12 @@ initalarme=tmr.create()
function hvbouton()
gpio.trig(zswitch, "none")
initalarme:unregister()
dofile("a_start_boot.lua")
-- dofile("start_job.lua")
dofile("start_boot.lua")
end
gpio.trig(zswitch, "both", hvbouton)
initalarme:alarm(8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("a_start_boot.lua")
-- dofile("start_job.lua")
dofile("start_boot.lua")
end)

View File

@@ -1,10 +1,8 @@
--Petit script pour la gestion de la LED, juste pour comprendre la prog ;-)
print("\n led_job.lua zf181018.1616 \n")
print("\n led_job.lua zf200717.1746 \n")
zLED=0
gpio.mode(zLED, gpio.OUTPUT)
gpio.write(zLED, gpio.HIGH)
zLED=4 gpio.mode(zLED, gpio.OUTPUT) gpio.write(zLED, gpio.HIGH)
function led_on()
gpio.write(zLED, gpio.LOW)
@@ -16,6 +14,5 @@ function led_off()
fled="ON"
end
led_on()
led_off()
led_on() tmr.delay(10000) led_off()

View File

@@ -0,0 +1,15 @@
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf200717.1749 \n")
zLED=4 gpio.write(zLED, gpio.HIGH) gpio.mode(zLED,gpio.OUTPUT)
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
dofile("wifi_ap_start.lua")
dofile("led_job.lua")
dofile("web_srv.lua")
dofile("flash_led_xfois.lua")
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)

View File

@@ -9,6 +9,9 @@ function web_get()
elseif (_GET.led == "off") then
led_off()
html_home()
elseif (_GET.name == "zuzu") then
print("zuzu")
html_zuzu()
elseif (_GET.led == "flash") then
xfois=tonumber(_GET.fois)
blink_LED()

View File

@@ -1,28 +1,38 @@
-- petit script pour le HTML du serveur web
print("\n web_html.lua zf200302.2324 \n")
print("\n web_html.lua zf200717.1801 \n")
--Partie HTML et CSS pour la page web
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. 1608 </h1>\n"
buf = buf .. "<h1>Petit serveur WEB sur NodeMCU 1802 </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 .. "pour éteindre la LED, http://xxx/?led=status<br>\n"
buf = buf .. "pour flasher la LED 6x, http://xxx/?led=flash&fois=6<br>\n"
buf = buf .. "pour allumer la LED: <a href=\"http://192.168.4.1/?led=on\">http://192.168.4.1/?led=on</a><br>\n"
buf = buf .. "pour éteindre la LED: <a href=\"http://192.168.4.1/?led=off\">http://192.168.4.1/?led=off</a><br>\n"
buf = buf .. "pour éteindre la LED: <a href=\"http://192.168.4.1/?led=status\">http://192.168.4.1/?led=status</a><br>\n"
buf = buf .. "pour flasher la LED 6x: <a href=\"http://192.168.4.1/?led=flash&fois=6\">http://192.168.4.1/?led=flash&fois=6</a><br>\n"
buf = buf .. "hello zuzu: <a href=\"http://192.168.4.1/?name=zuzu&phrase=hello\">http://192.168.4.1/?name=zuzu&phrase=hello</a><br>\n"
buf = buf .. "</body></html>"
end
function html_status()
print("tutu")
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. 1608 </h1>\n"
buf = buf .. "Toto\n"
buf = buf .. "<h1>Hello, this is NodeMCU 1752 </h1>\n"
if gpio.read(zLED) == 1 then
buf = buf .. "<p>Led is off</p>\n"
else
buf = buf .. "<p>Led is on</p>\n"
end
buf = buf .. "<a href=\"../\">back...</a><br>\n"
buf = buf .. "</body></html>"
end
function html_zuzu()
print("c'est zuzu")
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 1800 </h1>\n"
buf = buf .. _GET.phrase.." zuzu<br>\n"
buf = buf .. "<br><a href=\"../\">back...</a><br>\n"
buf = buf .. "</body></html>"
end

View File

@@ -1,6 +1,6 @@
-- petit script de serveur WEB Wifi
-- petit script de serveur WEB plus évolué
print("\n web_srv.lua zf200302.2323 \n")
print("\n web_srv.lua zf200717.1735 \n")
dofile("web_get.lua")
dofile("web_html.lua")
@@ -31,6 +31,7 @@ srv:listen(80, function(conn)
web_get()
-- html_home()
--print("send html...")
client:send("HTTP/1.1 200 OK\r\n\r\n")
client:send(buf)
buf=nil
end

View File

@@ -0,0 +1,10 @@
-- Démarre le WIFI en mode AP
print("\n wifi_ap_start.lua zf200717.1728 \n")
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ ssid = "web_srv", pwd = "12345678" })
dofile("wifi_info.lua")
--wifi.ap.config({ ssid = "NodeMCU ".."btn "..wifi.ap.getmac(), pwd = "12345678" })

View File

@@ -1,10 +0,0 @@
-- Démarre le WIFI en mode AP
print("\n wifi_ap_stop.lua zf180824.2000 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.SOFTAP then
wifi.setmode(wifi.NULLMODE)
elseif zmodewifi == wifi.STATIONAP then
wifi.setmode(wifi.STATION)
end
print("WIFI AP arrêté")

View File

@@ -1,4 +0,0 @@
-- Petit script pour configurer le client WIFI du NodeMCU
print("\n wifi_cli_conf.lua zf200302.2300 \n")
wifi.sta.config{ssid="xxx", pwd="xxx", save=true}

View File

@@ -1,14 +0,0 @@
-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM
print("\n wifi_cli_start.lua zf180824.2000 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI mode CLI only")
wifi.setmode(wifi.STATION)
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP+CLI")
wifi.setmode(wifi.STATIONAP)
end
wifi.sta.autoconnect(1)
wifi.sta.connect()
dofile("wifi_get_ip.lua")

View File

@@ -1,12 +0,0 @@
-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi
print("\n wifi_get_ip.lua zf200302.2258 \n")
wifitimer1=tmr.create()
wifitimer1:alarm(1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
wifitimer1:unregister()
dofile("wifi_info.lua")
end
end)

View File

@@ -1,28 +1,45 @@
-- Petit script pour afficher les infos actuel du WIFI
print("\n wifi_info.lua zf180824.2000 \n")
print("\n wifi_info.lua zf200106.1803 \n")
local zmodewifi=wifi.getmode()
if zmodewifi == wifi.NULLMODE then
print("WIFI OFF")
elseif zmodewifi == wifi.STATION then
print("WIFI mode CLI")
print("Connected IP:\n",wifi.sta.getip())
do
function wifi_info()
local zmodewifi=wifi.getmode()
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
if zmodewifi == wifi.NULLMODE then
print("WIFI OFF")
elseif zmodewifi == wifi.STATION then
print("WIFI mode CLI")
print("Connected IP:\n",wifi.sta.getip())
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
end
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP")
print("AP MAC:\n\t"..wifi.ap.getmac())
print("AP IP:\n\t"..wifi.ap.getip())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP")
print("Connected IP:\n",wifi.sta.getip())
do
print("Current client config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid)
elseif zmodewifi == wifi.SOFTAP then
print("WIFI mode AP\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP\n")
print("CLIENT IP:\n",wifi.sta.getip())
local sta_config=wifi.sta.getconfig(true)
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
print("Current CLIENT config:")
print("\tssid:", sta_config.ssid)
print("\tpassword:", sta_config.pwd)
print("\tbssid:", sta_config.bssid.."\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
end
print("AP MAC: "..wifi.ap.getmac())
print("AP IP: "..wifi.ap.getip())
wifi_info=nil
end
wifi_info()