Mon fifo http_post à l'air de fonctionner à la mano, me reste encore à le mettre en auto dans le crontab :-)
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
-- Petit script pour faire office de crontab pour les mesures
|
||||
print("\n 0_cron.lua zf200524.1224 \n")
|
||||
print("\n 0_cron.lua zf200524.1246 \n")
|
||||
|
||||
|
||||
function tprint(t)
|
||||
for key,value in pairs(t) do
|
||||
print(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
ztemp1=20 zhum1=40 ztemp2=20 zhum2=40
|
||||
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(5*1000, tmr.ALARM_AUTO, function()
|
||||
@@ -8,6 +18,22 @@ cron1:alarm(5*1000, tmr.ALARM_AUTO, function()
|
||||
|
||||
f = "0_1_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
f = "0_2_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
|
||||
http_post(influxdb_url,"energy,capteur=th1 humidity="..ztemp1)
|
||||
http_post(influxdb_url,"energy,capteur=th1 humidity="..zhum1)
|
||||
http_post(influxdb_url,"energy,capteur=th1 humidity="..ztemp2)
|
||||
http_post(influxdb_url,"energy,capteur=th1 humidity="..zhum2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
table.remove(t_zurl, 1) table.remove(t_zarg, 1)
|
||||
print("t_zurl:") tprint(t_zurl) print("t_zarg:") tprint(t_zarg)
|
||||
|
||||
|
||||
f = "0_send_data.lua" if file.exists(f) then dofile(f) end
|
||||
ztemp1=nil zhum1=nil ztemp2=nil zhum2=nil
|
||||
f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -20,4 +46,4 @@ end)
|
||||
--[[
|
||||
cron1:stop()
|
||||
cron1:start()
|
||||
]]
|
||||
]]
|
||||
|
||||
41
Mesures/humidity/solar-grafana/0_http_post.lua
Normal file
41
Mesures/humidity/solar-grafana/0_http_post.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- Petit script pour envoyer en // es valeurs sur un serveur WEB (InfluxDB)
|
||||
-- via un http POST à travers un FIFO
|
||||
|
||||
if verbose then print("\n 0_http_post.lua zf200524.1336 \n") end
|
||||
|
||||
t_zurl={} t_zarg={} f_zpost=false
|
||||
|
||||
function zpost()
|
||||
f_zpost=true zurl=t_zurl[1] zarg=t_zarg[1]
|
||||
if verbose then print("zurl: "..zurl) end if verbose then print("zarg: "..zarg) end
|
||||
|
||||
http.post(zurl, 'Content-Type: application/x-www-form-urlencoded\r\n', zarg, function(code, data)
|
||||
if (code < 0) then
|
||||
print("HTTP request failed")
|
||||
print("zuzu", code, data)
|
||||
else
|
||||
if verbose then print(code, data) end
|
||||
end
|
||||
|
||||
table.remove(t_zurl, 1) table.remove(t_zarg, 1)
|
||||
if t_zurl[1]==nil then
|
||||
f_zpost=false
|
||||
else
|
||||
zpost()
|
||||
end
|
||||
if verbose then print("End zpost:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function http_post(zurl,zarg)
|
||||
table.insert(t_zurl, zurl) table.insert(t_zarg, zarg)
|
||||
print("t_zurl:") tprint(t_zurl) print("t_zarg:") tprint(t_zarg)
|
||||
if f_zpost==false then zpost() end
|
||||
if verbose then print("End http_post:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end
|
||||
@@ -1,16 +1,18 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot.lua zf200523.1833 \n")
|
||||
print("\n boot.lua zf200524.1250 \n")
|
||||
|
||||
function boot()
|
||||
verbose = true
|
||||
print("On lance le boot...")
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
--f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
|
||||
f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
|
||||
f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
--f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
|
||||
--f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f = "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
print("verbose:",verbose)
|
||||
print("boot lancé...")
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
Reference in New Issue
Block a user