diff --git a/Mesures/humidity/solar-grafana/0_htu21d.lua b/Mesures/humidity/solar-grafana/0_1_htu21d.lua similarity index 95% rename from Mesures/humidity/solar-grafana/0_htu21d.lua rename to Mesures/humidity/solar-grafana/0_1_htu21d.lua index 4eff8ae..1a9e425 100644 --- a/Mesures/humidity/solar-grafana/0_htu21d.lua +++ b/Mesures/humidity/solar-grafana/0_1_htu21d.lua @@ -2,12 +2,12 @@ -- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt function readHTU21D() - if verbose then print("\n 0_htu21d.lua zf200119.1517 \n") end + if verbose then print("\n 0_1_htu21d.lua zf200521.1404 \n") end id = 0 sda = 5 scl = 6 addr = 0x40 HUMIDITY = 0xE5 TEMPERATURE = 0xE3 i2c.setup(id, sda, scl, i2c.SLOW) sda = nil scl = nil - + function read_HTU21D(zreg, zdelay) i2c.start(id) i2c.address(id, addr, i2c.TRANSMITTER) i2c.write(id, zreg) i2c.stop(id) diff --git a/Mesures/humidity/solar-grafana/0_2_htu21d.lua b/Mesures/humidity/solar-grafana/0_2_htu21d.lua new file mode 100644 index 0000000..47c3743 --- /dev/null +++ b/Mesures/humidity/solar-grafana/0_2_htu21d.lua @@ -0,0 +1,43 @@ +-- Lit le capteur I2C HTU21D de mesure d'humidité et de température +-- 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 zf200521.1347 \n") end + + id = 0 sda = 4 scl = 6 addr = 0x40 + HUMIDITY = 0xE5 TEMPERATURE = 0xE3 + i2c.setup(id, sda, scl, i2c.SLOW) sda = nil scl = nil + + function read_HTU21D(zreg, zdelay) + i2c.start(id) i2c.address(id, addr, i2c.TRANSMITTER) + i2c.write(id, zreg) i2c.stop(id) + i2c.start(id) i2c.address(id, addr, i2c.RECEIVER) + tmr.delay(zdelay) + r = i2c.read(id,3) i2c.stop(id) + return r + end + + function readTemp() + r = read_HTU21D(TEMPERATURE, 50000) + r = (bit.band((bit.lshift(string.byte(r,1),8)+string.byte(r,2)),0xfffc)*17572)/65536-4685 + return tonumber(string.format("%.1f", tostring(r/100))) + end + + function readHumi() + r = read_HTU21D(HUMIDITY, 16000) + r = (bit.band((bit.lshift(string.byte(r,1),8)+string.byte(r,2)),0xfffc)*12500)/65536-600 + return tonumber(string.format("%.1f", tostring(r/100))) + end + + ztemp1=readTemp() zhum1=readHumi() + if verbose then print("Temperature: "..ztemp1.." °C") end + if verbose then print("Humidity: "..zhum1.." %") end + + id=nil sda=nil scl=nil addr=nil HUMIDITY=nil TEMPERATURE=nil r=nil + read_HTU21D=nil readTemp=nil readHumi=nil readHTU21D=nil + if verbose then print(node.heap()) end + collectgarbage() + if verbose then print(node.heap()) end +end + +readHTU21D() diff --git a/Mesures/humidity/solar-grafana/boot.lua b/Mesures/humidity/solar-grafana/boot.lua index a58b4b0..edfe2aa 100644 --- a/Mesures/humidity/solar-grafana/boot.lua +++ b/Mesures/humidity/solar-grafana/boot.lua @@ -1,6 +1,6 @@ -- Scripts à charger après le boot pour démarrer son projet -print("\n boot.lua zf200303.1409 \n") +print("\n boot.lua zf200521.1339 \n") function boot() verbose = true @@ -10,11 +10,11 @@ function boot() --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_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_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 = "web_ide2.lua" if file.exists(f) then dofile(f) end print("verbose:",verbose) diff --git a/Mesures/humidity/solar-grafana/0_tst_maxime.lua b/Mesures/humidity/solar-grafana/oldies/0_tst_maxime.lua similarity index 100% rename from Mesures/humidity/solar-grafana/0_tst_maxime.lua rename to Mesures/humidity/solar-grafana/oldies/0_tst_maxime.lua