Configuré les bons secrets pour ce projet, mais la mesure de distance ne fonctionne pas encore

This commit is contained in:
Christian Zufferey
2020-06-24 19:25:18 +02:00
parent 904221563b
commit 657af220be
2 changed files with 30 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
-- Petit script pour faire office de crontab pour les mesures
print("\n 0_cron.lua zf200621.1936 \n")
print("\n 0_cron.lua zf200621.1922 \n")
cron1=tmr.create()
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
@@ -7,7 +7,7 @@ cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
-- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
rt_launch()
-- rt_launch()
-- http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1")
@@ -15,7 +15,15 @@ cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
-- http_post(influxdb_url,"energy,memory=cron1_"..yellow_id.." ram="..node.heap())
-- if yellow_id == 60 then http_post(influxdb_url,"energy,compteur=3 puissance="..zpower/1000) end
if yellow_id == 64 then http_post(influxdb_url,"energy,compteur=4 puissance="..zpower/1000) end
-- if yellow_id == 64 then http_post(influxdb_url,"energy,compteur=4 puissance="..zpower/1000) end
-- if yellow_id == 69 then http_post(influxdb_url,"bolo_ruru,capteur="..node_id.." hauteur="..zlength) end
-- http_post(influxdb_url,"energy,value=test2_"..yellow_id.." val=2")
-- http_post(influxdb_url,"energy,value=test3_"..yellow_id.." val=3")

View File

@@ -1,7 +1,7 @@
-- Mesure la distance avec le module ultra-son
print("\n ultra_son.lua zf181026.1355 \n")
print("\n 0_ultra_son.lua zf200624.1910 \n")
--Parametres pour le module ultra son
--Paramètres pour le module ultra son
local ztrig=5
gpio.mode(ztrig, gpio.OUTPUT)
local fast_write = gpio.write
@@ -18,37 +18,37 @@ local ultra_son_stop=0
--Function pour envoyer la pulse
function zmesure_pulse()
--t1=tmr.now()
-- fast_write(ztrig, 1)
-- fast_write(ztrig, 0)
--gpio.serout(ztrig,gpio.LOW,{1,10})
gpio.serout(ztrig,gpio.HIGH,{10,1})
--t2=tmr.now()
--print("durée: "..t2-t1-314)
--t1=tmr.now()
-- fast_write(ztrig, 1)
-- fast_write(ztrig, 0)
--gpio.serout(ztrig,gpio.LOW,{1,10})
gpio.serout(ztrig,gpio.HIGH,{10,1})
--t2=tmr.now()
--print("durée: "..t2-t1-314)
end
--Fonction pour mesurer la pulse
function zmesure()
--print("pin: "..gpio.read(zecho))
--print("pin: "..gpio.read(zecho))
if fast_read(zecho)==1 then
ultra_son_start=tmr.now()
else
ultra_son_stop=tmr.now()
print("Delta: "..ultra_son_stop-ultra_son_start)
-- zlength=math.floor(480*(ultra_son_stop-ultra_son_start)/2/10000)/100
print("Delta: "..ultra_son_stop-ultra_son_start)
-- zlength=math.floor(480*(ultra_son_stop-ultra_son_start)/2/10000)/100
zlength=480*(ultra_son_stop-ultra_son_start)/2/10000
-- if zlength>6 then zlength=0 end
-- if zlength>6 then zlength=0 end
disp_mesure()
end
end
gpio.trig(zecho,"both",zmesure)
-- à commenter après les tests de perf
function disp_mesure() print(zlength) end
tmr.alarm(detectortimer1, 1000, tmr.ALARM_AUTO, zmesure_pulse)
function disp_mesure() print("La distance est de "..zlength.."cm") end
tmr_mesure=tmr.create()
tmr_mesure:alarm(1*1000, tmr.ALARM_AUTO, zmesure_pulse)