From f3ebbb4f152f868ebdc4811a698aa25f992cf0ab Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sat, 23 May 2020 16:56:29 +0200 Subject: [PATCH] =?UTF-8?q?Cela=20va=20mieux,=20mais=20=C3=A7a=20n'envoie?= =?UTF-8?q?=20pas=20automatiquement=20vie=20le=20crontab=20:-(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mesures/humidity/solar-grafana/0_1_htu21d.lua | 4 +- Mesures/humidity/solar-grafana/0_2_htu21d.lua | 4 +- Mesures/humidity/solar-grafana/0_cron.lua | 33 ++++++++++---- .../humidity/solar-grafana/0_send_data.lua | 44 ++++++++++++------- Mesures/humidity/solar-grafana/boot.lua | 12 ++--- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/Mesures/humidity/solar-grafana/0_1_htu21d.lua b/Mesures/humidity/solar-grafana/0_1_htu21d.lua index 8fbd6a4..6377175 100644 --- a/Mesures/humidity/solar-grafana/0_1_htu21d.lua +++ b/Mesures/humidity/solar-grafana/0_1_htu21d.lua @@ -2,7 +2,7 @@ -- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt function readHTU21D() - if verbose then print("\n 0_1_htu21d.lua zf200523.1408 \n") end + if verbose then print("\n 0_1_htu21d.lua zf200523.1642 \n") end id = 0 sda = 5 scl = 6 addr = 0x40 HUMIDITY = 0xE5 TEMPERATURE = 0xE3 @@ -40,4 +40,4 @@ function readHTU21D() if verbose then print(node.heap()) end end -readHTU21D() +--readHTU21D() diff --git a/Mesures/humidity/solar-grafana/0_2_htu21d.lua b/Mesures/humidity/solar-grafana/0_2_htu21d.lua index dd18afa..7989c27 100644 --- a/Mesures/humidity/solar-grafana/0_2_htu21d.lua +++ b/Mesures/humidity/solar-grafana/0_2_htu21d.lua @@ -2,7 +2,7 @@ -- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt function readHTU21D() - if verbose then print("\n 0_2_htu21d.lua zf200523.1408 \n") end + if verbose then print("\n 0_2_htu21d.lua zf200523.1643 \n") end id = 0 sda = 5 scl = 4 addr = 0x40 HUMIDITY = 0xE5 TEMPERATURE = 0xE3 @@ -40,4 +40,4 @@ function readHTU21D() if verbose then print(node.heap()) end end -readHTU21D() +--readHTU21D() diff --git a/Mesures/humidity/solar-grafana/0_cron.lua b/Mesures/humidity/solar-grafana/0_cron.lua index 19925ce..1deede9 100644 --- a/Mesures/humidity/solar-grafana/0_cron.lua +++ b/Mesures/humidity/solar-grafana/0_cron.lua @@ -1,22 +1,37 @@ -- Petit script pour faire office de crontab pour les mesures -print("\n 0_cron.lua zf200229.1557 \n") +print("\n 0_cron.lua zf200523.1644 \n") cron1=tmr.create() -cron1:alarm(60*1000, tmr.ALARM_AUTO, function() +cron1:alarm(5*1000, tmr.ALARM_AUTO, function() if verbose then print("cron1........................") end if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end ---[[ -f = "0_htu21d.lua" if file.exists(f) then dofile(f) end + print("toto0") + th_id=1 + print("toto1") + f = "0_1_htu21d.lua" if file.exists(f) then dofile(f) end + print("toto2") + readHTU21D() + print("toto3") + f = "0_send_data.lua" if file.exists(f) then dofile(f) end + print("toto4") + send_data() - zurl = thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1) + print("toto5") + th_id=2 + print("toto6") + f = "0_2_htu21d.lua" if file.exists(f) then dofile(f) end + print("toto7") + readHTU21D() + print("toto8") + f = "0_send_data.lua" if file.exists(f) then dofile(f) end + print("toto9") + send_data() + print("toto10") - f = "0_send_data.lua" if file.exists(f) then dofile(f) end - - ztemp1=nil zhum1=nil -]] + th_id=nil ztemp1=nil zhum1=nil if verbose then print(node.heap()) end collectgarbage() diff --git a/Mesures/humidity/solar-grafana/0_send_data.lua b/Mesures/humidity/solar-grafana/0_send_data.lua index bb5e2fc..d5abe6c 100644 --- a/Mesures/humidity/solar-grafana/0_send_data.lua +++ b/Mesures/humidity/solar-grafana/0_send_data.lua @@ -1,24 +1,34 @@ --- Petit script pour envoyer les valeurs de température sur un serveur WEB via un HTTP GET +-- Petit script pour envoyer les valeurs sur un serveur WEB (InfluxDB) +-- via un http GET function send_data() - if verbose then print("\n 0_send_data.lua zf200119.1518 \n") end + if verbose then print("\n 0_send_data.lua zf200523.1643 \n") end - if verbose then print("send_data_web: ") end - if verbose then print(zurl) end - - http.get(zurl, nil, function(code, data) - if (code < 0) then - if verbose then print("HTTP request failed") end - if verbose then print("zuzu", code, data) end - else - if verbose then print(code, data) end - end - zurl=nil + function zpost(zarg) + if verbose then print("influxdb_url: "..influxdb_url) end + if verbose then print("zarg: "..zarg) end + http.post(influxdb_url, 'Content-Type: application/x-www-form-urlencoded\r\n', zarg, function(code, data) + -- print("toto") + if (code < 0) then + print("HTTP request failed") + print("zuzu", code, data) + else + if verbose then print(code, data) end + end + -- print("tutu") end) - zurl=nil send_data=nil - if verbose then print(node.heap()) end - collectgarbage() - if verbose then print(node.heap()) end + end + + zpost("energy,capteur=th"..th_id.." humidity="..zhum1) + zpost("energy,capteur=th"..th_id.." temperature="..ztemp1) + + zarg=nil code=nil data=nil zpost=nil send_data=nil + -- print("titi") end +--send_data() + +--[[ +verbose=true send_data() +]] diff --git a/Mesures/humidity/solar-grafana/boot.lua b/Mesures/humidity/solar-grafana/boot.lua index edfe2aa..8199834 100644 --- a/Mesures/humidity/solar-grafana/boot.lua +++ b/Mesures/humidity/solar-grafana/boot.lua @@ -1,20 +1,14 @@ -- Scripts à charger après le boot pour démarrer son projet -print("\n boot.lua zf200521.1339 \n") +print("\n boot.lua zf200523.1611 \n") function boot() verbose = true print("On lance le boot...") print(node.heap()) collectgarbage() print(node.heap()) - - --f="0_htu21d.lua" if file.exists(f) then dofile(f) end - --zurl=thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1) - --f="0_send_data.lua" if file.exists(f) then dofile(f) end - --f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end - - --f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end - --f="0_cron.lua" if file.exists(f) then dofile(f) end --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 = "web_ide2.lua" if file.exists(f) then dofile(f) end print("verbose:",verbose)