From 40ab0cde4b91b9b74e98602f1d4ba1923b56e288 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Mon, 6 Jan 2020 00:17:23 +0100 Subject: [PATCH] =?UTF-8?q?beuhh,=20ma=20superbe=20proc=C3=A9dure=20de=20c?= =?UTF-8?q?onfiguration=20automatique=20du=20wifi=20ne=20fonctionne=20plus?= =?UTF-8?q?=20:-(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SonOff/SonOff_2/_zremote_cmd.txt | 4 ++- SonOff/SonOff_2/a.lua | 52 ++++++++++++++++++++++++++++---- SonOff/SonOff_2/boot.lua | 8 +++-- SonOff/SonOff_2/wifi_init.lua | 21 ++++++++----- SonOff/SonOff_2/z_index.html | 47 +++++++++++++++++++++++++++-- 5 files changed, 112 insertions(+), 20 deletions(-) diff --git a/SonOff/SonOff_2/_zremote_cmd.txt b/SonOff/SonOff_2/_zremote_cmd.txt index 1707c98..e891005 100644 --- a/SonOff/SonOff_2/_zremote_cmd.txt +++ b/SonOff/SonOff_2/_zremote_cmd.txt @@ -1,5 +1,5 @@ # Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom -# zf200103.1217 +# zf200105.0016 Todo à faire pour ce projet ! @@ -7,6 +7,7 @@ Todo à faire pour ce projet ! - ajouter l'affichage du node_id dans z_index.html - ajouter argument ok dans wifi_init.html (sécurité) - ajouter le contrôle flip/flop du btn sur RELAY +- ajouter une page affichage variables globales - if verbose print partout dans 0_send_data.lua - 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 @@ -51,6 +52,7 @@ for k,v in pairs(_G) do print(k,v) end # commandes lua pour ce projet export zIP="192.168.0.156" +export zIP="192.168.4.1" export zport="23" ./luatool.py --ip $zIP:$zport -f z_index.html ./luatool.py --ip $zIP:$zport -f api_sonoff.html diff --git a/SonOff/SonOff_2/a.lua b/SonOff/SonOff_2/a.lua index 909c6ca..709aa75 100644 --- a/SonOff/SonOff_2/a.lua +++ b/SonOff/SonOff_2/a.lua @@ -1,9 +1,49 @@ -print('\\n-----') -local l = file.list() -table.sort(l) -for k,v in pairs(l) do print(k..', size:'..v)end -print('-----\\n') +print("a start... zf190105.2344") -zdir={};pfile = file.list();for k,v in pairs(pfile) do zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v end;table.sort(zdir);print('\n-----');for i=1, #zdir do print(zdir[i]) end;print('-----\n');zdir=nil;pfile=nil;k=nil;v=nil;i=nil +srv:close() +srv=nil + +wifi.setmode(wifi.NULLMODE,true) + +print("toto") +tmr.delay(1*1000*1000) +print("tutu") + +wifi.setmode(wifi.STATIONAP,true) + +wifi.sta.config{ssid="", pwd="", auto=true, save=true} +wifi.sta.autoconnect(1) wifi.sta.connect() +wifi.ap.config({ ssid = "toto", auth=wifi.OPEN, save=true }) + +wifi.setmode(wifi.STATION,true) + +--wifi.setmode(wifi.STATIONAP) +--wifi.ap.config({ssid="MyPersonalSSID", auth=wifi.OPEN}) +--enduser_setup.manual(true) + +--[[ +srv:close() +srv=nil + +wifi.setmode(wifi.NULLMODE,true) + +print("toto") +a1=tmr.create() +a1:alarm(10*1000, tmr.ALARM_SINGLE, function() + enduser_setup.start( + function() + print("Connected to WiFi as:" .. wifi.sta.getip()) + end, + function(err, str) + print("enduser_setup: Err #" .. err .. ": " .. str) + end, + print -- Lua print function can serve as the debug callback + ) + print(node.heap()) collectgarbage() print(node.heap()) + print("tutu") +end) + +]] + diff --git a/SonOff/SonOff_2/boot.lua b/SonOff/SonOff_2/boot.lua index ebcd739..a693d17 100644 --- a/SonOff/SonOff_2/boot.lua +++ b/SonOff/SonOff_2/boot.lua @@ -1,11 +1,13 @@ -- Scripts à charger après le boot pour démarrer le core system -print("\n boot.lua zf200101.1235 \n") +print("\n boot.lua zf200105.2358 \n") function boot() - gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil + if zswitch ~= nill then + gpio.trig(zswitch, "none") hvbouton=nil zswitch=nil reset_reason=nil + end + f= "wifi_init.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 - f= "wifi_init.lua" if file.exists(f) then dofile(f) end end boot() diff --git a/SonOff/SonOff_2/wifi_init.lua b/SonOff/SonOff_2/wifi_init.lua index 6b6b073..c4aa022 100644 --- a/SonOff/SonOff_2/wifi_init.lua +++ b/SonOff/SonOff_2/wifi_init.lua @@ -1,7 +1,7 @@ -- Petit script pour initaliser la couche WIFI function wifi_init() - print("\n wifi_init.lua zf200101.1302 \n") + print("\n wifi_init.lua zf200105.2355 \n") -- 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 @@ -16,7 +16,7 @@ function wifi_init() ap_ssid=nil ap_pwd=nil wifi_init2=tmr.create() - wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function() + wifi_init2:alarm(120*1000, tmr.ALARM_SINGLE, function() print("BOOOOUM, y'a plus de AP WIFI !") wifi.setmode(wifi.STATION,true) wifi_init2=nil print(node.heap()) collectgarbage() print(node.heap()) @@ -32,12 +32,19 @@ function wifi_init() if wifi.sta.getip() == nil then print("Connecting to AP...") i=i+1 - if i > 15 then + if i > 5 then i=nil wifi_init1:unregister() - print("booum!") - enduser_setup.start(function() - node.restart() - end) + print("pas glop :-(") + + wifi_init2:unregister() + wifi.setmode(wifi.SOFTAP,true) + + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + boot2_go = true + + --enduser_setup.start(function() + -- node.restart() + --end) end else wifi_init1:unregister() zLED=nil i=nil diff --git a/SonOff/SonOff_2/z_index.html b/SonOff/SonOff_2/z_index.html index f260143..2ebe2f6 100644 --- a/SonOff/SonOff_2/z_index.html +++ b/SonOff/SonOff_2/z_index.html @@ -5,7 +5,7 @@ SonOff home page -

SonOff home page 200103.1212

+

SonOff home page 200105.2228

Menu:

SonOff API LED On
@@ -17,6 +17,45 @@ Affichage des températures, affiche les températures mesurées

+ + +<% + if (vars ~= nil) then + zout("
vars: "..vars.."
") + for k, v in string.gmatch(vars, "(%w+)=(%w+%p+%w+)&*") do + _GET[k] = v + zout(k..": "..v.."
") + end + end + if (_GET.SetupWIFI == "true") then + + zout("setup wifi...") + print("toto") + --wifi.setmode(wifi.NULLMODE) + --enduser_setup.start(function() + -- node.restart() + --end) + + + + + end + if (_GET.RESTART == "true") then + + zout("oups restart...") + + end +%> + + + + + + + + + +
Etat de la LED: <% zLED=7 -- SonOff @@ -31,8 +70,10 @@

<% - a,b,c = wifi.sta.getip() - zout("IP: "..a.."     MASK: "..b.."     GATEWAY: "..c.."
") + if wifi.sta.getip() ~= nil then + a,b,c = wifi.sta.getip() + zout("IP: "..a.."     MASK: "..b.."     GATEWAY: "..c.."
") + end collectgarbage() zout("RAM: "..node.heap()) %>