Super bien avancé sur mon tracker WPS
* complètement changé le telnet serveur, pris la nouvelle version sur NodeMCU. Ne plante plus maintenant * commencé à tester l'écoute des AP WIFI qui sont dans le parage du NodeMCU * règle l'horloge RTC via SNMP * amélioré le mode dsleep afin de ne pas perdre l'horloge RTC
This commit is contained in:
40
DeepSleep/ESP-M3/a.lua
Normal file
40
DeepSleep/ESP-M3/a.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- Scripts pour tester l'écoute des AP WIFI
|
||||
|
||||
print("\n a.lua zf181211.0016 \n")
|
||||
|
||||
--f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
-- print AP list in new format
|
||||
function a()
|
||||
ztime()
|
||||
function listap(t)
|
||||
print("")
|
||||
for k,v in pairs(t) do
|
||||
print(k.." : "..v)
|
||||
end
|
||||
print("")
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
end
|
||||
|
||||
--a()
|
||||
|
||||
--[[
|
||||
-- Print AP list that is easier to read
|
||||
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
|
||||
print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
|
||||
for bssid,v in pairs(t) do
|
||||
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
|
||||
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
|
||||
|
||||
]]
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot.lua zf181208.1752 \n")
|
||||
print("\n boot.lua zf181211.0005 \n")
|
||||
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -14,9 +14,13 @@ end
|
||||
f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
f= "a.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
a()
|
||||
|
||||
--heartbeat()
|
||||
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
|
||||
-- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k !
|
||||
|
||||
print("\n dsleep.lua zf181209.1457 \n")
|
||||
print("\n dsleep.lua zf181211.0018 \n")
|
||||
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
function dsleep_on()
|
||||
print("timer dsleep on...")
|
||||
ztmr_SLEEP = tmr.create()
|
||||
tmr.alarm(ztmr_SLEEP, 5*1000, tmr.ALARM_SINGLE, function ()
|
||||
tmr.alarm(ztmr_SLEEP, 10*1000, tmr.ALARM_SINGLE, function ()
|
||||
print("Je dors...")
|
||||
node.dsleep(30*1000*1000)
|
||||
tmr.delay(100*1000)
|
||||
-- node.dsleep(4*1000*1000)
|
||||
rtctime.dsleep(30*1000*1000)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -54,11 +56,9 @@ function watch_wifi_off()
|
||||
end)
|
||||
end
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason: ",reset_reason)
|
||||
if reset_reason == 4 then print("Coucou, soft reset...") end
|
||||
if reset_reason == 5 then print("Coucou, je suis réveillé...") end
|
||||
if reset_reason == 6 then print("Coucou, hard reset...") end
|
||||
print("Coucou, je suis réveillé...")
|
||||
print("Et il est: ")
|
||||
ztime()
|
||||
|
||||
watch_wifi_on()
|
||||
|
||||
|
||||
@@ -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 zf181208.1756 \n")
|
||||
print("\n init.lua zf181210.2358 \n")
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
@@ -26,9 +26,10 @@ elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 6 then
|
||||
print("reset")
|
||||
second_chance()
|
||||
print("external reset")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Scripts de seconde chance pour réparer une boucle dans le restart
|
||||
|
||||
print("\n repair.lua zf181119.2356 \n")
|
||||
print("\n repair.lua zf181210.1456 \n")
|
||||
|
||||
--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f= "az_init_led.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "az_init_led.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
--[[
|
||||
@@ -13,4 +13,4 @@ jobtimer1=tmr.create()
|
||||
tmr.alarm(jobtimer1, 5*1000, tmr.ALARM_AUTO, function()
|
||||
print("repair...")
|
||||
end)
|
||||
]]
|
||||
]]
|
||||
|
||||
24
DeepSleep/ESP-M3/set_time.lua
Normal file
24
DeepSleep/ESP-M3/set_time.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Scripts pour régler l'horloge quand on est connecté en WIFI
|
||||
|
||||
print("\n set_time.lua zf181211.0010 \n")
|
||||
|
||||
--f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
|
||||
function set_time()
|
||||
sntp.sync(nil, nil, nil, 1)
|
||||
end
|
||||
|
||||
function ztime()
|
||||
tm = rtctime.epoch2cal(rtctime.get())
|
||||
print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
end
|
||||
|
||||
set_time()
|
||||
|
||||
88
DeepSleep/ESP-M3/telnet_srv2.lua
Normal file
88
DeepSleep/ESP-M3/telnet_srv2.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
-- Serveur telnet pour connexion en remote WIFI, NOUVELLE VERSION !
|
||||
-- source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/telnet/telnet.lua
|
||||
|
||||
print("\n telnet_srv2.lua zf181210.1625 \n")
|
||||
|
||||
local node, table, tmr, wifi, uwrite, tostring =
|
||||
node, table, tmr, wifi, 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
|
||||
node.output(nil)
|
||||
end
|
||||
|
||||
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("Telnet server running...\nUsage: telnet -r ip\n")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Petit WEB IDE tout simple autonome
|
||||
-- ATTENTION: tourne sur le port 88 !
|
||||
|
||||
print("\n _web_ide2.lua zf181208.1902 \n")
|
||||
print("\n _web_ide2.lua zf181210.1516 \n")
|
||||
|
||||
--[[
|
||||
XChip's NodeMCU IDE
|
||||
@@ -113,8 +113,9 @@ srv:listen(88,function(conn)
|
||||
if vars=="edit" then
|
||||
conn:send("<script>function tag(c){document.getElementsByTagName('w')[0].innerHTML=c};\n")
|
||||
conn:send("var x=new XMLHttpRequest()\nx.onreadystatechange=function(){if(x.readyState==4) document.getElementsByName('t')[0].value = x.responseText; };\nx.open('GET',location.pathname,true)\nx.send()</script>")
|
||||
conn:send("<a href='/'>Back to file list</a><br><br><textarea name=t cols=120 rows=50></textarea></br>")
|
||||
conn:send("<button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")
|
||||
conn:send("<h2><a href='/'>Back to file list</a>\n")
|
||||
conn:send("<br><br><button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")
|
||||
conn:send("</h2><br><textarea name=t cols=110 rows=50></textarea></br>")
|
||||
end
|
||||
|
||||
if vars=="run" then
|
||||
|
||||
BIN
Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.bin
Normal file
BIN
Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.bin
Normal file
Binary file not shown.
BIN
Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.pdf
Normal file
BIN
Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user