From 881e50b25a31aa135d4f961750844653a6c6eac3 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sat, 3 Aug 2019 21:39:20 +0200 Subject: [PATCH] =?UTF-8?q?Commencer=20=C3=A0=20=C3=A9crire=20le=20test=20?= =?UTF-8?q?de=20la=20d=C3=A9tection=20de=20la=20led=20du=20compteur=20?= =?UTF-8?q?=C3=A9lectrique.=20Il=20ne=20fait=20que=20seulement=20allumer?= =?UTF-8?q?=20la=20petite=20LED=20du=20NodeMCU=20quand=20il=20'voit'=20la?= =?UTF-8?q?=20LED=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mesures/energy/0_get_energy.lua | 42 +++++++++++++++------------------ Mesures/energy/boot.lua | 8 +++---- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Mesures/energy/0_get_energy.lua b/Mesures/energy/0_get_energy.lua index 2fcea1a..fba1b5f 100644 --- a/Mesures/energy/0_get_energy.lua +++ b/Mesures/energy/0_get_energy.lua @@ -1,34 +1,30 @@ --- Lit le capteur de température solaire en fonction de son field qui se trouve dans les secrets ! -print("\n 0_get_temp.lua zf190728.1014 \n") +-- Lit le capteur LDR pour mesurer la consommation électrique du compteur de la maison +print("\n 0_get_energy.lua zf190803.2138 \n") -- lecture: https://thingspeak.com/channels/802784/private_show --- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/ -local ow_pin = 3 -ds18b20.setup(ow_pin) +local ldr_pin = 2 -- pin de la LDR +local zledbleue=0 --led bleue -function get_temp() - ds18b20.read( - function(ind,rom,res,temp,tdec,par) - print(ind, temp, zfield) - if zfield == 1 then - ztemp1 = temp - zurl=hub_url.."field1="..tostring(ztemp1) - send_temp() - elseif zfield == 2 then - ztemp2 = temp - elseif zfield == 3 then - ztemp3 = temp - zurl=hub_url.."field3="..tostring(ztemp3) - send_temp() - end - print(ztemp1, ztemp2, ztemp3) - end,{}) +gpio.mode(ldr_pin, gpio.INT, gpio.FLOAT) + +function get_energy() + if gpio.read(ldr_pin)==0 then + zled_state="OFF" + gpio.write(zledbleue, gpio.HIGH) + else + zled_state="ON" + gpio.write(zledbleue, gpio.LOW) + end + print("btn_led: "..zled_state) +-- disp_send() end +gpio.trig(ldr_pin, "both", get_energy) + --[[ -get_temp() +get_energy() ]] diff --git a/Mesures/energy/boot.lua b/Mesures/energy/boot.lua index d432a99..e1ae4ed 100644 --- a/Mesures/energy/boot.lua +++ b/Mesures/energy/boot.lua @@ -1,6 +1,6 @@ -- Scripts à charger après le boot pour démarrer son appli -print("\n boot.lua zf190803.1908 \n") +print("\n boot.lua zf190803.2137 \n") function heartbeat() f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end @@ -24,13 +24,13 @@ 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= "web_srv2.lua" if file.exists(f) then dofile(f) end ---f= "0_get_temp.lua" if file.exists(f) then dofile(f) end +f= "0_get_energy.lua" if file.exists(f) then dofile(f) end --f= "0_send_temp.lua" if file.exists(f) then dofile(f) end --f= "0_cron_temp.lua" if file.exists(f) then dofile(f) end f=nil ---heartbeat=nil -heartbeat() +heartbeat=nil +--heartbeat()