wip
This commit is contained in:
@@ -1,41 +1,56 @@
|
||||
-- Lit le capteur LDR pour mesurer la consommation électrique du compteur de la maison
|
||||
print("\n 0_get_energy.lua zf190807.0923 \n")
|
||||
-- Lit le convertisseur ADC pour mesurer le courant électrique de l'installation PV
|
||||
print("\n 0_get_energy.lua zf190909.0007 \n")
|
||||
|
||||
-- lecture: https://thingspeak.com/channels/802784/private_show
|
||||
-- Astuce de mesure, on lit l'adc toutes les 21ms, soit 47.6x par seconde
|
||||
-- comme l'alternance fait 20ms, on balaye (déphasage) statistiquement l'aleternance
|
||||
-- ce qui nous permet d'estimer une valeur moyenne du courant
|
||||
-- quelque soit sa forme !
|
||||
-- toutes les secondes on remet à zéro les minima et maxima
|
||||
|
||||
local ldr_pin = 2 -- pin de la LDR
|
||||
local zledbleue=0 --led bleue
|
||||
zadc_min=1024 zadc_max=0
|
||||
|
||||
gpio.mode(ldr_pin, gpio.INT, gpio.FLOAT)
|
||||
|
||||
zt1_energy = tmr.now()
|
||||
zt2_energy = tmr.now()
|
||||
|
||||
function get_energy()
|
||||
if gpio.read(ldr_pin)==0 then
|
||||
zled_state="OFF"
|
||||
gpio.write(zledbleue, gpio.HIGH)
|
||||
zt1_energy = tmr.now()
|
||||
else
|
||||
zled_state="ON"
|
||||
gpio.write(zledbleue, gpio.LOW)
|
||||
zt2_energy = tmr.now()
|
||||
zt_energy = (zt2_energy-zt1_energy)/1000000
|
||||
if zt_energy >= 0.3 and zt_energy <= 100 then
|
||||
print("Durée ".. zt_energy)
|
||||
zpuissance = math.floor(3600/zt_energy)/1000
|
||||
print("Puissance ".. zpuissance.."kW")
|
||||
send_temp()
|
||||
end
|
||||
end
|
||||
print("btn_led: "..zled_state)
|
||||
if adc.force_init_mode(adc.INIT_ADC)
|
||||
then
|
||||
node.restart()
|
||||
return -- don't bother continuing, the restart is scheduled
|
||||
end
|
||||
|
||||
tmr_clr_rms=tmr.create()
|
||||
tmr_clr_rms:alarm(2*1000, tmr.ALARM_AUTO, function()
|
||||
clr_rms()
|
||||
end)
|
||||
|
||||
tmr_mes_adc=tmr.create()
|
||||
tmr_mes_adc:alarm(0.017*1000, tmr.ALARM_AUTO, function()
|
||||
get_adc()
|
||||
end)
|
||||
|
||||
function get_adc()
|
||||
zadc=0 znb=3
|
||||
for i=1,znb do zadc=zadc+adc.read(0) end
|
||||
zadc=math.floor(zadc/znb)
|
||||
if zadc<=zadc_min then zadc_min=zadc end
|
||||
if zadc>=zadc_max then zadc_max=zadc end
|
||||
end
|
||||
|
||||
zrms_offset=10
|
||||
zpow_cal=411
|
||||
zadc_cal=337
|
||||
|
||||
function clr_rms()
|
||||
zadc_rms0=zadc_max-zadc_min
|
||||
zadc_rms=zadc_rms0-zrms_offset
|
||||
if zadc_rms<=0 then zadc_rms=0 end
|
||||
zpower=math.floor(zadc_rms*zpow_cal/zadc_cal)
|
||||
print(zadc,zadc_min,zadc_max,zadc_rms0,zadc_rms,zpower.."W")
|
||||
zadc_min=1024 zadc_max=0
|
||||
end
|
||||
|
||||
gpio.trig(ldr_pin, "both", get_energy)
|
||||
|
||||
--[[
|
||||
|
||||
get_energy()
|
||||
get_adc()
|
||||
|
||||
]]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot.lua zf190805.1042 \n")
|
||||
print("\n boot.lua zf190908.2249 \n")
|
||||
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -29,8 +29,8 @@ f= "web_srv2.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()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user