Essayé de déployer mon nouveau système sur un SonOff, pour l'instant cela fonctionne, mais il y a très peu de RAM :-(
This commit is contained in:
14
SonOff/SonOff_2/00test_cmd.lua
Normal file
14
SonOff/SonOff_2/00test_cmd.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
print("getpeer",srv_rt:getpeer())
|
||||
print("srv_rt",srv_rt)
|
||||
srv_rt=nil
|
||||
rt_connect=nil
|
||||
telnet_listener=nil
|
||||
package=nil
|
||||
d=nil
|
||||
require=nil
|
||||
pairs=nil
|
||||
ipairs=nil
|
||||
telnet_listener=nil
|
||||
|
||||
rt_retry=3
|
||||
rt_connect()
|
||||
27
SonOff/SonOff_2/0_btn_flipflop.lua
Normal file
27
SonOff/SonOff_2/0_btn_flipflop.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
-- Petit scripts pour faire un flip flop avec le bouton et la led du nodemcu
|
||||
-- Très intéressant la techno utilisée ici pour enlever les rebonds du micro switch
|
||||
-- dans la variable b se trouve l'heure à laquelle l'interruption est arrivée, il suffit juste alors de lui mettre un petit délai de 300mS
|
||||
|
||||
print("\n 0_btn_flipflop.lua zf200216.1457 \n")
|
||||
|
||||
gpio.write(zLED,1) gpio.mode(zLED,gpio.OUTPUT)
|
||||
gpio.mode(zBTN,gpio.INT)
|
||||
|
||||
d=tmr.now()
|
||||
|
||||
function zled (a,b,c)
|
||||
--print("a: "..a..",b: "..b..",c: "..c)
|
||||
if b-d > 300*1000 then
|
||||
if verbose then
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
verbose=false
|
||||
else
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(200000) gpio.write(zLED, gpio.HIGH)
|
||||
verbose=true
|
||||
end
|
||||
d=b
|
||||
print("verbose:",verbose)
|
||||
end
|
||||
end
|
||||
|
||||
gpio.trig(zBTN, "down", zled)
|
||||
24
SonOff/SonOff_2/0_cron.lua
Normal file
24
SonOff/SonOff_2/0_cron.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Petit script pour faire office de crontab pour les mesures
|
||||
print("\n 0_cron.lua zf200229.1557 \n")
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(60*1000, tmr.ALARM_AUTO, function()
|
||||
if verbose then print("cron1........................") end
|
||||
if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
|
||||
f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--[[
|
||||
f = "0_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
zurl = thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1)
|
||||
|
||||
f = "0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
ztemp1=nil zhum1=nil
|
||||
]]
|
||||
|
||||
if verbose then print(node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end)
|
||||
24
SonOff/SonOff_2/0_send_data.lua
Normal file
24
SonOff/SonOff_2/0_send_data.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Petit script pour envoyer les valeurs de température sur un serveur WEB via un HTTP GET
|
||||
|
||||
function send_data()
|
||||
if verbose then print("\n 0_send_data.lua zf200119.1518 \n") end
|
||||
|
||||
if verbose then print("send_data_web: ") end
|
||||
if verbose then print(zurl) end
|
||||
|
||||
http.get(zurl, nil, function(code, data)
|
||||
if (code < 0) then
|
||||
if verbose then print("HTTP request failed") end
|
||||
if verbose then print("zuzu", code, data) end
|
||||
else
|
||||
if verbose then print(code, data) end
|
||||
end
|
||||
zurl=nil
|
||||
end)
|
||||
zurl=nil send_data=nil
|
||||
if verbose then print(node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end
|
||||
|
||||
send_data()
|
||||
182
SonOff/SonOff_2/0_tst3_socat.lua
Normal file
182
SonOff/SonOff_2/0_tst3_socat.lua
Normal file
@@ -0,0 +1,182 @@
|
||||
--[[
|
||||
tests connection reverse telnet
|
||||
commande à faire tourner sur le serveur
|
||||
|
||||
1ere console
|
||||
pour une liaison directe:
|
||||
socat TCP-LISTEN:23047,fork,reuseaddr STDIO
|
||||
pour une console sur un port:
|
||||
socat TCP-LISTEN:23047,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1
|
||||
|
||||
2e console
|
||||
telnet -r localhost 23000
|
||||
]]
|
||||
|
||||
print("\n 0_tst3_socat.lua zf200229.2243 \n")
|
||||
|
||||
local node, table, tmr, uwrite, tostring =
|
||||
node, table, tmr, uart.write, tostring
|
||||
|
||||
local function telnet_listener(socket)
|
||||
local insert, remove, concat, heap, gc =
|
||||
table.insert, table.remove, table.concat, node.heap, collectgarbage
|
||||
local fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0
|
||||
local s -- s is a copy of the TCP socket if and only if sending is in progress
|
||||
local wdclr, cnt = tmr.wdclr, 0
|
||||
local function debug(fmt, ...)
|
||||
if (...) then fmt = fmt:format(...) end
|
||||
uwrite(0, "\r\nDBG: ",fmt,"\r\n" )
|
||||
cnt = cnt + 1
|
||||
if cnt % 10 then wdclr() end
|
||||
end
|
||||
|
||||
local function flushGarbage()
|
||||
if heap() < 13440 then gc() end
|
||||
end
|
||||
|
||||
local function sendLine()
|
||||
if not s then return end
|
||||
|
||||
if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s
|
||||
s = nil
|
||||
return
|
||||
end
|
||||
flushGarbage()
|
||||
if #fifo2 < 4 then -- Flush FIFO1 into FIFO2
|
||||
insert(fifo2,concat(fifo1))
|
||||
fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0
|
||||
end
|
||||
local rec = remove(fifo2,1) .. (remove(fifo2,1) or '') ..
|
||||
(remove(fifo2,1) or '') .. (remove(fifo2,1) or '')
|
||||
fifo2l = fifo2l - #rec
|
||||
flushGarbage()
|
||||
s:send(rec)
|
||||
end
|
||||
|
||||
local F1_SIZE = 256
|
||||
|
||||
local function queueLine(str)
|
||||
while #str > 0 do -- this is because str might be longer than the packet size!
|
||||
local k, l = F1_SIZE - fifo1l, #str
|
||||
local chunk
|
||||
if #fifo1 >= 32 or (k < l and k < 16) then
|
||||
insert(fifo2, concat(fifo1))
|
||||
fifo2l, fifo1, fifo1l, k = fifo2l + fifo1l, {}, 0, F1_SIZE
|
||||
end
|
||||
if l > k+16 then -- also tolerate a size overrun of 16 bytes to avoid a split
|
||||
chunk, str = str:sub(1,k), str:sub(k+1)
|
||||
else
|
||||
chunk, str = str, ''
|
||||
end
|
||||
insert(fifo1, chunk)
|
||||
fifo1l = fifo1l + #chunk
|
||||
end
|
||||
if not s and socket then
|
||||
s = socket
|
||||
sendLine()
|
||||
else
|
||||
flushGarbage()
|
||||
end
|
||||
end
|
||||
|
||||
local function receiveLine(s, line)
|
||||
node.input(line)
|
||||
end
|
||||
|
||||
local function disconnect(s)
|
||||
--fifo1, fifo1l, fifo2, fifo2l, s = {}, 0, {}, 0, nil
|
||||
fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, nil, nil
|
||||
--insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
|
||||
--wdclr, cnt = nil, nil
|
||||
node.output(nil)
|
||||
print("disconnected...")
|
||||
-- print("rt_retry:",rt_retry)
|
||||
-- rt_retry=rt_retry-1
|
||||
-- print("rt_retry:",rt_retry)
|
||||
-- if rt_retry>=0 then
|
||||
print("on ressaie en vitesse une fois ;-)")
|
||||
rt_connect()
|
||||
-- end
|
||||
end
|
||||
|
||||
--zzz
|
||||
local function zconnection(s)
|
||||
print("Welcome on ne devrait jamais passer par là to NodeMCU world.")
|
||||
end
|
||||
|
||||
socket:on("connection", zconnection)
|
||||
socket:on("receive", receiveLine)
|
||||
socket:on("disconnection", disconnect)
|
||||
socket:on("sent", sendLine)
|
||||
node.output(queueLine, 0)
|
||||
end
|
||||
|
||||
--net.createServer(net.TCP, 180):listen(23, telnet_listener)
|
||||
print("Revers telnet server running...\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function rt_connect()
|
||||
if verbose then
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
print("trying connect to "..console_host..":"..console_port)
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
srv_rt = nil srv_rt = net.createConnection(net.TCP, 0)
|
||||
srv_rt:on("connection", function(sck)
|
||||
if verbose then
|
||||
print("connected on "..console_host..":"..console_port)
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
telnet_listener(sck)
|
||||
print("Welcome to NodeMCU world.")
|
||||
end)
|
||||
srv_rt:connect(console_port,console_host)
|
||||
end
|
||||
|
||||
tmr_socat1=tmr.create()
|
||||
tmr_socat1:alarm(5*1000, tmr.ALARM_AUTO , function()
|
||||
rt_retry=1
|
||||
if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
|
||||
if srv_rt~=nil then
|
||||
if console_port == srv_rt:getpeer() then
|
||||
--cela tourne...
|
||||
if verbose then gpio.write(zLED, gpio.LOW) end
|
||||
else
|
||||
--on relance...
|
||||
rt_connect()
|
||||
end
|
||||
else
|
||||
--on relance...
|
||||
rt_connect()
|
||||
end
|
||||
end)
|
||||
|
||||
rt_retry=3
|
||||
rt_connect()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
tmr_socat1:unregister()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
print(srv_rt:getpeer())
|
||||
|
||||
srv_rt:connect(console_port,console_host)
|
||||
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
if console_port == srv_rt:getpeer() then
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
else
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
end
|
||||
|
||||
|
||||
]]
|
||||
33
SonOff/SonOff_2/0_zdyndns.lua
Normal file
33
SonOff/SonOff_2/0_zdyndns.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Petit script pour s'inregistrer sur zdyndns
|
||||
|
||||
function send_zdyndns()
|
||||
if verbose then print("\n 0_zdyndns.lua zf200229.1553 \n") end
|
||||
|
||||
zip = wifi.sta.getip()
|
||||
zdyndns_str = "s "..node_id..","..console_host..":"..tostring(console_port).." "..zip.."\n"
|
||||
if verbose then print("zdyndns_str: /"..zdyndns_str.."/") end
|
||||
|
||||
srv_zdyndns = net.createConnection(net.TCP, 0)
|
||||
|
||||
srv_zdyndns:on("receive", function(conn, pl)
|
||||
print("receiving...")
|
||||
print(pl)
|
||||
end)
|
||||
|
||||
srv_zdyndns:on("connection", function(sck)
|
||||
if verbose then print("connected & sending...") end
|
||||
sck:send(zdyndns_str, function(sk)
|
||||
sk:close()
|
||||
if verbose then print("close...") end
|
||||
zdyndns_str=nil zip=nil srv_zdyndns=nil send_zdyndns=nil
|
||||
if verbose then print(node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end)
|
||||
end)
|
||||
|
||||
srv_zdyndns:connect(zdyndns_port,zdyndns_host)
|
||||
|
||||
end
|
||||
|
||||
send_zdyndns()
|
||||
@@ -1,36 +1,16 @@
|
||||
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
|
||||
# zf200116.1833
|
||||
# zf200301.1318
|
||||
|
||||
Todo à faire pour ce projet !
|
||||
|
||||
- trouver un moyen pour configurer la lED dans initz.lua sans le rendre dangereux en cas de problème (éviter le reflashing en cas de reboot loop)
|
||||
- lancement ou arrêt du WEBIDE via la home page
|
||||
- refaire le fichier _secrets_project.lua_ à partir de secrets_project.lua
|
||||
- faire la documentation pour le fonctionnement de concept de rtelnet dans un fichier à part .md
|
||||
|
||||
- flip/flop du relais depuis la page api_sonoff
|
||||
- arrêter de demander de connecter le WIFI automatiquement en mode station juste après le boot dans la config wifiinit (automatic connect)
|
||||
- ajouter le contrôle flip/flop du btn sur RELAY
|
||||
- if verbose print partout dans *.lua
|
||||
- le wifi setup ne fonctionne toujours pas quand il y a déjà un ap de connecté (problème du reboot quand adrs ip ok)!
|
||||
|
||||
v- ajouter fonction restart dans z_index.html (ATTENTION avec un argument restart, pas besoin de faire une page restart.html !)
|
||||
v- ajouter l'affichage du node_id dans z_index.html
|
||||
v- ajouter le web_srv2 dans boot au lieu de boot2
|
||||
v- ajouter un état du RELAY et de la LED dans z_index.html
|
||||
v- ajouter une page affichage variables globales
|
||||
v- améliorer api_sonoff.html, il faut ajouter 'home' sur la page
|
||||
v- améliorer le résultat de api_sonoff.html, il faut sortir l'état des IO lors d'un changement comme confirmation
|
||||
v- copier secrets_project et secrets_wifi dans _secrets_project_ _secrets_wifi_ pour la documentation
|
||||
v- déplacer le mode AP dans wifi_init
|
||||
v- enlever la ligne wifi init dans z_index.html
|
||||
v- faire la page web service pour allumer la LED
|
||||
v- faire la page web service pour allumer le relay
|
||||
v- garder variable node_id pour identification après poweron général, reattribution adrs ip sur modem 4G
|
||||
v- passer à 10 secondes la seconde chance
|
||||
v- passer à 15x les tentatives de connexions au WIFI
|
||||
v- vérifier le fonctionnement d'allumer la LED, car ne marche plus !
|
||||
x- mettre ZLED2 et ZRELAY dans secrets_project
|
||||
x-ajouter argument ok dans wifi_init.html (sécurité)
|
||||
|
||||
|
||||
- y regarder pour faire tourner en MEME temps le reverse et le forward telnet
|
||||
- z lancement ou arrêt du WEBIDE via la home page
|
||||
|
||||
|
||||
|
||||
@@ -45,11 +25,11 @@ x-ajouter argument ok dans wifi_init.html (sécurité)
|
||||
# définitions à faire AVANT !
|
||||
export luatool_tty="/dev/cu.wchusbserial1410"
|
||||
|
||||
export zIP="192.168.0.182"
|
||||
export zIP="192.168.0.150"
|
||||
export zport="23"
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="2323"
|
||||
export zport="23000"
|
||||
ATTENTION: voir les tunnels tout à la fin !
|
||||
|
||||
|
||||
@@ -95,37 +75,58 @@ verbose=false
|
||||
zsort_rssi() zshow()
|
||||
|
||||
|
||||
#commandes luatool pour ce projet le .137 est à jour avec la nouvelle version du wifi !
|
||||
################################
|
||||
# commandes lua pour ce projet #
|
||||
################################
|
||||
ssh ubuntu@www.zuzutest.ml killall -9 socat
|
||||
sleep 1
|
||||
killall -9 ssh
|
||||
sleep 1
|
||||
ssh ubuntu@www.zuzutest.ml socat TCP-LISTEN:23001,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1 &
|
||||
watch -n 1 'ssh ubuntu@www.zuzutest.ml netstat -nat |grep 230'
|
||||
|
||||
######## envoyer un CTRL-C dans le terminal !
|
||||
|
||||
ssh -N -L 23000:localhost:23000 ubuntu@www.zuzutest.ml &
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="23000"
|
||||
telnet -rN $zIP $zport
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
~.
|
||||
zdyn
|
||||
|
||||
=node.heap()
|
||||
collectgarbage()
|
||||
=node.heap()
|
||||
|
||||
|
||||
dofile("dir.lua")
|
||||
dir()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
dofile("wifi_info.lua")
|
||||
|
||||
node.restart()
|
||||
|
||||
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
./luatool.py --ip $zIP:$zport -f wifi_init.lua
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f secrets_wifi.lua
|
||||
./luatool.py --ip $zIP:$zport -f initz.lua -t init.lua
|
||||
./luatool.py --ip $zIP:$zport -f boot.lua
|
||||
./luatool.py --ip $zIP:$zport -f boot2.lua
|
||||
./luatool.py --ip $zIP:$zport -f wifi_init.lua
|
||||
./luatool.py --ip $zIP:$zport -f set_time.lua
|
||||
./luatool.py --ip $zIP:$zport -f wifi_info.lua
|
||||
./luatool.py --ip $zIP:$zport -f c.lua
|
||||
./luatool.py --ip $zIP:$zport -f cat.lua
|
||||
./luatool.py --ip $zIP:$zport -f flash_led_xfois.lua
|
||||
./luatool.py --ip $zIP:$zport -f head.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_tst3_socat.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_cron.lua
|
||||
./luatool.py --ip $zIP:$zport -f secrets_project.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_zdyndns.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_btn_flipflop.lua
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f b.lua
|
||||
./luatool.py --ip $zIP:$zport -f web_srv2.lua
|
||||
./luatool.py --ip $zIP:$zport -f api_sonoff.html
|
||||
./luatool.py --ip $zIP:$zport -f z_index.html
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f wifi_get_conf.html
|
||||
./luatool.py --ip $zIP:$zport -f wifi_set_conf.html
|
||||
./luatool.py --ip $zIP:$zport -f initz.lua -t init.lua
|
||||
|
||||
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f z_page1.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page2.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page3.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page4.html
|
||||
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_ap_start.lua
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_cli_conf.lua
|
||||
@@ -183,7 +184,7 @@ for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
# faire un cat d'un fichier sur le NodeMCU
|
||||
dofile("cat.lua")
|
||||
cat("boot2.lua")
|
||||
cat("secrets_project.lua")
|
||||
|
||||
|
||||
# commandes luatool
|
||||
|
||||
@@ -8,26 +8,31 @@
|
||||
<title>API SonOff</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>API SonOff zf200112.1706</h1>
|
||||
<h1>API SonOff zf200118.1812</h1>
|
||||
<a href="/">Home...</a><br><br>
|
||||
<%
|
||||
if _GET.LED == "on" then
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
zout("LED=".._GET.LED.."<br>")
|
||||
zout('<a href="api_sonoff.html?LED=off"> Off</a><br>')
|
||||
|
||||
end
|
||||
if _GET.LED == "off" then
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
zout("LED=".._GET.LED.."<br>")
|
||||
zout('<a href="api_sonoff.html?LED=on"> On</a>')
|
||||
end
|
||||
%>
|
||||
<%
|
||||
if _GET.RELAY == "on" then
|
||||
gpio.mode(zRELAY, gpio.OUTPUT) gpio.write(zRELAY, gpio.HIGH)
|
||||
zout("RELAY=".._GET.RELAY.."<br>")
|
||||
zout('<a href="api_sonoff.html?RELAY=off"> Off</a><br>')
|
||||
end
|
||||
if _GET.RELAY == "off" then
|
||||
gpio.mode(zRELAY, gpio.OUTPUT) gpio.write(zRELAY, gpio.LOW)
|
||||
zout("RELAY=".._GET.RELAY.."<br>")
|
||||
zout('<a href="api_sonoff.html?RELAY=on"> On</a>')
|
||||
end
|
||||
%>
|
||||
</body>
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot.lua zf200108.1751 \n")
|
||||
print("\n boot.lua zf200229.2303 \n")
|
||||
|
||||
function boot()
|
||||
|
||||
print("booooooooooot...")
|
||||
verbose = true
|
||||
print("On lance le boot...")
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
--f= "0_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f="0_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
--zurl=thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1)
|
||||
--f="0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
|
||||
--f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f = "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
print("verbose:",verbose)
|
||||
print("boot lancé...")
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
f=nil boot=nil
|
||||
verbose = true
|
||||
|
||||
end
|
||||
boot()
|
||||
|
||||
23
SonOff/SonOff_2/disp_temp.html
Normal file
23
SonOff/SonOff_2/disp_temp.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>Affichage de la température et humidité</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Affichage de la température et humidité 200118.1800</h1>
|
||||
<a href="/">Home...</a><br>
|
||||
<%
|
||||
zout("<h1>"..node_id.." 200112.1919 </h1>")
|
||||
%>
|
||||
<br>
|
||||
<%
|
||||
zout("Température: "..readTemp().." °C<br>")
|
||||
zout("Humidité: "..readHumi().." %<br>")
|
||||
|
||||
zout("<br><br>RAM: "..node.heap().."<br>")
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,7 +3,7 @@
|
||||
-- le script repair.lua pendant xx secondes avant de continuer
|
||||
--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason
|
||||
|
||||
print("\n init.lua zf200110.1948 \n")
|
||||
print("\n init.lua zf200118.1507 \n")
|
||||
|
||||
function initz()
|
||||
|
||||
@@ -26,8 +26,8 @@ function initz()
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
--zLED=4 -- NodeMCU
|
||||
zLED=7 -- SonOff
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
initalarme1=tmr.create()
|
||||
initalarme1:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
|
||||
@@ -1,63 +1,74 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf200111.1219 \n")
|
||||
print("\n wifi_init.lua zf200229.2330 \n")
|
||||
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
function wifi_init_end()
|
||||
wifi_init1:unregister() i=nil
|
||||
tmr_wifi_init1:unregister() i=nil
|
||||
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
|
||||
f=nil secrets_wifi=nil cli_pwd=nil cli_ssid=nil
|
||||
wifi_init1=nil wifi_init=nil
|
||||
tmr_wifi_init1=nil wifi_init=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
-- f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
zdelay=1 if reset_reason=="seconde_chance" then zdelay=20 end
|
||||
wifi_init3=tmr.create()
|
||||
wifi_init3:alarm(zdelay*1000, tmr.ALARM_SINGLE, function()
|
||||
tmr_wifi_init3=tmr.create()
|
||||
tmr_wifi_init3:alarm(zdelay*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
wifi_init3:unregister() wifi_init3=nil wifi_init_end=nil
|
||||
tmr_wifi_init3:unregister() tmr_wifi_init3=nil wifi_init_end=nil
|
||||
reset_reason=nil zdelay=nil
|
||||
end)
|
||||
end
|
||||
|
||||
if file.exists("_setup_wifi_") then
|
||||
file.remove("_setup_wifi_")
|
||||
print("setup wifi...")
|
||||
file.remove("_setup_wifi_")
|
||||
wifi.sta.config{ssid="", pwd=""} wifi.sta.connect()
|
||||
if zLED == nil then zLED = 4 end
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
tmr_wifi_init4=tmr.create()
|
||||
tmr_wifi_init4:alarm(0.1*1000, tmr.ALARM_AUTO , function()
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
end)
|
||||
tmr.create():alarm(90*1000, tmr.ALARM_SINGLE, function()
|
||||
node.restart()
|
||||
end)
|
||||
enduser_setup.start(function()
|
||||
print("on est sortit du setup wifi et on restart !")
|
||||
node.restart()
|
||||
end)
|
||||
print("setup wifi out...")
|
||||
print("setup gadget lancé...")
|
||||
else
|
||||
-- charge les secrets pour le wifi
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true}
|
||||
wifi.sta.autoconnect(1) wifi.sta.connect()
|
||||
if node_id == nil then node_id = "generic" end
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd} wifi.sta.connect()
|
||||
if node_id == nil then node_id = "generic" ap_pwd = "12345678" end
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
wifi_init2=tmr.create()
|
||||
wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
tmr_wifi_init2=tmr.create()
|
||||
tmr_wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) wifi_init2=nil
|
||||
wifi.setmode(wifi.STATION,true) tmr_wifi_init2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT) i=1
|
||||
wifi_init1=tmr.create()
|
||||
wifi_init1:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
tmr_wifi_init1=tmr.create()
|
||||
tmr_wifi_init1:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
print(i,"Connecting to AP...")
|
||||
i=i+1
|
||||
if i > 15 then
|
||||
if i > 30 then
|
||||
print("pas de wifi :-(")
|
||||
wifi_init2:unregister() wifi_init2=nil
|
||||
wifi.setmode(wifi.SOFTAP,true)
|
||||
wifi_init_end()
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
print("on restart pour le setup wifi")
|
||||
node.restart()
|
||||
--tmr_wifi_init2:unregister() tmr_wifi_init2=nil
|
||||
--wifi.setmode(wifi.SOFTAP,true)
|
||||
--wifi_init_end()
|
||||
end
|
||||
else
|
||||
wifi_init_end()
|
||||
@@ -69,6 +80,6 @@ end
|
||||
wifi_init()
|
||||
|
||||
--[[
|
||||
file.putcontents("_setup_wifi_", "")
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
file.remove("eus_params.lua")
|
||||
]]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user