Commencé la partie dsleep, mais cela ne marche pas encore :-(

This commit is contained in:
Christian Zufferey
2020-07-20 21:00:06 +02:00
parent 374e04bb61
commit 8b718295ac
4 changed files with 58 additions and 23 deletions

View File

@@ -3,14 +3,14 @@
-- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k ! -- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k !
print("\n dsleep.lua zf181211.0018 \n") print("\n dsleep.lua zf200720.2058 \n")
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
function dsleep_on() function dsleep_on()
print("timer dsleep on...") print("timer dsleep on...")
ztmr_SLEEP = tmr.create() ztmr_SLEEP = tmr.create()
tmr.alarm(ztmr_SLEEP, 10*1000, tmr.ALARM_SINGLE, function () ztmr_SLEEP:alarm(10*1000, tmr.ALARM_SINGLE, function ()
print("Je dors...") print("Je dors...")
tmr.delay(100*1000) tmr.delay(100*1000)
-- node.dsleep(4*1000*1000) -- node.dsleep(4*1000*1000)
@@ -20,17 +20,17 @@ end
function dsleep_off() function dsleep_off()
print("timer dsleep off...") print("timer dsleep off...")
tmr.unregister(ztmr_SLEEP) ztmr_SLEEP:unregister()
end end
function watch_wifi_on() function watch_wifi_on()
dsleep_on() dsleep_on()
ztmr_watch_wifi_on=tmr.create() ztmr_watch_wifi_on = tmr.create()
tmr.alarm(ztmr_watch_wifi_on, 1000, tmr.ALARM_AUTO , function() ztmr_watch_wifi_on:alarm(1*1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then if wifi.sta.getip() == nil then
-- print("Unconnected... (on)") -- print("Unconnected... (on)")
else else
tmr.stop(ztmr_watch_wifi_on) ztmr_watch_wifi_on:stop()
print("Connected... (on)") print("Connected... (on)")
-- f= "wifi_info.lua" if file.exists(f) then dofile(f) end -- f= "wifi_info.lua" if file.exists(f) then dofile(f) end
watch_wifi_off() watch_wifi_off()
@@ -40,17 +40,17 @@ end
function watch_wifi_off() function watch_wifi_off()
dsleep_off() dsleep_off()
tmr.unregister(ztmr_watch_wifi_on) ztmr_watch_wifi_on:unregister()
ztmr_watch_wifi_off=tmr.create() ztmr_watch_wifi_off = tmr.create()
tmr.alarm(ztmr_watch_wifi_off, 1000, tmr.ALARM_AUTO , function() ztmr_watch_wifi_off:alarm(1*1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then if wifi.sta.getip() == nil then
tmr.stop(ztmr_watch_wifi_off) ztmr_watch_wifi_off:stop()
print("Unconnected... (off)") print("Unconnected... (off)")
watch_wifi_on() watch_wifi_on()
tmr.unregister(ztmr_watch_wifi_off) ztmr_watch_wifi_off:unregister()
else else
-- print("Connected... (off)") -- print("Connected... (off)")
xfois =2 xfois = 2
blink_LED () blink_LED ()
end end
end) end)

View File

@@ -1,7 +1,7 @@
-- Scripts à charger après le boot pour démarrer son projet -- Scripts à charger après le boot pour démarrer son projet
function boot() function boot()
print("\n boot.lua zf200720.1828 \n") print("\n boot.lua zf200720.2055 \n")
print("On lance le boot...") print("On lance le boot...")
collectgarbage() print(node.heap()) collectgarbage() print(node.heap())
local f local f
@@ -13,6 +13,12 @@ function boot()
-- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason -- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason
-- http_post(influxdb_url,zarg_boot) -- http_post(influxdb_url,zarg_boot)
f = "set_time.lua" if file.exists(f) then dofile(f) end
print(node.heap()) collectgarbage() print(node.heap())
f = "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
print(node.heap()) collectgarbage() print(node.heap())
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end -- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
-- print(node.heap()) collectgarbage() print(node.heap()) -- print(node.heap()) collectgarbage() print(node.heap())

View File

@@ -0,0 +1,38 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
function flash_led_xfois()
print("\n flash_led_xfois.lua zf200720.2053 \n")
--zLED=0 --NodeMCU
-- zLED=4 --EPS-M3
zTm_On_LED = 50 --> en ms
zTm_Off_LED = 100 --> en ms
nbfois = 0
gpio.write(zLED, gpio.HIGH)
gpio.mode(zLED, gpio.OUTPUT)
ztmr_Flash_LED = tmr.create()
function blink_LED ()
if nbfois >= xfois then
-- print(nbfois)
nbfois = 0
else
if gpio.read(zLED)==gpio.HIGH then
gpio.write(zLED, gpio.LOW)
-- tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
ztmr_Flash_LED:alarm(zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
gpio.write(zLED, gpio.HIGH)
nbfois = nbfois+1
-- tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
ztmr_Flash_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
end
end
xfois =2
blink_LED ()
end
flash_led_xfois()

View File

@@ -1,15 +1,6 @@
-- Scripts pour régler l'horloge quand on est connecté en WIFI -- Scripts pour régler l'horloge quand on est connecté en WIFI
print("\n set_time.lua zf181212.0841 \n") print("\n set_time.lua zf200720.2055 \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() function set_time()
sntp.sync(nil, nil, nil, 1) sntp.sync(nil, nil, nil, 1)