diff --git a/DeepSleep/Pet_tracker_2/dsleep.lua b/DeepSleep/Pet_tracker_2/0_dsleep.lua similarity index 68% rename from DeepSleep/Pet_tracker_2/dsleep.lua rename to DeepSleep/Pet_tracker_2/0_dsleep.lua index 14453b3..42a6e84 100644 --- a/DeepSleep/Pet_tracker_2/dsleep.lua +++ b/DeepSleep/Pet_tracker_2/0_dsleep.lua @@ -3,14 +3,14 @@ -- 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 function dsleep_on() print("timer dsleep on...") 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...") tmr.delay(100*1000) -- node.dsleep(4*1000*1000) @@ -20,17 +20,17 @@ end function dsleep_off() print("timer dsleep off...") - tmr.unregister(ztmr_SLEEP) + ztmr_SLEEP:unregister() end function watch_wifi_on() dsleep_on() - ztmr_watch_wifi_on=tmr.create() - tmr.alarm(ztmr_watch_wifi_on, 1000, tmr.ALARM_AUTO , function() + ztmr_watch_wifi_on = tmr.create() + ztmr_watch_wifi_on:alarm(1*1000, tmr.ALARM_AUTO , function() if wifi.sta.getip() == nil then -- print("Unconnected... (on)") else - tmr.stop(ztmr_watch_wifi_on) + ztmr_watch_wifi_on:stop() print("Connected... (on)") -- f= "wifi_info.lua" if file.exists(f) then dofile(f) end watch_wifi_off() @@ -40,17 +40,17 @@ end function watch_wifi_off() dsleep_off() - tmr.unregister(ztmr_watch_wifi_on) - ztmr_watch_wifi_off=tmr.create() - tmr.alarm(ztmr_watch_wifi_off, 1000, tmr.ALARM_AUTO , function() + ztmr_watch_wifi_on:unregister() + ztmr_watch_wifi_off = tmr.create() + ztmr_watch_wifi_off:alarm(1*1000, tmr.ALARM_AUTO , function() if wifi.sta.getip() == nil then - tmr.stop(ztmr_watch_wifi_off) + ztmr_watch_wifi_off:stop() print("Unconnected... (off)") watch_wifi_on() - tmr.unregister(ztmr_watch_wifi_off) + ztmr_watch_wifi_off:unregister() else -- print("Connected... (off)") - xfois =2 + xfois = 2 blink_LED () end end) diff --git a/DeepSleep/Pet_tracker_2/boot.lua b/DeepSleep/Pet_tracker_2/boot.lua index f3f6149..76b520c 100644 --- a/DeepSleep/Pet_tracker_2/boot.lua +++ b/DeepSleep/Pet_tracker_2/boot.lua @@ -1,7 +1,7 @@ -- Scripts à charger après le boot pour démarrer son projet function boot() - print("\n boot.lua zf200720.1828 \n") + print("\n boot.lua zf200720.2055 \n") print("On lance le boot...") collectgarbage() print(node.heap()) local f @@ -13,6 +13,12 @@ function boot() -- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason -- 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 -- print(node.heap()) collectgarbage() print(node.heap()) diff --git a/DeepSleep/Pet_tracker_2/flash_led_xfois.lua b/DeepSleep/Pet_tracker_2/flash_led_xfois.lua new file mode 100644 index 0000000..8bf982b --- /dev/null +++ b/DeepSleep/Pet_tracker_2/flash_led_xfois.lua @@ -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() + diff --git a/DeepSleep/Pet_tracker_2/set_time.lua b/DeepSleep/Pet_tracker_2/set_time.lua index 88f1acb..26c3679 100644 --- a/DeepSleep/Pet_tracker_2/set_time.lua +++ b/DeepSleep/Pet_tracker_2/set_time.lua @@ -1,15 +1,6 @@ -- Scripts pour régler l'horloge quand on est connecté en WIFI -print("\n set_time.lua zf181212.0841 \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("\n set_time.lua zf200720.2055 \n") function set_time() sntp.sync(nil, nil, nil, 1)