diff --git a/Mesures/humidity/bolo-thingspeak/0_cron.lua b/Mesures/humidity/bolo-thingspeak/0_cron.lua index c50ec84..b43d674 100644 --- a/Mesures/humidity/bolo-thingspeak/0_cron.lua +++ b/Mesures/humidity/bolo-thingspeak/0_cron.lua @@ -1,14 +1,20 @@ -- Petit script pour faire office de crontab pour les mesures -print("\n 0_cron.lua zf200119.1009 \n") +print("\n 0_cron.lua zf200119.1436 \n") cron1=tmr.create() cron1:alarm(20*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 - ztemp1=readTemp() zhum1=readHumi() - if verbose then print("Temperature: "..ztemp1.." °C") end - if verbose then print("Humidity: "..zhum1.." %") end - zurl=thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1) - send_data() ztemp1=nil zhum1=nil r=nil - if verbose then print(node.heap()) collectgarbage() print(node.heap()) end + + 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 + + ztemp1=nil zhum1=nil + + if verbose then print(node.heap()) end + collectgarbage() + if verbose then print(node.heap()) end end) diff --git a/Mesures/humidity/bolo-thingspeak/0_htu21d.lua b/Mesures/humidity/bolo-thingspeak/0_htu21d.lua index 85a86fb..4acade6 100644 --- a/Mesures/humidity/bolo-thingspeak/0_htu21d.lua +++ b/Mesures/humidity/bolo-thingspeak/0_htu21d.lua @@ -1,42 +1,43 @@ -- Lit le capteur I2C HTU21D de mesure d'humidité et de température -print("\n 0_htu21d.lua zf200119.0957 \n") +print("\n 0_htu21d.lua zf200119.1426 \n") --- module https://learn.sparkfun.com/tutorials/htu21d-humidity-sensor-hookup-guide/all --- acahat https://www.aliexpress.com/item/32480177429.html --- schéma https://github.com/sparkfun/HTU21D_Breakout/blob/master/hardware/SparkFun_HTU21D_Breakout.pdf --- data sheet https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf --- Comparaison DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280 --- http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html --- théorie http://electromag1.wifeo.com/capteurs-de-temperature-et-humidite-gy-21-et-si7021.php --- source lua: https://github.com/tebben/NodeMCU +-- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt --- ATTENTION: il n'y a seulement que certaines combinaisons de pins qui fonctionnent avec le capteur HTU21D avec le NodeMCU ! +function readHTU21D() + id = 0 sda = 5 scl = 6 addr = 0x40 + HUMIDITY = 0xE5 TEMPERATURE = 0xE3 + i2c.setup(id, sda, scl, i2c.SLOW) sda = nil scl = nil -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) + i2c.start(id) i2c.address(id, addr, i2c.RECEIVER) + tmr.delay(zdelay) + r = i2c.read(id,3) i2c.stop(id) + return r + end -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 + 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 -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 - -print("Temperature: "..readTemp().." °C") -print("Humidity: "..readHumi().." %") -r = nil +readHTU21D() diff --git a/Mesures/humidity/bolo-thingspeak/0_send_data.lua b/Mesures/humidity/bolo-thingspeak/0_send_data.lua index 0ba8f1b..5fcd501 100644 --- a/Mesures/humidity/bolo-thingspeak/0_send_data.lua +++ b/Mesures/humidity/bolo-thingspeak/0_send_data.lua @@ -1,5 +1,5 @@ -- Petit script pour envoyer les valeurs de température sur un serveur WEB via un HTTP GET -print("\n 0_send_data.lua zf200119.1009 \n") +print("\n 0_send_data.lua zf200119.1433 \n") function send_data() if verbose then print("send_data_web: ") end @@ -14,8 +14,10 @@ function send_data() end zurl=nil end) + zurl=nil send_data=nil + if verbose then print(node.heap()) end + collectgarbage() + if verbose then print(node.heap()) end end ---[[ send_data() -]] diff --git a/Mesures/humidity/bolo-thingspeak/_zremote_cmd.txt b/Mesures/humidity/bolo-thingspeak/_zremote_cmd.txt index c3ce6d0..a1f0dc0 100644 --- a/Mesures/humidity/bolo-thingspeak/_zremote_cmd.txt +++ b/Mesures/humidity/bolo-thingspeak/_zremote_cmd.txt @@ -1,9 +1,10 @@ # Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom -# zf200119.1034 +# zf200119.1043 Todo à faire pour ce projet ! +- faire que send_data et read_temp soient lancés à la volée afin d'économiser de la RAM quand ce n'est pas utilisé - arrêter de demander de connecter le WIFI automatiquement en mode station juste après le boot dans la config wifiinit (automatic connect) - lancement ou arrêt du WEBIDE via la home page - le wifi setup ne fonctionne toujours pas quand il y a déjà un ap de connecté (problème du reboot quand adrs ip ok)! @@ -81,11 +82,13 @@ telnet -rN $zIP $zport verbose=false ~. +=node.heap() +collectgarbage() +=node.heap() + dofile("dir.lua") dir() -collectgarbage() -=node.heap() for k,v in pairs(_G) do print(k,v) end dofile("wifi_info.lua") diff --git a/Mesures/humidity/bolo-thingspeak/boot.lua b/Mesures/humidity/bolo-thingspeak/boot.lua index ccead74..0f85672 100644 --- a/Mesures/humidity/bolo-thingspeak/boot.lua +++ b/Mesures/humidity/bolo-thingspeak/boot.lua @@ -1,19 +1,18 @@ -- Scripts à charger après le boot pour démarrer son projet -print("\n boot.lua zf20015.1700 \n") +print("\n boot.lua zf20019.1438 \n") function boot() - + verbose = true print("booooooooooot...") print(node.heap()) collectgarbage() print(node.heap()) - f= "0_htu21d.lua" if file.exists(f) then dofile(f) end - f= "0_send_data.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 - - f=nil boot=nil - verbose = true + 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_cron.lua" if file.exists(f) then dofile(f) end + --f = "web_ide2.lua" if file.exists(f) then dofile(f) end + f=nil boot=nil end boot() diff --git a/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt b/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt new file mode 100644 index 0000000..ac5d6e8 --- /dev/null +++ b/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt @@ -0,0 +1,10 @@ +-- module https://learn.sparkfun.com/tutorials/htu21d-humidity-sensor-hookup-guide/all +-- achat https://www.aliexpress.com/item/32480177429.html +-- schéma https://github.com/sparkfun/HTU21D_Breakout/blob/master/hardware/SparkFun_HTU21D_Breakout.pdf +-- data sheet https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf +-- Comparaison DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280 +-- http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html +-- théorie http://electromag1.wifeo.com/capteurs-de-temperature-et-humidite-gy-21-et-si7021.php +-- source lua: https://github.com/tebben/NodeMCU + +-- ATTENTION: il n'y a seulement que certaines combinaisons de pins qui fonctionnent avec le capteur HTU21D avec le NodeMCU !