- ajouté le workshop
This commit is contained in:
92
IR/ir_receive.lua
Normal file
92
IR/ir_receive.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
-- Script pour la gestion du récepteur IR à 38kHz (LED, infrared, infrarouge)
|
||||
-- permet la réception d'un code (4bits seulement) avec le protocole zIR, protocole de mon invention ;-)
|
||||
-- exprès pas standard afin de ne pas être parasité par les autres sources IR !
|
||||
|
||||
print("\n ir_receive.lua zf180918.1906 \n")
|
||||
|
||||
pin_hp = 8
|
||||
gpio.mode(pin_hp,gpio.OUTPUT)
|
||||
gpio.write(pin_hp,gpio.LOW)
|
||||
|
||||
pin_ir_receive = 7
|
||||
gpio.mode(pin_ir_receive, gpio.INT, gpio.PULLUP)
|
||||
|
||||
Mark_Coeff = 0.5
|
||||
-- en mS/uS
|
||||
Mark_Start = 3 *Mark_Coeff *1000
|
||||
Mark_Bit1 = 2 *Mark_Coeff *1000
|
||||
Mark_Bit0 = 1 *Mark_Coeff *1000
|
||||
Mark_Space = 0.5 *Mark_Coeff *1000
|
||||
|
||||
function detect_start_begin()
|
||||
t_start_begin = tmr.now()
|
||||
gpio.trig(pin_ir_receive,"up",detect_start_end)
|
||||
end
|
||||
|
||||
function detect_start_end()
|
||||
t_start_len = tmr.now()-t_start_begin
|
||||
if t_start_len >= Mark_Start*0.8 and t_start_len <= Mark_Start*1.2 then
|
||||
ir_code = 0 num_bit = 0
|
||||
print("stxfir")
|
||||
gpio.trig(pin_ir_receive,"down",detect_bit_begin)
|
||||
else
|
||||
gpio.trig(pin_ir_receive,"none")
|
||||
end
|
||||
end
|
||||
|
||||
function detect_bit_begin()
|
||||
t_bit_begin = tmr.now()
|
||||
gpio.trig(pin_ir_receive,"up",detect_bit_end)
|
||||
end
|
||||
|
||||
function detect_bitt_end()
|
||||
bit_ok = flase
|
||||
t_bit_len = tmr.now()-t_bit_begin
|
||||
if t_bit_len >= Mark_Bit1*0.8 and t_bit_len <= Mark_Bit1*1.2 then
|
||||
ir_code = ir_code+(1+num_bit)^2
|
||||
bit_ok = true
|
||||
elseif t_bit_len >= Mark_Bit0*0.8 and t_bit_len <= Mark_Bit0*1.2 then
|
||||
bit_ok = true
|
||||
end
|
||||
if bit_ok = true then
|
||||
if num_bit <= 3 then
|
||||
num_bit = num_bit+1
|
||||
gpio.trig(pin_ir_receive,"down",detect_bit_begin)
|
||||
else
|
||||
print("code reçu: "..ir_code)
|
||||
gpio.trig(pin_ir_receive,"down",detect_start_begin)
|
||||
end
|
||||
else
|
||||
ir_code = 200
|
||||
gpio.trig(pin_ir_receive,"none")
|
||||
print("code error")
|
||||
end
|
||||
end
|
||||
|
||||
gpio.trig(pin_ir_receive,"down",detect_start_begin)
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
i=1 j=i
|
||||
|
||||
function pulse_detected()
|
||||
-- gpio.write(pin_hp,gpio.HIGH)
|
||||
--tmr.delay(500)
|
||||
i=i+1
|
||||
-- gpio.write(pin_hp,gpio.LOW)
|
||||
end
|
||||
|
||||
|
||||
ir_receive_tmr1=tmr.create()
|
||||
tmr.alarm(ir_receive_tmr1, 500, tmr.ALARM_AUTO, function()
|
||||
if i~=j then
|
||||
gpio.write(pin_hp,gpio.HIGH)
|
||||
print(i)
|
||||
j=i
|
||||
gpio.write(pin_hp,gpio.LOW)
|
||||
end
|
||||
end)
|
||||
]]
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- Script pour la gestion de l'émetteur IR à 38kHz (LED, infrared, infrarouge)
|
||||
-- permet l'envoi d'un code avec le protocole zIR, protocole de mon invention ;-)
|
||||
-- permet l'envoi d'un code (4bits seulement) avec le protocole zIR, protocole de mon invention ;-)
|
||||
-- exprès pas standard afin de ne pas être parasité par les autres sources IR !
|
||||
-- ATTENTION, on utilise ici l'astuce du gpio.serout pour faire la pulse de 26uS (38kHz),
|
||||
-- car on n'arrive pas avec le gpio.write à faire une pulse plus courte que 400uS
|
||||
|
||||
print("\n ir_send.lua zf180916.1706 \n")
|
||||
print("\n ir_send.lua zf180918.1826 \n")
|
||||
|
||||
pin_ir_send = 7
|
||||
gpio.mode(pin_ir_send,gpio.OUTPUT)
|
||||
@@ -13,9 +13,9 @@ gpio.write(pin_ir_send,gpio.HIGH)
|
||||
Mark_Coeff = 0.5
|
||||
-- en mS/uS
|
||||
Mark_Start = 3 *Mark_Coeff *1000
|
||||
Mark_Bit1 = 1 *Mark_Coeff *1000
|
||||
Mark_Bit0 = 2 *Mark_Coeff *1000
|
||||
Mark_Space = 1 *Mark_Coeff *1000
|
||||
Mark_Bit1 = 2 *Mark_Coeff *1000
|
||||
Mark_Bit0 = 1 *Mark_Coeff *1000
|
||||
Mark_Space = 0.5 *Mark_Coeff *1000
|
||||
|
||||
-- envoi une série de pulses à 38kHz de durée zduration en uS
|
||||
function pulse_ir(zduration)
|
||||
|
||||
22
Workshop/181004/blink_led1.lua
Normal file
22
Workshop/181004/blink_led1.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- programme pour faire clignoter une LED avec un rapport on/off
|
||||
--zf20180717.1118
|
||||
|
||||
zLED=0
|
||||
zTm_On_LED = 500 --> en ms
|
||||
zTm_Off_LED = 500 --> en ms
|
||||
zFlag_LED = 0
|
||||
|
||||
function blink_LED ()
|
||||
if zFlag_LED==gpio.LOW then
|
||||
zFlag_LED=gpio.HIGH
|
||||
tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
|
||||
else
|
||||
zFlag_LED=gpio.LOW
|
||||
tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
|
||||
end
|
||||
gpio.write(zLED, zFlag_LED)
|
||||
end
|
||||
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
ztmr_LED = tmr.create()
|
||||
blink_LED ()
|
||||
14
Workshop/181004/blink_led_ko.lua
Normal file
14
Workshop/181004/blink_led_ko.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
-- 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
|
||||
|
||||
17
Workshop/181004/btn_led.lua
Normal file
17
Workshop/181004/btn_led.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Programme qui allume la led bleue quand on appuie le bouton flash
|
||||
-- hv180711.1125
|
||||
|
||||
zledbleue=0 --led bleue
|
||||
zswitch=3--switch flash
|
||||
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function bouton()
|
||||
if gpio.read(zswitch)==0 then
|
||||
gpio.write(zledbleue, gpio.LOW)
|
||||
else
|
||||
gpio.write(zledbleue, gpio.HIGH)
|
||||
end
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", bouton)
|
||||
17
Workshop/181004/cat.lua
Normal file
17
Workshop/181004/cat.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf180826.1109 \n")
|
||||
|
||||
function cat(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
zfilei = file.open(zfile, "r")
|
||||
i=1
|
||||
zline=file.readline()
|
||||
repeat
|
||||
print(i..": "..string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
until zline== nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
15
Workshop/181004/dir.lua
Normal file
15
Workshop/181004/dir.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- fonction dir() pour afficher les fichiers dans la flash
|
||||
print("\n dir.lua zf180826.1019 \n")
|
||||
|
||||
function dir()
|
||||
print("\n-------------------------------")
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
|
||||
end
|
||||
print("-------------------------------")
|
||||
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
|
||||
end
|
||||
|
||||
dir()
|
||||
22
Workshop/181004/init.lua
Normal file
22
Workshop/181004/init.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
--Programme qui démarre le robot en appuyant sur le bouton flash et le redémarre si le bouton flash est appuyer pendant 3 secondes
|
||||
|
||||
print("\n init.lua hv180906.1450\n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
initalarme=tmr.create()
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
tmr.unregister(initalarme)
|
||||
dofile("start_boot.lua")
|
||||
dofile("start_job.lua")
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
|
||||
print("\nStart\n")
|
||||
dofile("start_boot.lua")
|
||||
-- dofile("start_job.lua")
|
||||
end)
|
||||
12
Workshop/181004/rm_files.lua
Normal file
12
Workshop/181004/rm_files.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU
|
||||
|
||||
print("\n rm_files.lua zf180907.1511 \n")
|
||||
|
||||
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
file.remove(k)
|
||||
end
|
||||
print("-------------------------------")
|
||||
print("\nC'est tout effaced :-) \n")
|
||||
28
Workshop/181004/start_boot.lua
Normal file
28
Workshop/181004/start_boot.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
-- Scripts à charger au moment du boot afin de pouvoir travailler avec le robot à distance
|
||||
print("\n start_boot.lua zf180907.1440 \n")
|
||||
|
||||
dofile("disp_oled.lua")
|
||||
oled_line1="RESET"
|
||||
oled_line2=""
|
||||
oled_line3=""
|
||||
oled_line4=""
|
||||
oled_line5=""
|
||||
disp_oled()
|
||||
|
||||
oled_line1="Waiting..."
|
||||
oled_line2=""
|
||||
oled_line3=""
|
||||
oled_line4=""
|
||||
oled_line5=""
|
||||
disp_oled()
|
||||
|
||||
--dofile("wifi_cnf_start.lua")
|
||||
dofile("wifi_ap_stop.lua")
|
||||
dofile("wifi_cli_start.lua")
|
||||
dofile("web_srv.lua")
|
||||
dofile("telnet_srv.lua")
|
||||
|
||||
zpeed=50
|
||||
turn_on = 700
|
||||
zauto=false
|
||||
dofile("motor.lua")
|
||||
55
Workshop/181004/start_job.lua
Normal file
55
Workshop/181004/start_job.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
print("\n start_job.lua hv180907.1558 \n")
|
||||
|
||||
jobtimer1=tmr.create()
|
||||
jobtimer2=tmr.create()
|
||||
|
||||
oled_line1="Job Start..."
|
||||
oled_line2=""
|
||||
oled_line3=""
|
||||
oled_line4=""
|
||||
oled_line5=""
|
||||
disp_oled()
|
||||
|
||||
oled_line1="AUTO..."
|
||||
oled_line2=""
|
||||
oled_line3=""
|
||||
oled_line4=""
|
||||
oled_line5=""
|
||||
disp_oled()
|
||||
|
||||
zpeed=50
|
||||
turn_on = 700
|
||||
|
||||
function return_mesure()
|
||||
print(zlength)
|
||||
print("RAM: "..node.heap())
|
||||
|
||||
if zauto then
|
||||
if zlength < 0.20 then
|
||||
backward()
|
||||
tmr.alarm(jobtimer2, 200, tmr.ALARM_SINGLE, function()
|
||||
if math.random(1,2) == 1 then
|
||||
right()
|
||||
else
|
||||
left()
|
||||
end
|
||||
tmr.alarm(jobtimer2, turn_on, tmr.ALARM_SINGLE, forward)
|
||||
end)
|
||||
end
|
||||
tmr.alarm(jobtimer1, 300, tmr.ALARM_SINGLE, start_mesure)
|
||||
else
|
||||
if zmeter then
|
||||
oled_line1=zlength.." m"
|
||||
oled_line2=""
|
||||
oled_line3=""
|
||||
oled_line4="NodeMCU: "..wifi.ap.getmac()
|
||||
disp_oled()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
dofile("detector.lua")
|
||||
zauto=true
|
||||
tmr.alarm(jobtimer1, 300, tmr.ALARM_SINGLE, start_mesure)
|
||||
forward()
|
||||
|
||||
43
Workshop/181004/telnet_srv.lua
Normal file
43
Workshop/181004/telnet_srv.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
-- 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")
|
||||
4
Workshop/181004/thefirst.lua
Normal file
4
Workshop/181004/thefirst.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
a=3
|
||||
b=4
|
||||
c=a*b
|
||||
print(c)
|
||||
77
Workshop/181004/web_get.lua
Normal file
77
Workshop/181004/web_get.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
-- petit script pour la gestion du GET du serveur web
|
||||
|
||||
print("\n web_get.lua hv180907.1557 \n")
|
||||
|
||||
webtimer1=tmr.create()
|
||||
webtimer2=tmr.create()
|
||||
webtimer3=tmr.create()
|
||||
webtimer4=tmr.create()
|
||||
|
||||
function forward_stop()
|
||||
if zauto then
|
||||
tmr.alarm(webtimer3, turn_on, tmr.ALARM_SINGLE, forward)
|
||||
else
|
||||
tmr.alarm(webtimer3, turn_on, tmr.ALARM_SINGLE, stop)
|
||||
end
|
||||
end
|
||||
|
||||
--Réaction des boutons
|
||||
function web_get()
|
||||
if (_GET.pin == "L") then
|
||||
left()
|
||||
forward_stop()
|
||||
elseif (_GET.pin == "R") then
|
||||
right()
|
||||
forward_stop()
|
||||
elseif (_GET.pin == "F") then
|
||||
forward()
|
||||
elseif (_GET.pin == "B") then
|
||||
backward()
|
||||
elseif (_GET.pin == "S") then
|
||||
zauto=false
|
||||
stop()
|
||||
elseif (_GET.pin == "SL") then
|
||||
zpeed=50
|
||||
set_speed()
|
||||
elseif (_GET.pin == "SM") then
|
||||
zpeed=70
|
||||
set_speed()
|
||||
elseif (_GET.pin == "SF") then
|
||||
zpeed=100
|
||||
set_speed()
|
||||
elseif (_GET.pin == "A") then
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, function()
|
||||
stop()
|
||||
oled_line1="Auto..." oled_line2="" oled_line3="" oled_line4="" oled_line5=""
|
||||
disp_oled()
|
||||
zauto=true
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, start_mesure)
|
||||
end)
|
||||
elseif (_GET.pin == "ML") then
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, function()
|
||||
stop()
|
||||
oled_line1="Manuel..." oled_line2="" oled_line3="" oled_line4="" oled_line5=""
|
||||
disp_oled()
|
||||
zauto=false
|
||||
end)
|
||||
elseif (_GET.pin == "T1") then
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, function()
|
||||
dofile("start_job.lua")
|
||||
end)
|
||||
elseif (_GET.pin == "T2") then
|
||||
oled_line1="Restart..." oled_line2="" oled_line3="" oled_line4="" oled_line5=""
|
||||
disp_oled()
|
||||
zauto=false
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, node.restart)
|
||||
elseif (_GET.pin == "T3") then
|
||||
tmr.alarm(webtimer1, 500, tmr.ALARM_SINGLE, function()
|
||||
zauto=false
|
||||
zmeter=true
|
||||
stop()
|
||||
oled_line1="Meter..." oled_line2="" oled_line3="" oled_line4="" oled_line5=""
|
||||
disp_oled()
|
||||
tmr.alarm(webtimer2, 600, tmr.ALARM_AUTO, start_mesure)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
24
Workshop/181004/web_html.lua
Normal file
24
Workshop/181004/web_html.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- petit script pour le HTML du serveur web
|
||||
|
||||
print("\n web_html.lua hv180907.1542 \n")
|
||||
|
||||
--Partie HTML et CSS pour la page web
|
||||
function web_html()
|
||||
buf = "<!DOCTYPE html><html><body><meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>\n"
|
||||
buf = buf .. "<h1>Contrôler le robot : </h1>"
|
||||
buf = buf .. "<a href='?pin=F'><button id='bf'>F</button></a><br>\n"
|
||||
buf = buf .. "<a href='?pin=L'><button id='bl'>L</button></a><a href='?pin=S'><button id='bs'>S</button></a><a href='?pin=R'><button id='br'>R</button></a></br>\n"
|
||||
buf = buf .. "<a href='?pin=B'><button id='bb'>B</button></a>\n"
|
||||
buf = buf .. "<h1> Vitesse : </h1>\n"
|
||||
buf = buf .. "<a href='?pin=SL'><button id='bsl'>Low</button></a><a href='?pin=SM'><button id='bsm'>Mid</button></a><a href='?pin=SF'><button id='bsf'>Fast</button></a>\n"
|
||||
buf = buf .. "<h1> Robot : </h1>\n"
|
||||
buf = buf .. "<a href='?pin=A'><button id='ba'>A</button></a><a href='?pin=ML'><button id='bml'>ML</button></a>\n"
|
||||
buf = buf .. "<h1> Tests : </h1>\n"
|
||||
buf = buf .. "<a href='?pin=T1'><button id='bt1'>Start</button></a><a href='?pin=T2'><button id='bt2'>Reboot</button></a>"
|
||||
buf = buf .. "<a href='?pin=T3'><button id='bt3'>T3</button></a><a href='?pin=T4'><button id='bt4'>T4</button></a>\n"
|
||||
buf = buf .. "<style>\n"
|
||||
buf = buf .. "#bf, #bb, #bl, #br, #bs, #bsl, #bsm, #bsf, #ba, #bml, #bt1, #bt2, #bt3, #bt4{font-size:10px; position:relative; height:50px; width:50px;}\n"
|
||||
buf = buf .. "#bf, #bb {left:50px;}\n"
|
||||
buf = buf .. "h1 {font-size:15px;}\n"
|
||||
buf = buf .. "</style>\n"
|
||||
end
|
||||
39
Workshop/181004/web_srv.lua
Normal file
39
Workshop/181004/web_srv.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
-- petit script de serveur WEB Wifi
|
||||
|
||||
print("\n web_srv.lua hv180906.1455 \n")
|
||||
|
||||
dofile("web_get.lua")
|
||||
dofile("web_html.lua")
|
||||
|
||||
srv = net.createServer(net.TCP)
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
|
||||
--print("\n\nweb_srv")
|
||||
--print("method: ",method)
|
||||
--print("path: ",path)
|
||||
--print("request: ",request)
|
||||
--print("vars: ",vars)
|
||||
|
||||
if not string.find(request, "/favicon.ico") then
|
||||
--print("coucou")
|
||||
if (method == nil) then
|
||||
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
||||
end
|
||||
_GET = {}
|
||||
if (vars ~= nil) then
|
||||
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
|
||||
_GET[k] = v
|
||||
print(k..": "..v)
|
||||
end
|
||||
end
|
||||
web_get()
|
||||
web_html()
|
||||
--print("send html...")
|
||||
client:send(buf)
|
||||
buf=nil
|
||||
end
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
13
Workshop/181004/wifi_ap_start.lua
Normal file
13
Workshop/181004/wifi_ap_start.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Démarre le WIFI en mode AP
|
||||
print("\n wifi_ap_start.lua zf180824.2000 \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 "..wifi.ap.getmac(), pwd = "12345678" })
|
||||
dofile("wifi_info.lua")
|
||||
10
Workshop/181004/wifi_ap_stop.lua
Normal file
10
Workshop/181004/wifi_ap_stop.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
-- 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é")
|
||||
4
Workshop/181004/wifi_cli_conf.lua
Normal file
4
Workshop/181004/wifi_cli_conf.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Petit script pour configurer le client WIFI du NodeMCU
|
||||
print("\n wifi_cli_conf.lua zf180824.2000 \n")
|
||||
|
||||
wifi.sta.config{ssid="Hugo", pwd="tototutu", save=true}
|
||||
14
Workshop/181004/wifi_cli_start.lua
Normal file
14
Workshop/181004/wifi_cli_start.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
-- 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")
|
||||
10
Workshop/181004/wifi_cli_stop.lua
Normal file
10
Workshop/181004/wifi_cli_stop.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
-- 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é")
|
||||
15
Workshop/181004/wifi_cnf_start.lua
Normal file
15
Workshop/181004/wifi_cnf_start.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- 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)
|
||||
6
Workshop/181004/wifi_cnf_stop.lua
Normal file
6
Workshop/181004/wifi_cnf_stop.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
-- Petit script pour arrêter le mode configuration WIFI du NodeMCU
|
||||
print("\n wifi_cnf_stop.lua zf180824.2000 \n")
|
||||
|
||||
enduser_setup.stop()
|
||||
wifi.sta.autoconnect(1)
|
||||
wifi.sta.connect()-- Petit script pour arrêter le mode configuration WIFI du NodeMCU
|
||||
12
Workshop/181004/wifi_get_ip.lua
Normal file
12
Workshop/181004/wifi_get_ip.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi
|
||||
print("\n wifi_get_ip.lua zf180824.2000 \n")
|
||||
|
||||
wifitimer1=tmr.create()
|
||||
tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
else
|
||||
tmr.stop(wifitimer1)
|
||||
dofile("wifi_info.lua")
|
||||
end
|
||||
end)
|
||||
28
Workshop/181004/wifi_info.lua
Normal file
28
Workshop/181004/wifi_info.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf180824.2000 \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
|
||||
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
|
||||
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
|
||||
print("AP MAC: "..wifi.ap.getmac())
|
||||
print("AP IP: "..wifi.ap.getip())
|
||||
end
|
||||
4
Workshop/181004/wifi_off.lua
Normal file
4
Workshop/181004/wifi_off.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Déconnecte le WIFI
|
||||
print("\n wifi_off.lua zf180822.0959 \n")
|
||||
|
||||
wifi.setmode(wifi.NULLMODE)
|
||||
5
Workshop/181004/wifi_start.lua
Normal file
5
Workshop/181004/wifi_start.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Exemple de petit script pour démarrer le WIFI
|
||||
print("\n wifi_start.lua zf180824.2000 \n")
|
||||
|
||||
dofile("wifi_cli_start.lua")
|
||||
dofile("wifi_ap_start.lua")
|
||||
Reference in New Issue
Block a user