Commencer à écrire le test de la détection de la led du compteur électrique. Il ne fait que seulement allumer la petite LED du NodeMCU quand il 'voit' la LED :-)

This commit is contained in:
Christian Zufferey
2019-08-03 21:39:20 +02:00
parent 7cb3c0654a
commit 881e50b25a
2 changed files with 23 additions and 27 deletions

View File

@@ -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()
]]

View File

@@ -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()