diff --git a/DeepSleep/ESP-M3/a.lua b/DeepSleep/ESP-M3/a.lua new file mode 100644 index 0000000..2e94a02 --- /dev/null +++ b/DeepSleep/ESP-M3/a.lua @@ -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) + + +]] diff --git a/DeepSleep/ESP-M3/boot.lua b/DeepSleep/ESP-M3/boot.lua index c37dad6..f122373 100644 --- a/DeepSleep/ESP-M3/boot.lua +++ b/DeepSleep/ESP-M3/boot.lua @@ -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() diff --git a/DeepSleep/ESP-M3/dsleep.lua b/DeepSleep/ESP-M3/dsleep.lua index 0353630..14453b3 100644 --- a/DeepSleep/ESP-M3/dsleep.lua +++ b/DeepSleep/ESP-M3/dsleep.lua @@ -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() diff --git a/DeepSleep/ESP-M3/initz.lua b/DeepSleep/ESP-M3/initz.lua index 292bfe1..356caa1 100644 --- a/DeepSleep/ESP-M3/initz.lua +++ b/DeepSleep/ESP-M3/initz.lua @@ -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 diff --git a/DeepSleep/ESP-M3/repair.lua b/DeepSleep/ESP-M3/repair.lua index 626b5e5..691c123 100644 --- a/DeepSleep/ESP-M3/repair.lua +++ b/DeepSleep/ESP-M3/repair.lua @@ -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) -]] \ No newline at end of file +]] diff --git a/DeepSleep/ESP-M3/set_time.lua b/DeepSleep/ESP-M3/set_time.lua new file mode 100644 index 0000000..f4f1bab --- /dev/null +++ b/DeepSleep/ESP-M3/set_time.lua @@ -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() + diff --git a/DeepSleep/ESP-M3/telnet_srv2.lua b/DeepSleep/ESP-M3/telnet_srv2.lua new file mode 100644 index 0000000..b126f2f --- /dev/null +++ b/DeepSleep/ESP-M3/telnet_srv2.lua @@ -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") + diff --git a/DeepSleep/ESP-M3/web_ide2.lua b/DeepSleep/ESP-M3/web_ide2.lua index fd2037b..16d00f2 100644 --- a/DeepSleep/ESP-M3/web_ide2.lua +++ b/DeepSleep/ESP-M3/web_ide2.lua @@ -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("") - conn:send("Back to file list


") - conn:send("run") + conn:send("

Back to file list\n") + conn:send("

run") + conn:send("



") end if vars=="run" then diff --git a/DeepSleep/ESP-M3/goodies/wifi_info.lua b/DeepSleep/ESP-M3/wifi_info.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_info.lua rename to DeepSleep/ESP-M3/wifi_info.lua diff --git a/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.bin b/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.bin new file mode 100644 index 0000000..a9d2cbb Binary files /dev/null and b/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.bin differ diff --git a/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.pdf b/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.pdf new file mode 100644 index 0000000..e11095c Binary files /dev/null and b/Firmware/nodemcu-master-19-modules-2018-12-10-22-19-49-float.pdf differ