diff --git a/Mesures/humidity/psychrometre/README.md b/Mesures/humidity/psychrometre/README.md index 1565346..06eba3e 100644 --- a/Mesures/humidity/psychrometre/README.md +++ b/Mesures/humidity/psychrometre/README.md @@ -5,10 +5,27 @@ zf191203.0022 Petit projet pour mesurer l'humidité de référence, par exemple pour l'étalonnage d'un hygromètre, par la méthode de la psychométrie. https://fr.wikipedia.org/wiki/Psychrom%C3%A9trie + + +## Le principe ? +C'est très simple, on mesure la température de deux thermomètres, un recouvert d'un manchon humide et l'autre à l'air libre, les deux thermomètres sont mis dans un flux d'air forcé. La différence de températures indique, via une table de conversion, l'humidité relative de l'air. + + +### Tables psychrométriques + http://meteonet.info/html/table_psychrometrique.html https://www.abcclim.net/table-psychrometrique.html -Principe simple, on mesure la température de deux thermomètres, un recouvert d'un manchon humide et l'autre à l'air libre. La différence de températures indique, via une table de conversion, l'humidité relative de l'air. + +### Abaque psychrométrique + +![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/zzzimg/20191202_232755.jpg) + + +### Calculateur *on line* de valeurs psychrométriques + +https://fr.planetcalc.com/246/ +https://www.rotronic.com/fr/humidity_measurement-feuchtemessung-mesure_de_l_humidite/humidity-calculator-feuchterechner-mr ![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232755.jpg) @@ -18,9 +35,9 @@ Mon petit psychromètre à base de NodeMCU & DS18B20 ![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232703.jpg) - Les températures mesurées en fonctionnement + ![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232904.jpg) Et le résultat à lire dans une table psychrométrique diff --git a/Mesures/humidity/psychrometre/img/PsychrometricChart-SeaLevel-SI.jpg b/Mesures/humidity/psychrometre/img/PsychrometricChart-SeaLevel-SI.jpg new file mode 100644 index 0000000..63618ca Binary files /dev/null and b/Mesures/humidity/psychrometre/img/PsychrometricChart-SeaLevel-SI.jpg differ diff --git a/Mesures/temp/mario/0_cron.lua b/Mesures/temp/mario/0_cron.lua new file mode 100644 index 0000000..073c089 --- /dev/null +++ b/Mesures/temp/mario/0_cron.lua @@ -0,0 +1,13 @@ +-- Petit script pour faire office de crontab pour les +--mesures +print("\n 0_cron.lua zf190917.0033 \n") + +f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end +flash_led_xfois() +xfois =2 + +cron1=tmr.create() +cron1:alarm(10*1000, tmr.ALARM_AUTO, function() + blink_LED () + send_data() +end) diff --git a/Mesures/temp/mario/0_get_data.lua b/Mesures/temp/mario/0_get_data.lua new file mode 100644 index 0000000..9c81dd7 --- /dev/null +++ b/Mesures/temp/mario/0_get_data.lua @@ -0,0 +1,62 @@ +-- Lit le convertisseur ADC connecté sur le transformateur de courant +-- pour mesurer le courant électrique de l'installation PV +print("\n 0_get_data.lua zf191024.1037 \n") + +-- Astuce de mesure: +-- On converti le courant en tension avec la résistance de charge du +-- transformateur de courant 1/800 et le mesure avec l'ADC +-- Au lieu de découper la sinusoïde en 100 parties, c'est à dire toutes +-- les 0.2ms (5'000x /s), pour en faire l'intégrale. On lit l'adc toutes +-- les 11ms (91x /s) donc beaucoup plus lentement. +-- Comme la sinusoïde fait 20ms et est répétitive, on balaye (par décalage) +-- statistiquement la sinusoïde. +-- On redresse l'alternance par rapport à la masse fictive (env 0.5), +-- ce qui nous permet d'estimer une valeur RMS du courant +-- quelque soit sa forme et on le somme sur 2.1 secondes +-- Les mesures min et max ne sont là juste pour vérifier que nous sommes +-- bien dans la plage de mesure avec le choix de la résistance de conversion +-- la conversion courant/tension/puissance est faite avec une simple régle de 3 + + +zpow_cal=401 --puissance mesurée de la charge étalon +zadc_cal=189 --valeur de l'adc pour zpow_cal +zadc_offset=548 + +zadc_sum=0 zadc_offset_sum=0 znb_mes=0 +zadc_min=zadc_offset zadc_max=zadc_offset + +if adc.force_init_mode(adc.INIT_ADC) +then + node.restart() + return +end + +tmr_read_adc=tmr.create() +tmr_read_adc:alarm(11, tmr.ALARM_AUTO, function() + read_adc() +end) + +tmr_calc_rms=tmr.create() +tmr_calc_rms:alarm(2.1*1000, tmr.ALARM_AUTO, function() + calc_rms() +end) + +function read_adc() + zadc=adc.read(0) + if zadc<=zadc_min then zadc_min=zadc end + if zadc>=zadc_max then zadc_max=zadc end + zadc_offset_sum=zadc_offset_sum+zadc + zadc=zadc-zadc_offset if zadc<=0 then zadc=zadc*-1 end + zadc_sum=zadc_sum+zadc znb_mes=znb_mes+1 +end + +function calc_rms() + zadc_rms=math.floor(zadc_sum/znb_mes) + if zadc_rms<=8 then zadc_rms=0 end + zadc_offset=math.floor(zadc_offset_sum/znb_mes) + zpower=math.floor(zadc_rms*zpow_cal/zadc_cal) + if verbose then print(zadc_min,zadc_max,zadc_max-zadc_min,zadc_offset,zadc_rms,zpower.."W") end + zadc_min=zadc_offset zadc_max=zadc_offset + zadc_sum=0 zadc_offset_sum=0 znb_mes=0 + zadc_min=zadc_offset zadc_max=zadc_offset +end diff --git a/Mesures/temp/mario/0_send_data.lua b/Mesures/temp/mario/0_send_data.lua new file mode 100644 index 0000000..38f119b --- /dev/null +++ b/Mesures/temp/mario/0_send_data.lua @@ -0,0 +1,27 @@ +-- Petit script pour envoyer les valeurs sur un serveur WEB (InfluxDB) +-- via un http GET +print("\n 0_send_data.lua zf190924.1043 \n") + +function send_data() + if verbose then print("send_data: ") end + + zarg="energy,compteur=2 puissance="..zpower/1000 + 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) +-- print("titi") +end + +--[[ +zpower=450 +send_data() +]] diff --git a/Mesures/temp/mario/README.md b/Mesures/temp/mario/README.md new file mode 100644 index 0000000..06eba3e --- /dev/null +++ b/Mesures/temp/mario/README.md @@ -0,0 +1,70 @@ +# Mesure d'humidité de référence par psychométrie + +zf191203.0022 + +Petit projet pour mesurer l'humidité de référence, par exemple pour l'étalonnage d'un hygromètre, par la méthode de la psychométrie. + +https://fr.wikipedia.org/wiki/Psychrom%C3%A9trie + + +## Le principe ? +C'est très simple, on mesure la température de deux thermomètres, un recouvert d'un manchon humide et l'autre à l'air libre, les deux thermomètres sont mis dans un flux d'air forcé. La différence de températures indique, via une table de conversion, l'humidité relative de l'air. + + +### Tables psychrométriques + +http://meteonet.info/html/table_psychrometrique.html +https://www.abcclim.net/table-psychrometrique.html + + +### Abaque psychrométrique + +![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/zzzimg/20191202_232755.jpg) + + +### Calculateur *on line* de valeurs psychrométriques + +https://fr.planetcalc.com/246/ +https://www.rotronic.com/fr/humidity_measurement-feuchtemessung-mesure_de_l_humidite/humidity-calculator-feuchterechner-mr + + +![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232755.jpg) + +Mon petit psychromètre à base de NodeMCU & DS18B20 + + +![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232703.jpg) + +Les températures mesurées en fonctionnement + + +![Image of Yaktocat](https://raw.githubusercontent.com/zuzu59/NodeMCU_Lua/master/Mesures/humidity/psychrometre/img/20191202_232904.jpg) + +Et le résultat à lire dans une table psychrométrique + + +## Astuces de mesures + +Dans ce projet on utilise deux capteurs de température de précision DS18B20 en mode alimentation parasite (seulement deux fils, alimentation comprise). La lecture des températures se fait pour l'instant dans la console série ! + + +## Installation + +Il faut *flasher* le NodeMCU avec ce firmware: + +https://github.com/zuzu59/NodeMCU_Lua/blob/master/Firmware/nodemcu-master-20-modules-2019-06-01-12-50-39-float.bin + +Avec ces modules: + +``` +adc bit ds18b20 file gpio http i2c mqtt net node ow pcm rtctime sntp spi tmr uart wifi ws2812 +``` + + +## Utilisation + +Le code utilisé ici est de la récupération d'un autre projet (temp_solar_zf), 99% est inutile ! + +Ce n'est que le script *a2.lua* qui est utilisé ici pour lire les températures dans la console. Le but n'était pas de faire du code mais d'avoir très rapidement un hygromètre d'étalonnage ;-) + +Un jour quand j'aurai le temps, on ne sait jamais, je terminerai ce projet et lui ferai un joli interface WEB avec graphage sur un Grafana/InfluxDB ;-))) diff --git a/Mesures/temp/mario/_secrets_project - copie.lua b/Mesures/temp/mario/_secrets_project - copie.lua new file mode 100644 index 0000000..8a93966 --- /dev/null +++ b/Mesures/temp/mario/_secrets_project - copie.lua @@ -0,0 +1,15 @@ +-- Petit script pour configurer les secrets dans ce projet +-- et que l'on n'aimerait pas être exportés sur Internet (github) +-- Il faut donc modifier le .gitignore avec secrets*.lua +-- il faut le renommer en 'secrets_project.lua' et sera exécuté +-- par 'boot2.lua' au moment du boot + +function secrets_project() + print("\n secrets_project.lua zf191029.2116 \n") + + influxdb_url="http://www.aaa.ml:8086/write?db=xxx&u=yyy&p=zzz" + print("influxdb_url: "..influxdb_url) + +end +secrets_project() +secrets_project=nil diff --git a/Mesures/temp/mario/_secrets_wifi - copie.lua b/Mesures/temp/mario/_secrets_wifi - copie.lua new file mode 100644 index 0000000..8925860 --- /dev/null +++ b/Mesures/temp/mario/_secrets_wifi - copie.lua @@ -0,0 +1,23 @@ +-- Petit script pour configurer les secrets utilisés pour le wifi +-- et que l'on n'aimerait pas être exportés sur Internet (github) +-- Il faut donc modifier le .gitignore avec secrets*.lua +-- il faut le renommer en 'secrets_wifi.lua' et sera exécuté +-- par 'wifi_init.lua' une fois pour la configuration du WIFI + +function secrets_wifi() + print("\n secrets_wifi.lua zf191108.1744 \n") + + -- cli_ssid="3g-s7" + -- cli_ssid="3G-zf2" + -- cli_ssid="apzuzu6_EXT" + cli_ssid="xxx" + cli_pwd="yyy" + + -- cli_ssid="voie4." + -- cli_pwd="yyy" + + ap_ssid="NodeMCU" + ap_pwd="yyy" + +end +secrets_wifi() diff --git a/Mesures/temp/mario/_zremote_cmd.txt b/Mesures/temp/mario/_zremote_cmd.txt new file mode 100644 index 0000000..61727b4 --- /dev/null +++ b/Mesures/temp/mario/_zremote_cmd.txt @@ -0,0 +1,180 @@ +# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom +# zf191201.2334 + +# si luatool ne marche pas sur le MAC, il faut lire ceci: +# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0 + +# raccourcis clavier +# CTRL+ALT+ENTER envoie au terminal la ligne de l'éditeur +# SHIT+CTRL+` ouvre le terminal (attention, ne pas oublier de copier le *path* dans le *tree* et le changer) +# ALT+CMD+F bascule entre le terminal et l'éditeur + +# définitions à faire AVANT ! +cd /Users/zuzu/Desktop/NodeMCU/NodeMCU_Lua/WIFI_sniffer/cret_project +export luatool_tty="/dev/cu.wchusbserial1410" +export zIP="192.168.0.200" +#export zIP="192.168.0.137" +export zport="23" + +cd '/Users/zuzu/Google Drive/FamilleZ Share/FamilleZ/Papa/LUA/NodeMCU ESP8266/NodeMCU_Lua/WIFI_sniffer/cret_project' +export zIP="localhost" +export zport="2323" +ATTENTION: voir les tunnels tout à la fin ! + + +# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP) +telnet -rN $zIP $zport +~. +--node.restart() +collectgarbage() +=node.heap() +for k,v in pairs(_G) do print(k,v) end + + +# commandes lua pour ce projet +telnet -rN $zIP $zport +wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED) +dofile("dir2.lua") +filec('dir2.lua') +dirc() +~. + + + +verbose=true +verbose=false +zsort_rssi() zshow() + + +#commandes luatool pour ce projet le .137 est à jour avec la nouvelle version du wifi ! +~. +./luatool.py --ip $zIP:$zport -l +./luatool.py --ip $zIP:$zport -f wifi_init.lua + + +./luatool.py --ip $zIP:$zport -f secrets_wifi.lua +./luatool.py --ip $zIP:$zport -f initz.lua -t init.lua +./luatool.py --ip $zIP:$zport -f boot.lua +./luatool.py --ip $zIP:$zport -f boot2.lua +./luatool.py --ip $zIP:$zport -f wifi_init.lua +./luatool.py --ip $zIP:$zport -f set_time.lua +./luatool.py --ip $zIP:$zport -f wifi_info.lua +./luatool.py --ip $zIP:$zport -f c.lua +./luatool.py --ip $zIP:$zport -f cat.lua +./luatool.py --ip $zIP:$zport -f flash_led_xfois.lua +./luatool.py --ip $zIP:$zport -f head.lua + +./luatool.py --ip $zIP:$zport -f b.lua +./luatool.py --ip $zIP:$zport -f web_srv2.lua +./luatool.py --ip $zIP:$zport -f z_index.html + + +./luatool.py --ip $zIP:$zport -f wifi_get_conf.html +./luatool.py --ip $zIP:$zport -f wifi_set_conf.html + + +./luatool.py --ip $zIP:$zport -f z_page1.html +./luatool.py --ip $zIP:$zport -f z_page2.html +./luatool.py --ip $zIP:$zport -f z_page3.html +./luatool.py --ip $zIP:$zport -f z_page4.html + +./luatool.py --ip $zIP:$zport --delete wifi_ap_start.lua +./luatool.py --ip $zIP:$zport --delete wifi_cli_conf.lua +./luatool.py --ip $zIP:$zport --delete wifi_cli_start.lua +./luatool.py --ip $zIP:$zport --delete dir.lua +./luatool.py --ip $zIP:$zport --delete initz.lua +./luatool.py --ip $zIP:$zport --delete wifi_conf.lua + + + +dofile("wifi_info.lua") +--node.restart() +for k,v in pairs(_G) do print(k,v) end +t=12 +t=nil +print(pcall(function () print("2"..t) end)) + + + +# ici c'est maintenant ;-) +~. +./luatool.py --ip $zIP:$zport -f b.lua +#./luatool.py --ip $zIP:$zport --zrestart +telnet -rN $zIP $zport +zsort_rssi() zshow() +print(ztrig_rssi) +ztrig_rssi=-1000 +ztrig_rssi=-90 + + + +# test de la gestion des erreurs +~. +./luatool.py --ip $zIP:$zport -f c.lua +#./luatool.py --ip $zIP:$zport --zrestart +telnet -rN $zIP $zport +status, err = pcall(function () dofile("c.lua") end) if status==false then print("Error: ",err) end +zerr=nil +zerr=1 +ztmr_tst_err:unregister() + + + +~. +./luatool.py --ip $zIP:$zport -f head.lua +telnet -rN $zIP $zport +dofile("head.lua") +zhead("c.lua") + +ztmr_tst_err:unregister() +for k,v in pairs(_G) do print(k,v) end + +./luatool.py --ip $zIP --zrestart + + +# faire un cat d'un fichier sur le NodeMCU +dofile("cat.lua") +cat("boot2.lua") + + +# commandes luatool +./luatool.py -h +./luatool.py --ip $zIP:$zport -i +./luatool.py --ip $zIP:$zport -l +./luatool.py --ip $zIP:$zport -f toto.lua -d +./luatool.py --ip $zIP:$zport --delete toto.lua + + +# création des tunnels ssh +ATTENTION: dans un premier terminal ! +Pour le MsL +ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.1.111:23 ubuntu@localhost -p 20221 + +Pour le Crêt +ssh -N -L 2323:192.168.0.137:23 admin@z.zufferey.com -p 1822 +ssh -N -L 2323:192.168.0.122:23 admin@z.zufferey.com -p 1822 + +ATTENTION: dans un deuxième terminal ! +export zIP="localhost" +export zport="2323" +telnet -rN $zIP $zport + +dofile("dir2.lua") +dir() +filec("head.lua") + +dofile("head.lua") +zhead("dir2.lua") + +dofile("cat.lua") +cat("head.lua") + +~. +--node.restart() +=node.heap() + + +status, err = pcall(function () fonction_a_tester() end) if status==false then print("Error: ",err) end +status, err = pcall(function () toto() end) if status==false then print("Error: ",err) end + +. diff --git a/Mesures/temp/mario/a1.lua b/Mesures/temp/mario/a1.lua new file mode 100644 index 0000000..1f98ae2 --- /dev/null +++ b/Mesures/temp/mario/a1.lua @@ -0,0 +1,23 @@ +-- programme pour faire un test depuis de le webide + +-- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/ + +function a1() + print("\n a1.lua zf190601.1627 \n") +end + +a1() + +local ow_pin = 3 +ds18b20.setup(ow_pin) + +print("toto182538") + +-- read all sensors and print all measurement results +ds18b20.read( + function(ind,rom,res,temp,tdec,par) + print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) + end,{}) + +print("tutu152603") + diff --git a/Mesures/temp/mario/a2.lua b/Mesures/temp/mario/a2.lua new file mode 100644 index 0000000..f619676 --- /dev/null +++ b/Mesures/temp/mario/a2.lua @@ -0,0 +1,44 @@ +-- programme pour faire un test depuis de le webide + +function a2() + print("\n a2.lua zf191202.2324 \n") + +end + +a2() + +-- Lit les capteurs de température solaire et envoie les mesures sur ThingSpeak +-- zf190617.1134 + +-- lecture: https://thingspeak.com/channels/802784/private_show + +-- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/ + + +local ow_pin = 3 +ds18b20.setup(ow_pin) + +print("toto182538") + +-- ztemp1=0 ztemp2=0 ztemp3=0 + +-- read all sensors and print all measurement results +ds18b20.read( + function(ind,rom,res,temp,tdec,par) +-- print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par) + print(ind,temp) + if ind == 1 then + ztemp1 = temp + elseif ind == 2 then + ztemp2 = temp + elseif ind == 3 then + ztemp3 = temp + --C'est la fin de lecture, on envoie les mesures à ThingSpeak + end + print(ztemp1,ztemp2,ztemp2-ztemp1) +-- disp_send() +-- end + end,{}) + +print("tutu152603") + diff --git a/Mesures/temp/mario/a3.lua b/Mesures/temp/mario/a3.lua new file mode 100644 index 0000000..188dfa6 --- /dev/null +++ b/Mesures/temp/mario/a3.lua @@ -0,0 +1,43 @@ +-- programme pour faire un test depuis de le webide + +function a3() + print("\n a3.lua zf190617.1135 \n") + +end + +a3() + + + + +-- Petit script pour envoyer quelque chose sur un serveur WEB +print("\n web_cli.lua zf190616.1519 \n") + +function disp_send() + print("web_cli: ") +-- ztemp1=11 ztemp2=12 ztemp3=13 + + zurl=thingspeak_url_update.."field1="..tostring(ztemp1).."&field2="..tostring(ztemp2).."&field3="..tostring(ztemp3) + print(zurl) + http.get(zurl, nil, function(code, data) + print("toto") + if (code < 0) then + print("tutu") + print("HTTP request failed") + print("zuzu", code, data) + else + print("titi") + print(code, data) + end + end) +end + +--disp_send() + + +--[[ +disp_send() + + + +]] diff --git a/Mesures/temp/mario/a4.lua b/Mesures/temp/mario/a4.lua new file mode 100644 index 0000000..0e6fdf0 --- /dev/null +++ b/Mesures/temp/mario/a4.lua @@ -0,0 +1,16 @@ +-- programme pour faire un test depuis de le webide + +function a4() + print("\n a4.lua zf190617.1125 \n") + +end + +a4() + + + cron1=tmr.create() + cron1:alarm(20*1000, tmr.ALARM_AUTO, function() + f= "a2.lua" if file.exists(f) then dofile(f) end + end) + + diff --git a/Mesures/temp/mario/boot.lua b/Mesures/temp/mario/boot.lua new file mode 100644 index 0000000..109c0a4 --- /dev/null +++ b/Mesures/temp/mario/boot.lua @@ -0,0 +1,13 @@ +-- Scripts à charger après le boot pour démarrer le core system + +print("\n boot.lua zf191124.1920 \n") + +function boot() + --f= "led_rgb.lua" if file.exists(f) then dofile(f) end + f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end + f= "wifi_init.lua" if file.exists(f) then dofile(f) end + --f= "web_ide2.lua" if file.exists(f) then dofile(f) end + --f= "web_srv2.lua" if file.exists(f) then dofile(f) end +end +boot() + diff --git a/Mesures/temp/mario/boot2.lua b/Mesures/temp/mario/boot2.lua new file mode 100644 index 0000000..4a581b3 --- /dev/null +++ b/Mesures/temp/mario/boot2.lua @@ -0,0 +1,55 @@ +-- Scripts à charger après le boot pour démarrer son projet + +print("\n boot2.lua zf191124.1922 \n") + +function boot2() + second_chance=nil initz=nil boot=nil + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + if false then + tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) + end + + boot2_tmr=tmr.create() + boot2_tmr:alarm(1*1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + xfois =2 blink_LED () + else + boot2_tmr:unregister() + flash_led_xfois=nil blink_LED=nil ztmr_Flash_LED=nil + zTm_Off_LED=nil zTm_On_LED=nil nbfois=nil xfois=nil zLED=nil + boot2_tmr=nil secrets_wifi=nil wifi_init=nil + cli_ssid=nil cli_pwd=nil ap_ssid=nil ap_pwd=nil + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + f= "secrets_project.lua" if file.exists(f) then dofile(f) end + f= "set_time.lua" if file.exists(f) then dofile(f) end + collectgarbage() + --- f= "b.lua" if file.exists(f) then dofile(f) end + f= "web_srv2.lua" if file.exists(f) then dofile(f) end + + f=nil + + tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function() + print("BOOOOUM, y'a plus de boot2 !") + wifi_info=nil boot2=nil + end) + + end + end) +end + +boot2() + + +--[[ +tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function() + print(node.heap()) +end) +]] + +--[[ +for k,v in pairs(_G) do print(k,v) end +]] diff --git a/Mesures/temp/mario/c.lua b/Mesures/temp/mario/c.lua new file mode 100644 index 0000000..eb2f832 --- /dev/null +++ b/Mesures/temp/mario/c.lua @@ -0,0 +1,37 @@ +-- Scripts pour tester l'affichage des erreurs quand on se trouve ne remote telnet +-- source: https://www.lua.org/pil/8.4.html +-- source: https://riptutorial.com/lua/example/16000/using-pcall + +--[[ +Usage: +après l'avoir lancé on peut faire varier le contenu de la variable zerr pour cérer des erreurs répétitives + +Commandes à envoyer via un terminal: +~. +./luatool.py --ip $zIP:$zport -f c.lua +#./luatool.py --ip $zIP:$zport --zrestart +telnet -rN $zIP $zport +status, err = pcall(function () dofile("c.lua") end) if status==false then print("Error: ",err) end +zerr=nil +zerr=1 +ztmr_tst_err:unregister() +]] + +print("\n c.lua zf191030.1231 \n") + +zerr=1 +ztmr_tst_err = tmr.create() + +-- le code à tester DOIT être encapsulé dans une fonction +function zfoo() + print("toto: "..zerr) +end + +-- timer pour générer des erreurs répétitives +ztmr_tst_err:alarm(3*1000, tmr.ALARM_AUTO, function() + -- test du code + local status, err = pcall(function () zfoo() end) if status==false then print("Error: ",err) end +end) + + +-- diff --git a/Mesures/temp/mario/cat.lua b/Mesures/temp/mario/cat.lua new file mode 100644 index 0000000..8a2e29c --- /dev/null +++ b/Mesures/temp/mario/cat.lua @@ -0,0 +1,22 @@ +-- fonction cat() pour afficher le contenu d'un fichier dans la flash +print("\n cat.lua zf191124.2204 \n") + +function zread_line() + local zline = "" + while true do + local t = zf:read(1) if t == nil then return end + zline = zline..t + if t == "\n" then return string.sub(zline,1,string.len(zline)-1) end + end +end + +function cat(zfile) + print("\n"..zfile.."\n-------------------------------") + zf = file.open(zfile, "r") + while true do + zline = zread_line() if zline == nil then break end + print(zline) + end + zf:close() + print("-------------------------------") +end diff --git a/Mesures/temp/mario/dir2.lua b/Mesures/temp/mario/dir2.lua new file mode 100644 index 0000000..bd2fb1a --- /dev/null +++ b/Mesures/temp/mario/dir2.lua @@ -0,0 +1,90 @@ +-- fonction dirc() pour calculer le checksum de tous les fichiers sur le NodeMCU ! +-- fonction filec(fichier) pour calculer le checksum d'un seul fichiers sur le NodeMCU ! + +print("\n dir2.lua zf191124.1602 \n") + +function calc_chksum_file() + local name_file = list_files[zcmpt1] + print(name_file) + local size_file = 1 local chksum_file = 0 + local f = file.open(name_file, "r") + while true do + local t = f:read(1) if t == nil then break end + chksum_file = chksum_file + size_file * string.byte(t) + size_file = size_file + 1 + if size_file%100 == 0 then uart.write(0,".") end + end + f:close() print("") + zdir[#zdir+1]=name_file..string.rep(" ",24-string.len(name_file)).." : "..size_file..", "..chksum_file + zcmpt1 = zcmpt1 + 1 + zrepeat() +end + +function zrepeat() + if zcmpt1 <= #list_files then +-- if zcmpt1 <= 3 then + node.task.post(calc_chksum_file) + else + table.sort(zdir) for i=1, #zdir do print(zdir[i]) end + zdir=nil list_files=nil zcmpt1=nil + end +end + +function dirc() + zdir={} list_files={} + local pfile = file.list() + for k,v in pairs(pfile) do + list_files[#list_files+1]=k + end + zcmpt1 = 1 zrepeat() +end + +function filec(name_file) + print(name_file) + local size_file = 1 local chksum_file = 0 + local f = file.open(name_file, "r") + while true do + local t = f:read(1) if t == nil then break end + chksum_file = chksum_file + size_file * string.byte(t) + size_file = size_file + 1 + if size_file%100 == 0 then uart.write(0,".") end + end + f:close() print("") + print(name_file..string.rep(" ",24-string.len(name_file)).." : "..size_file..", "..chksum_file) +end + +function dir() + local zdir={} + local pfile = file.list() + for k,v in pairs(pfile) do + zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v + end + table.sort(zdir) for i=1, #zdir do print(zdir[i]) end + size_file=nil chksum_file=nil k=nil +end + +function clear_dir() + dir=nil dir2=nil dirc=nil filec=nil + zrepeat=nil calc_chksum_file=nil +end + +dir() +print("\nusage:") +print(" dir()") +print(" dirc()") +print(" filec('dir2.lua')") + + +--[[ +dir() +dirc() +filec("dir2.lua") + +=node.heap() +clear_dir() +=node.heap() + +for k,v in pairs(_G) do print(k,v) end + +status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end +]] diff --git a/Mesures/temp/mario/flash_led_xfois.lua b/Mesures/temp/mario/flash_led_xfois.lua new file mode 100644 index 0000000..0b3deaf --- /dev/null +++ b/Mesures/temp/mario/flash_led_xfois.lua @@ -0,0 +1,40 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off + +function flash_led_xfois() + print("\n flash_led_xfois.lua zf1911124.1053 \n") + + --zLED=0 --NodeMCU + zLED=4 --EPS-M3 + zTm_On_LED = 50 --> en ms + zTm_Off_LED = 100 --> en ms + nbfois = 0 + gpio.write(zLED, gpio.HIGH) + gpio.mode(zLED, gpio.OUTPUT) + ztmr_Flash_LED = tmr.create() + + function blink_LED () + if nbfois >= xfois then + -- print(nbfois) + nbfois = 0 + else + if gpio.read(zLED)==gpio.HIGH then + gpio.write(zLED, gpio.LOW) +-- tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + ztmr_Flash_LED:alarm(zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 +-- tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + ztmr_Flash_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end + end + +end + +flash_led_xfois() + +--[[ +xfois =2 +blink_LED () +]] diff --git a/Mesures/temp/mario/goodies/a.lua b/Mesures/temp/mario/goodies/a.lua new file mode 100644 index 0000000..7c59e2f --- /dev/null +++ b/Mesures/temp/mario/goodies/a.lua @@ -0,0 +1,48 @@ +-- Scripts pour tester le multi-tâche + + +function lenteur() + print("in...") + tmr.delay(1*1000*1000) + print("out...") + i=i+1 + zrepeat() +end + +function zrepeat() + if i<5 then + node.task.post(lenteur) + end + print("out2...") +end + + +t1=tmr.now() + +i=0 +zrepeat() + +t2=tmr.now() +print("durée: "..t2-t1) + + +--[[ + +t1={} +for k,v in pairs(pfile) do + t1[#t1+1]=k +end + +print(t1[3]) + + +t1 = file.list() +print(file.list()["a.lua"]) + + +print(file.list[1]) +print(#file.list) + + + +]] \ No newline at end of file diff --git a/Mesures/temp/mario/head.lua b/Mesures/temp/mario/head.lua new file mode 100644 index 0000000..0478b8c --- /dev/null +++ b/Mesures/temp/mario/head.lua @@ -0,0 +1,19 @@ +-- fonction cat() pour afficher les 10 premières lignes d'un fichier dans la flash +print("\n head.lua zf192028.1516 \n") + +function zhead(zfile) + print("\n"..zfile.."\n-------------------------------") + + zfilei = file.open(zfile, "r") + i=1 + zline=file.readline() + repeat +-- print(i..": "..string.sub(zline,1,string.len(zline)-1)) + print(string.sub(zline,1,string.len(zline)-1)) + i=i+1 zline=file.readline() + if i>10 then break end + until zline==nil + file.close(zfilei) + + print("-------------------------------") +end diff --git a/Mesures/temp/mario/img/20191202_232703.jpg b/Mesures/temp/mario/img/20191202_232703.jpg new file mode 100644 index 0000000..0b0db77 Binary files /dev/null and b/Mesures/temp/mario/img/20191202_232703.jpg differ diff --git a/Mesures/temp/mario/img/20191202_232755.jpg b/Mesures/temp/mario/img/20191202_232755.jpg new file mode 100644 index 0000000..e7a53ba Binary files /dev/null and b/Mesures/temp/mario/img/20191202_232755.jpg differ diff --git a/Mesures/temp/mario/img/20191202_232904.jpg b/Mesures/temp/mario/img/20191202_232904.jpg new file mode 100644 index 0000000..d28dc3f Binary files /dev/null and b/Mesures/temp/mario/img/20191202_232904.jpg differ diff --git a/Mesures/temp/mario/img/PsychrometricChart-SeaLevel-SI.jpg b/Mesures/temp/mario/img/PsychrometricChart-SeaLevel-SI.jpg new file mode 100644 index 0000000..63618ca Binary files /dev/null and b/Mesures/temp/mario/img/PsychrometricChart-SeaLevel-SI.jpg differ diff --git a/Mesures/temp/mario/img/ds18b20 parasite mode 2.jpg b/Mesures/temp/mario/img/ds18b20 parasite mode 2.jpg new file mode 100644 index 0000000..ed18a59 Binary files /dev/null and b/Mesures/temp/mario/img/ds18b20 parasite mode 2.jpg differ diff --git a/Mesures/temp/mario/img/ds18b20 parasite mode.jpg b/Mesures/temp/mario/img/ds18b20 parasite mode.jpg new file mode 100644 index 0000000..af073ef Binary files /dev/null and b/Mesures/temp/mario/img/ds18b20 parasite mode.jpg differ diff --git a/Mesures/temp/mario/initz.lua b/Mesures/temp/mario/initz.lua new file mode 100644 index 0000000..87c0905 --- /dev/null +++ b/Mesures/temp/mario/initz.lua @@ -0,0 +1,65 @@ +--Script de bootstrap, test au moment du boot qui a été la cause de boot. +-- Si la cause est un power on ou une connexion depuis l'IDE, alors +-- le script repair.lua pendant xx secondes avant de continuer +--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason + +print("\n init.lua zf191030.2015 \n") + +function initz() + zswitch=3 --switch flash + gpio.mode(zswitch, gpio.INT, gpio.PULLUP) + + function hvbouton() + gpio.trig(zswitch, "none") + initalarme:unregister() initalarme2:unregister() + f= "boot.lua" if file.exists(f) then dofile(f) end + f= "boot2.lua" if file.exists(f) then dofile(f) end + end + + gpio.trig(zswitch, "both", hvbouton) + + function second_chance() + print("seconde chance...") + f= "repair.lua" if file.exists(f) then dofile(f) end + initalarme=tmr.create() + initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function() + f= "boot.lua" if file.exists(f) then dofile(f) end + end) + initalarme2=tmr.create() + initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function() + gpio.trig(zswitch) + hvbouton=nil + zswitch=nil + reset_reason=nil + f= "boot2.lua" if file.exists(f) then dofile(f) end + end) + end + + _, reset_reason = node.bootreason() + print("reset_reason:",reset_reason) + if reset_reason == 0 then + print("power on") + second_chance() + elseif reset_reason == 4 then + print("node.restart") + gpio.trig(zswitch) + hvbouton=nil + second_chance=nil + zswitch=nil + reset_reason=nil + f= "boot.lua" if file.exists(f) then dofile(f) end + f= "boot2.lua" if file.exists(f) then dofile(f) end + elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end + f= "boot2.lua" if file.exists(f) then dofile(f) end + elseif reset_reason == 6 then + print("external reset") + second_chance() + else + print("autre raison") + second_chance() + end +end +initz() + diff --git a/Mesures/temp/mario/luatool.py b/Mesures/temp/mario/luatool.py new file mode 100755 index 0000000..68815e9 --- /dev/null +++ b/Mesures/temp/mario/luatool.py @@ -0,0 +1,405 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +version = "0.6.6 zf191124.1036" + +print("luatool.py ver " + version) + +#Améliorations +# Pour voir les améliorations il faut 'chercher' les zzz + + +# +# ESP8266 luatool +# Author e-mail: 4ref0nt@gmail.com +# Site: http://esp8266.ru +# Contributions from: https://github.com/sej7278 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +# Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import sys +import serial +from time import sleep +import socket +import argparse +from os.path import basename + + +tqdm_installed = True +try: + from tqdm import tqdm +except ImportError, e: + if e.message == 'No module named tqdm': + tqdm_installed = False + else: + raise + + + +class TransportError(Exception): + """Custom exception to represent errors with a transport + """ + def __init__(self, message): + self.message = message + + def __str__(self): + return self.message + +class AbstractTransport: + def __init__(self): + raise NotImplementedError('abstract transports cannot be instantiated.') + + def close(self): + raise NotImplementedError('Function not implemented') + + def read(self, length): + raise NotImplementedError('Function not implemented') + + def writeln(self, data, check=1): + raise NotImplementedError('Function not implemented') + + def writer(self, data): + ##zzz191124 enlève la fin de ligne afin de ne pas perturber la vérification finale + data = data.rstrip('\r\n') + self.writeln("file.writeline([==[" + data + "]==])\r") + + def performcheck(self, expected): + line = '' + char = '' + i = -1 + while char != chr(62): # '>' + char = self.read(1) + if char == '': + raise Exception('No proper answer from MCU') + if char == chr(13) or char == chr(10): # LF or CR + if line != '': + #zzz191124 line = line.strip() + # zzz191021 Affiche ce que l'on a reçu du NodeMCU + if args.verbose: + print("\n\nzread0957: {" + line + "\n}\n") + + if line+'\r' == expected and not args.bar: + sys.stdout.write(" -> ok") + elif line+'\r' != expected: + if line[:4] == "lua:": + sys.stdout.write("\r\n\r\nLua ERROR: %s" % line) + raise Exception('ERROR from Lua interpreter\r\n\r\n') + else: + expected = expected.split("\r")[0] + sys.stdout.write("\r\n\r\nERROR") + sys.stdout.write("\r\n send string : '%s'" % expected) + sys.stdout.write("\r\n expected echo : '%s'" % expected) + sys.stdout.write("\r\n but got answer : '%s'" % line) + sys.stdout.write("\r\n\r\n") + raise Exception('Error sending data to MCU\r\n\r\n') + line = '' + else: + line += char + if char == chr(62) and expected[i] == char: + char = '' + i += 1 + + +class SerialTransport(AbstractTransport): + def __init__(self, port, baud, delay): + self.port = port + self.baud = baud + self.serial = None + self.delay = delay + + try: + self.serial = serial.Serial(port, baud) + except serial.SerialException as e: + raise TransportError(e.strerror) + + self.serial.timeout = 3 + self.serial.interCharTimeout = 3 + + # zzz191021 juste après l'ouverture du port série, on attend le caractère '>' + line = '' + char = '' + i = -1 + while char != chr(62): # '>' + char = self.read(1) + if char == '': + raise Exception('No proper answer from MCU') + line += char + i += 1 + if args.verbose: + print("line: ." + line + ".") + + + def writeln(self, data, check=1): + # zzz191020 on fait une petite pause avant l'envoi de chaque ligne + sleep(self.delay) + if self.serial.inWaiting() > 0: + self.serial.flushInput() + if len(data) > 0 and not args.bar: + sys.stdout.write("\r\n->") + sys.stdout.write(data.split("\r")[0]) + ##zzz191124 attend encore un petit peu avant d'envoyer + sleep(self.delay) + self.serial.write(data) + sleep(self.delay) + # zzz191021 Affiche ce que l'on a envoyé au NodeMCU + if args.verbose: + print("\n\nzwrite0952: {" + data + "\n}\n") + if check > 0: + self.performcheck(data) + elif not args.bar: + sys.stdout.write(" -> send without check") + + def read(self, length): + return self.serial.read(length) + + def close(self): + self.serial.flush() + self.serial.close() + + +class TcpSocketTransport(AbstractTransport): + def __init__(self, host, port): + self.host = host + self.port = port + self.socket = None + + try: + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + except socket.error as e: + raise TransportError(e.strerror) + + try: + self.socket.connect((host, port)) + except socket.error as e: + raise TransportError(e.strerror) + # read intro from telnet server (see telnet_srv.lua) + self.socket.recv(50) + + def writeln(self, data, check=1): + if len(data) > 0 and not args.bar: + sys.stdout.write("\r\n->") + sys.stdout.write(data.split("\r")[0]) + self.socket.sendall(data) + if check > 0: + self.performcheck(data) + elif not args.bar: + sys.stdout.write(" -> send without check") + + def read(self, length): + return self.socket.recv(length) + + def close(self): + self.socket.close() + + +def decidetransport(cliargs): + if cliargs.ip: + data = cliargs.ip.split(':') + host = data[0] + if len(data) == 2: + port = int(data[1]) + else: + port = 23 + return TcpSocketTransport(host, port) + else: + return SerialTransport(cliargs.port, cliargs.baud, cliargs.delay) + + +if __name__ == '__main__': + # parse arguments or use defaults + parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.') + parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line') + parser.add_argument('--delay', default=0.02, help='Delay in seconds between each write, default 0.03 sec.', type=float) + parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.') + parser.add_argument('--ip', default=None, help='Connect via telnet server (--ip IP[:port])') + parser.add_argument('--zrestart', action='store_true', help='Restart the NodeMCU.') + parser.add_argument('-a', '--append', action='store_true', help='Append source file to destination file.') + parser.add_argument('-b', '--baud', default=115200, help='Baudrate, default 115200') + parser.add_argument('-c', '--compile', action='store_true', help='Compile lua to lc after upload') + parser.add_argument('-d', '--dofile', action='store_true', help='Run the Lua script after upload') + parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.') + parser.add_argument('-f', '--src', default='main.lua', help='Source file on computer, default main.lua') + parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.') + parser.add_argument('-l', '--list', action='store_true', help='List files on device') + parser.add_argument('-p', '--port', default='/dev/ttyUSB0', help='Device name, default /dev/ttyUSB0') + parser.add_argument('-r', '--restart', action='store_true', help='Restart MCU after upload') + parser.add_argument('-t', '--dest', default=None, help='Destination file on MCU, default to source file name') + parser.add_argument('-v', '--verbose', action='store_true', help="Show progress messages.") + parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.') + args = parser.parse_args() + + transport = decidetransport(args) + + if args.bar and not tqdm_installed: + sys.stdout.write("You must install the tqdm library to use the bar feature\n") + sys.stdout.write("To install, at the prompt type: \"pip install tqdm\"\n") + sys.exit(0) + + + if args.list: + # zzz191020 Amélioré la sortie du listing des fichiers + transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0) + while True: + char = transport.read(1) + if char == '' or char == chr(62): # '' or '>' + break + sys.stdout.write(char) + sys.exit(0) + + if args.id: + transport.writeln("=node.chipid()\r", 0) + id="" + while True: + char = transport.read(1) + if char == '' or char == chr(62): + break + if char.isdigit(): + id += char + print("\n"+id) + sys.exit(0) + + # zzz191020 Ajouté la fonction restart seule + if args.zrestart: + transport.writeln("node.restart()\r") + sys.exit(0) + + if args.wipe: + transport.writeln("local l = file.list();for k,v in pairs(l) do print(k)end\r", 0) + file_list = [] + fn = "" + while True: + char = transport.read(1) + if char == '' or char == chr(62): + break + if char not in ['\r', '\n']: + fn += char + else: + if fn: + file_list.append(fn.strip()) + fn = '' + for fn in file_list[1:]: # first line is the list command sent to device + if args.verbose: + sys.stderr.write("Delete file {} from device.\r\n".format(fn)) + transport.writeln("file.remove(\"" + fn + "\")\r") + sys.exit(0) + + if args.delete: + transport.writeln("file.remove(\"" + args.delete + "\")\r") + sys.exit(0) + + if args.dest is None: + args.dest = basename(args.src) + # zzz191020 Affiche le fichier à envoyer + print("File: " + args.src) + + # open source file for reading + try: + try: + f = open(args.src, "rt") + except: + import os + base_dir = os.path.dirname(os.path.realpath(__file__)) + f = open(os.path.join(base_dir, args.src), "rt") + os.chdir(base_dir) + except: + sys.stderr.write("Could not open input file \"%s\"\n" % args.src) + sys.exit(1) + + # Verify the selected file will not exceed the size of the serial buffer. + # The size of the buffer is 256. This script does not accept files with + # lines longer than 230 characters to have some room for command overhead. + num_lines = 0 + for ln in f: + if len(ln) > 230: + sys.stderr.write("File \"%s\" contains a line with more than 240 " + "characters. This exceeds the size of the serial buffer.\n" + % args.src) + f.close() + sys.exit(1) + num_lines += 1 + + # Go back to the beginning of the file after verifying it has the correct + # line length + f.seek(0) + + # set serial timeout + if args.verbose: + sys.stderr.write("Upload starting\r\n") + + # remove existing file on device + if args.append==False: + if args.verbose: + sys.stderr.write("Stage 1. Deleting old file from flash memory") + transport.writeln("file.open(\"" + args.dest + "\", \"w\")\r") + transport.writeln("file.close()\r") + transport.writeln("file.remove(\"" + args.dest + "\")\r") + else: + if args.verbose: + sys.stderr.write("[SKIPPED] Stage 1. Deleting old file from flash memory [SKIPPED]") + + + # read source file line by line and write to device + if args.verbose: + sys.stderr.write("\r\nStage 2. Creating file in flash memory and write first line") + if args.append: + transport.writeln("file.open(\"" + args.dest + "\", \"a+\")\r") + else: + transport.writeln("file.open(\"" + args.dest + "\", \"w+\")\r") + line = f.readline() + if args.verbose: + sys.stderr.write("\r\nStage 3. Start writing data to flash memory...") + if args.bar: + for i in tqdm(range(0, num_lines)): + #zzz191124 transport.writer(line.strip()) + transport.writer(line) + line = f.readline() + else: + while line != '': + #zzz191124 transport.writer(line.strip()) + transport.writer(line) + line = f.readline() + + # close both files + f.close() + if args.verbose: + sys.stderr.write("\r\nStage 4. Flush data and closing file") + transport.writeln("file.flush()\r") + transport.writeln("file.close()\r") + + # compile? + if args.compile: + if args.verbose: + sys.stderr.write("\r\nStage 5. Compiling") + transport.writeln("node.compile(\"" + args.dest + "\")\r") + transport.writeln("file.remove(\"" + args.dest + "\")\r") + + # restart or dofile + if args.restart: + transport.writeln("node.restart()\r") + + if args.dofile: # never exec if restart=1 + transport.writeln("dofile(\"" + args.dest + "\")\r", 0) + + if args.echo: + if args.verbose: + sys.stderr.write("\r\nEchoing MCU output, press Ctrl-C to exit") + while True: + sys.stdout.write(transport.read(1)) + + # close serial port + transport.close() + + # flush screen + sys.stdout.flush() + sys.stderr.flush() + if not args.bar: + sys.stderr.write("\r\n--->>> All done <<<---\r\n") diff --git a/Mesures/temp/mario/set_time.lua b/Mesures/temp/mario/set_time.lua new file mode 100644 index 0000000..8b12174 --- /dev/null +++ b/Mesures/temp/mario/set_time.lua @@ -0,0 +1,36 @@ +-- Scripts pour régler l'horloge quand on est connecté en WIFI +-- Permet aussi de 'compresser' le unix time afin de prendre moins de place dans les strings + +print("\n set_time.lua zf191030.2026 \n") + +--source: https://www.freeformatter.com/epoch-timestamp-to-date-converter.html + +ztime2019 = 1546300800 -- Unix time pour le 1.1.2019 + +function set_time() + sntp.sync(nil, nil, nil, 1) +end + +function ztime_compress(ztime_long) + return ztime_long - ztime2019 +end + +function ztime_uncompress(ztime_short) + return ztime_short + ztime2019 +end + +function ztime_format(ztime) + local tm = rtctime.epoch2cal(ztime + 3600) + return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])) +end + +set_time() + +tmr.create():alarm(2*1000, tmr.ALARM_SINGLE, function() + print(ztime_format(rtctime.get())) +end) + + + + + diff --git a/Mesures/temp/mario/telnet_srv2.lua b/Mesures/temp/mario/telnet_srv2.lua new file mode 100644 index 0000000..19920f2 --- /dev/null +++ b/Mesures/temp/mario/telnet_srv2.lua @@ -0,0 +1,93 @@ +-- Serveur telnet pour connexion en remote WIFI, NOUVELLE VERSION ! +-- source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/telnet/telnet.lua + +print("\n telnet_srv2.lua zf191020.1932 \n") + +local node, table, tmr, wifi, uwrite, tostring = + node, table, tmr, wifi, uart.write, tostring + +local function telnet_listener(socket) + local insert, remove, concat, heap, gc = + table.insert, table.remove, table.concat, node.heap, collectgarbage + local fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0 + local s -- s is a copy of the TCP socket if and only if sending is in progress + local wdclr, cnt = tmr.wdclr, 0 + local function debug(fmt, ...) + if (...) then fmt = fmt:format(...) end + uwrite(0, "\r\nDBG: ",fmt,"\r\n" ) + cnt = cnt + 1 + if cnt % 10 then wdclr() end + end + + local function flushGarbage() + if heap() < 13440 then gc() end + end + + local function sendLine() + if not s then return end + + if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s + s = nil + return + end + flushGarbage() + if #fifo2 < 4 then -- Flush FIFO1 into FIFO2 + insert(fifo2,concat(fifo1)) + fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0 + end + local rec = remove(fifo2,1) .. (remove(fifo2,1) or '') .. + (remove(fifo2,1) or '') .. (remove(fifo2,1) or '') + fifo2l = fifo2l - #rec + flushGarbage() + s:send(rec) + end + + local F1_SIZE = 256 + + local function queueLine(str) + while #str > 0 do -- this is because str might be longer than the packet size! + local k, l = F1_SIZE - fifo1l, #str + local chunk + if #fifo1 >= 32 or (k < l and k < 16) then + insert(fifo2, concat(fifo1)) + fifo2l, fifo1, fifo1l, k = fifo2l + fifo1l, {}, 0, F1_SIZE + end + if l > k+16 then -- also tolerate a size overrun of 16 bytes to avoid a split + chunk, str = str:sub(1,k), str:sub(k+1) + else + chunk, str = str, '' + end + insert(fifo1, chunk) + fifo1l = fifo1l + #chunk + end + if not s and socket then + s = socket + sendLine() + else + flushGarbage() + end + end + + local function receiveLine(s, line) + node.input(line) + end + + local function disconnect(s) + fifo1, fifo1l, fifo2, fifo2l, s = {}, 0, {}, 0, nil + node.output(nil) + end + + --zzz + local function zconnection(s) + print("Welcome to NodeMCU world.") + end + + socket:on("connection", zconnection) + socket:on("receive", receiveLine) + socket:on("disconnection", disconnect) + socket:on("sent", sendLine) + node.output(queueLine, 0) +end + +net.createServer(net.TCP, 180):listen(23, telnet_listener) +print("Telnet server running...\nUsage: telnet -rN ip\n") diff --git a/Mesures/temp/mario/thost b/Mesures/temp/mario/thost new file mode 100644 index 0000000..e417b33 --- /dev/null +++ b/Mesures/temp/mario/thost @@ -0,0 +1,38 @@ + + zz_host_dir2.lua zf191124.1634 + +README.md : 2841, 347247457 +_secrets_energy.lua_ : 574, 14047690 +_zremote_cmd.txt : 4416, 811416628 +b.lua : 4289, 696634446 +boot.lua : 451, 8092291 +boot2.lua : 1581, 89772835 +c.lua : 1023, 45354296 +cat.lua : 522, 9721978 +dir2.lua : 2504, 246241567 +flash_led_xfois.lua : 1131, 43977377 +head.lua : 567, 11507510 +initz.lua : 2159, 175035891 +luatool.py : 14772, 8192529118 +secrets_project.lua : 539, 12833508 +secrets_wifi.lua : 635, 15410620 +set_time.lua : 879, 31173858 +telnet_srv2.lua : 2760, 289194718 +thost : 40, 43773 +tnode : 881, 22330813 +upload_s.sh : 1913, 159132384 +upload_t.sh : 1618, 109879609 +web_srv2.lua : 2960, 297644504 +wifi_info.lua : 1604, 98582260 +wifi_init.lua : 501, 10271357 +z_index.html : 1015, 44275501 +z_page1.html : 443, 7731060 +z_page2.html : 1867, 123937742 +z_page3.html : 1415, 67091731 +z_page4.html : 1660, 90364904 +zz_host_dir.lua : 2001, 159551326 +zz_host_dir2.lua : 2020, 162623430 + + +Rappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C + diff --git a/Mesures/temp/mario/tnode b/Mesures/temp/mario/tnode new file mode 100644 index 0000000..33dbfcb --- /dev/null +++ b/Mesures/temp/mario/tnode @@ -0,0 +1,22 @@ +b.lua : 4289, 696634446 +boot.lua : 451, 8092291 +boot2.lua : 1581, 89772835 +c.lua : 1023, 45354296 +cat.lua : 522, 9721978 +dir2.lua : 2504, 246241567 +flash_led_xfois.lua : 1131, 43977377 +head.lua : 567, 11507510 +init.lua : 2159, 175035891 +secrets_project.lua : 539, 12833508 +secrets_wifi.lua : 635, 15410620 +set_time.lua : 879, 31173858 +telnet_srv2.lua : 2760, 289194718 +web_srv2.lua : 2960, 297644504 +wifi_info.lua : 1604, 98582260 +wifi_init.lua : 501, 10271357 +z_index.html : 1015, 44275501 +z_page1.html : 443, 7731060 +z_page2.html : 1867, 123937742 +z_page3.html : 1415, 67091731 +z_page4.html : 1660, 90364904 +~. diff --git a/Mesures/temp/mario/upload_s.sh b/Mesures/temp/mario/upload_s.sh new file mode 100755 index 0000000..9cad8c5 --- /dev/null +++ b/Mesures/temp/mario/upload_s.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Petit script pour télécharger facilement tout le binz via le port série +#zf191201.2323 + +# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai ! +# Il est préférable de télécharger en premier les *gros* fichiers .lua ! + +# ATTENTION: cela efface tout le NodeMCU ! + +luatool_tty="/dev/cu.wchusbserial1410" + +echo "" +read -p "ATTENTION, cela va effacer tout le NodeMCU !" +read -p "Etes-vous vraiment certain ?" + +chmod +x luatool.py + +./luatool.py --port $luatool_tty -w +./luatool.py --port $luatool_tty -l +read -p "Est-ce bien vide ?" + +./luatool.py --port $luatool_tty --bar -f z_page4.html +./luatool.py --port $luatool_tty --bar -f z_page3.html +./luatool.py --port $luatool_tty --bar -f z_page2.html +./luatool.py --port $luatool_tty --bar -f z_page1.html +./luatool.py --port $luatool_tty --bar -f z_index.html +./luatool.py --port $luatool_tty --bar -f wifi_init.lua +./luatool.py --port $luatool_tty --bar -f wifi_info.lua +./luatool.py --port $luatool_tty --bar -f web_srv2.lua +./luatool.py --port $luatool_tty --bar -f telnet_srv2.lua +./luatool.py --port $luatool_tty --bar -f set_time.lua +./luatool.py --port $luatool_tty --bar -f secrets_wifi.lua +./luatool.py --port $luatool_tty --bar -f secrets_project.lua +./luatool.py --port $luatool_tty --bar -f head.lua +./luatool.py --port $luatool_tty --bar -f flash_led_xfois.lua +./luatool.py --port $luatool_tty --bar -f dir2.lua +./luatool.py --port $luatool_tty --bar -f cat.lua +#./luatool.py --port $luatool_tty --bar -f c.lua +./luatool.py --port $luatool_tty --bar -f boot2.lua +./luatool.py --port $luatool_tty --bar -f boot.lua +#./luatool.py --port $luatool_tty --bar -f b.lua + +./luatool.py --port $luatool_tty -l +read -p "Pas eu d'erreur, on part à fond avec le init.lua ?" + +./luatool.py --port $luatool_tty --bar -f initz.lua -t init.lua +./luatool.py --port $luatool_tty -l +echo -e "\nC'est tout bon ;-)" diff --git a/Mesures/temp/mario/upload_t.sh b/Mesures/temp/mario/upload_t.sh new file mode 100755 index 0000000..f379ded --- /dev/null +++ b/Mesures/temp/mario/upload_t.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Petit script pour télécharger facilement tout le binz +#zf191028.1459 + +# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai ! +# Il est préférable de télécharger en premier les *gros* fichiers .lua ! + +# ATTENTION: cela efface tout le NodeMCU ! + +luatool_tty="/dev/cu.wchusbserial1410" + +echo "" +read -p "ATTENTION, cela va effacer tout le NodeMCU !" +read -p "Etes-vous vraiment certain ?" + +chmod +x luatool.py + +./luatool.py --port $luatool_tty -w +./luatool.py --port $luatool_tty -l +read -p "Est-ce bien vide ?" + +./luatool.py --port $luatool_tty --bar --delay 0.06 -f telnet_srv2.lua +./luatool.py --port $luatool_tty --bar --delay 0.03 -f head.lua +./luatool.py --port $luatool_tty --bar --delay 0.03 -f flash_led_xfois.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_info.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_cli_start.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_cli_conf.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_ap_stop.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f secrets_energy.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f dir.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f cat.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f boot2.lua +./luatool.py --port $luatool_tty --bar --delay 0.001 -f boot.lua + +./luatool.py --port $luatool_tty -l +read -p "Pas eu d'erreur, on part à fond avec le init.lua ?" +./luatool.py --port $luatool_tty --bar --delay 0.001 -f initz.lua -t init.lua +echo -e "\nC'est tout bon ;-)" diff --git a/Mesures/temp/mario/web_ide2.lua b/Mesures/temp/mario/web_ide2.lua new file mode 100644 index 0000000..16d00f2 --- /dev/null +++ b/Mesures/temp/mario/web_ide2.lua @@ -0,0 +1,159 @@ +-- Petit WEB IDE tout simple autonome +-- ATTENTION: tourne sur le port 88 ! + +print("\n _web_ide2.lua zf181210.1516 \n") + +--[[ +XChip's NodeMCU IDE + +Create, Edit and run NodeMCU files using your webbrowser. +Examples: +http:/// will list all the files in the MCU +http:///newfile.lua displays the file on your browser +http:///newfile.lua?edit allows to creates or edits the specified script in your browser +http:///newfile.lua?run it will run the specified script and will show the returned value +]]-- + +srv=net.createServer(net.TCP) +srv:listen(88,function(conn) + + local rnrn=0 + local Status = 0 + local DataToGet = 0 + local method="" + local url="" + local vars="" + + conn:on("receive",function(conn,payload) + + if Status==0 then + _, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP") + print(method, url, vars) + end + + if method=="POST" then + + if Status==0 then + --print("status", Status) + _,_,DataToGet, payload = string.find(payload, "Content%-Length: (%d+)(.+)") + if DataToGet~=nil then + DataToGet = tonumber(DataToGet) + --print(DataToGet) + rnrn=1 + Status = 1 + else + print("bad length") + end + end + + -- find /r/n/r/n + if Status==1 then + --print("status", Status) + local payloadlen = string.len(payload) + local mark = "\r\n\r\n" + local i + for i=1, payloadlen do + if string.byte(mark, rnrn) == string.byte(payload, i) then + rnrn=rnrn+1 + if rnrn==5 then + payload = string.sub(payload, i+1,payloadlen) + file.open(url, "w") + file.close() + Status=2 + break + end + else + rnrn=1 + end + end + if Status==1 then + return + end + end + + if Status==2 then + --print("status", Status) + if payload~=nil then + DataToGet=DataToGet-string.len(payload) + --print("DataToGet:", DataToGet, "payload len:", string.len(payload)) + file.open(url, "a+") + file.write(payload) + file.close() + else + conn:send("HTTP/1.1 200 OK\r\n\r\nERROR") + Status=0 + end + + if DataToGet==0 then + conn:send("HTTP/1.1 200 OK\r\n\r\nOK") + Status=0 + end + end + + return + end + + DataToGet = -1 + + if url == "favicon.ico" then + conn:send("HTTP/1.1 404 file not found") + return + end + + conn:send("HTTP/1.1 200 OK\r\n\r\n") + + -- it wants a file in particular + if url~="" and vars=="" then + DataToGet = 0 + return + end + + conn:send("

NodeMCU IDE

") + + if vars=="edit" then + conn:send("") + conn:send("

Back to file list\n") + conn:send("

run") + conn:send("



") + end + + if vars=="run" then + conn:send("") + local st, result=pcall(dofile, url) + conn:send(tostring(result)) + conn:send("") + end + + if url=="" then + local l = file.list(); + for k,v in pairs(l) do + conn:send(""..k..", size:"..v.."
") + end + end + + conn:send("") + + end) + conn:on("sent",function(conn) + if DataToGet>=0 and method=="GET" then + if file.open(url, "r") then + file.seek("set", DataToGet) + local line=file.read(512) + file.close() + if line then + conn:send(line) + DataToGet = DataToGet + 512 + + if (string.len(line)==512) then + return + end + end + end + end + + conn:close() + end) +end) +print("listening, free:", node.heap()) + diff --git a/Mesures/temp/mario/web_srv2.lua b/Mesures/temp/mario/web_srv2.lua new file mode 100644 index 0000000..274ba82 --- /dev/null +++ b/Mesures/temp/mario/web_srv2.lua @@ -0,0 +1,87 @@ +-- petit script de serveur WEB avec Active Server Page ZYX + +print("\n web_srv2.lua zf191124.2225 \n") + +ztemp=12 + +-- dû refaire la commande file.readline car elle bug quand ligne longue +function zread_line() + local zline = "" + while true do + local t = file_web:read(1) if t == nil then return end + zline = zline..t + if t == "\n" then return zline end + end +end + +-- envoie sur le port ouvert mais depuis l'environnement global ! +function zout(zstring) + zzclient:send(zstring) -- envoie le résultat du code lua inline +end + +-- envoie un fichier HTML sur le port. ATTENTION: longueur de la ligne maximale de 1'024 bytes ! +function send_file(zclient, zfilename) + print("start send html...") + zclient:send("HTTP/1.1 200 OK\n") + zclient:send("Content-Type: text/html\n\n") + zzclient = zclient -- export le port sur l'environnement global ! + if zfilename == "" then zfilename = "z_index.html" end + file_web = file.open(zfilename, "r") + if file_web then + repeat + local line = zread_line() + if line then + if string.find(line, "<%%") then +-- print("start lua...") + flag_lua_code = true -- bascule sur le code lua inline + lua_code = "" + elseif string.find(line, "%%>") then +-- print("stop lua...") + flag_lua_code = false -- revient sur le code HTML +-- print("Et voici le code lua inline:\n"..lua_code) + loadstring(lua_code)() --on exécute ici le code lua inline ! + elseif flag_lua_code then +-- print(line) + lua_code = lua_code..line -- récupère le code lua inline + else +-- print(line) + zclient:send(line) -- envoie le code HTML + end + end + until not line + file_web:close() file_web = nil + else + zclient:send("

"..zfilename.." not found - 404 error

Home
") + end +end + + +srv = net.createServer() +srv:listen(80, function(conn) + conn:on("receive", function(client, request) + _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP") + + print("zrequest: \n---\n"..request.."---") + +-- print("method: ", method) print("path: ", path) print("vars: ", vars) + + if not string.find(request, "/favicon.ico") then + print("coucou") + if (method == nil) then + _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP") + end + print("method: ", method) print("path: ", path) print("vars: ", vars) + _GET = {} + if (vars ~= nil) then + for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do + _GET[k] = v + print(k..": "..v) + end + end + file_html=string.gsub(path, "/", "") + -- print("file_html: ",file_html) + send_file(client, file_html) + end + end) + conn:on("sent", function(c) c:close() end) +end) diff --git a/Mesures/temp/mario/wifi_info.lua b/Mesures/temp/mario/wifi_info.lua new file mode 100644 index 0000000..2a0066b --- /dev/null +++ b/Mesures/temp/mario/wifi_info.lua @@ -0,0 +1,44 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf191030.2017 \n") + +function wifi_info() + local zmodewifi=wifi.getmode() + + --wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP + + if zmodewifi == wifi.NULLMODE then + print("WIFI OFF") + elseif zmodewifi == wifi.STATION then + print("WIFI mode CLI") + print("Connected IP:\n",wifi.sta.getip()) + local sta_config=wifi.sta.getconfig(true) + print("Current client config:") + print("\tssid:", sta_config.ssid) + print("\tpassword:", sta_config.pwd) + print("\tbssid:", sta_config.bssid) + elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP\n") + print("AP IP: ", wifi.ap.getip()) + print("Current AP config:") + local ap_config=wifi.ap.getconfig(true) + print("\tssid:", ap_config.ssid) + print("\tpassword:", ap_config.pwd) + print("\tbssid:", wifi.ap.getmac()) + elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP\n") + print("CLIENT IP:\n",wifi.sta.getip()) + local sta_config=wifi.sta.getconfig(true) + print("Current CLIENT config:") + print("\tssid:", sta_config.ssid) + print("\tpassword:", sta_config.pwd) + print("\tbssid:", sta_config.bssid.."\n") + print("AP IP: ", wifi.ap.getip()) + print("Current AP config:") + local ap_config=wifi.ap.getconfig(true) + print("\tssid:", ap_config.ssid) + print("\tpassword:", ap_config.pwd) + print("\tbssid:", wifi.ap.getmac()) + end +end +wifi_info() + diff --git a/Mesures/temp/mario/wifi_init.lua b/Mesures/temp/mario/wifi_init.lua new file mode 100644 index 0000000..107fddf --- /dev/null +++ b/Mesures/temp/mario/wifi_init.lua @@ -0,0 +1,17 @@ +-- Petit script pour initaliser la couche WIFI + +function wifi_init() + print("\n wifi_init.lua zf191201.2329 \n") + -- charge les secrets pour le wifi + f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end + + wifi.setmode(wifi.STATION,true) +-- wifi.setmode(wifi.STATIONAP,true) +-- wifi.ap.config({ ssid = ap_ssid.." "..wifi.ap.getmac(), pwd = ap_pwd, save=true }) + + wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true} + wifi.sta.autoconnect(1) + wifi.sta.connect() +end + +wifi_init() diff --git a/Mesures/temp/mario/z_index.html b/Mesures/temp/mario/z_index.html new file mode 100644 index 0000000..df41ad5 --- /dev/null +++ b/Mesures/temp/mario/z_index.html @@ -0,0 +1,25 @@ + + + + + + ESP8266 home page + + + +

ESP8266 home page 191124.2332

+

Différentes pages HTML:

+

+ Page 1, affichage de la température dynamique en code Lua inline.
+ Page 2, tableau dynamique écrit en Lua inline.
+ Page 3, affichage du capteur non linéaire corrigé.
+ Page 4, test de récupération d'arguments pour un web service.
+ API HUB Temp,test d'un web service hub de mesures de température.
+ Affichage des températures, affiche les températures mesurées.
+ WIFI configuration.
+ +
Page qui n'existe pas !
+

+ + + diff --git a/Mesures/temp/mario/z_page1.html b/Mesures/temp/mario/z_page1.html new file mode 100644 index 0000000..c0bd757 --- /dev/null +++ b/Mesures/temp/mario/z_page1.html @@ -0,0 +1,26 @@ + + + + + + ESP8266 page 1 + + + +

ESP8266 page 1 190127.1445

+
+ Coucou c'est la page 1 !
+ Retour à la home page...


+ +La température est: + +<% +ztemp=ztemp+1 +zout(ztemp.."°C") +%> + +
Mais il fait encore trop froid !
+ + + + diff --git a/Mesures/temp/mario/z_page2.html b/Mesures/temp/mario/z_page2.html new file mode 100644 index 0000000..1516626 --- /dev/null +++ b/Mesures/temp/mario/z_page2.html @@ -0,0 +1,51 @@ + + + + + + ESP8266 page 2 + + + +

ESP8266 page 2 190127.1449

+
+ Coucou c'est la page 2 !
+ Retour à la home page...


+ + Voici un tableau dynamique écrit en Lua inline.

+ + Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.
+ Les données du tableau viennent du NodeMCU !

+ + <% + -- création du tableau sur le NodeMCUjuste juste pour la démo ici ! + zmac_adrs={} + zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf", ["zrssi"]=45, ["ztime"]="12:03:36"} + zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie", ["zrssi"]=50, ["ztime"]="14:23:46"} + zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf", ["zrssi"]=40, ["ztime"]="11:53:16"} + zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman", ["zrssi"]=55, ["ztime"]="17:07:23"} + %> + + + + + + <% + for k, v in pairs(zmac_adrs) do + zout("\n") + zout("\t\n") + zout("\t\n") + zout("\t\n") + zout("\t\n") + zout("\n") + end + %> +
MACNameRSSITime
" .. k .. "" .. tostring(zmac_adrs[k]["zname"]) .. "" .. tostring(zmac_adrs[k]["zrssi"]) .. "" .. tostring(zmac_adrs[k]["ztime"]) .. "
+ + <% + -- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici ! + zmac_adrs=nil + %> + + + diff --git a/Mesures/temp/mario/z_page3.html b/Mesures/temp/mario/z_page3.html new file mode 100644 index 0000000..6abc4ed --- /dev/null +++ b/Mesures/temp/mario/z_page3.html @@ -0,0 +1,50 @@ + + + + + + ESP8266 page 3 + + + +

ESP8266 page 3 190505.1156

+
+ Coucou c'est la page 3 !
+ Retour à la home page...


+ + Voici le résultat du capteur non linéaire corrigé avec une table + d'interpolation dans un fichier .csv sur la flash.

+ + Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.
+ Les données viennent du NodeMCU !

+ + <% + zout("Il reste: "..node.heap().." de RAM !

\n") + %> + + <% + zx0=83 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est "..zy0.."
") + %> + + <% + zx0=91 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est "..zy0.."
") + %> + + <% + zx0=100 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est "..zy0.."
") + %> + +
Yeah... cela fonctionne vachement bien !

+ + <% + zout("Il reste: "..node.heap().." de RAM !

\n") + %> + + + diff --git a/Mesures/temp/mario/z_page4.html b/Mesures/temp/mario/z_page4.html new file mode 100644 index 0000000..49f7086 --- /dev/null +++ b/Mesures/temp/mario/z_page4.html @@ -0,0 +1,53 @@ + + + + + + ESP8266 page 3 + + + +

ESP8266 page 4 190726.1955

+
+ Web service concentrateur de mesures de température !
+ Retour à la home page...


+ + Test d'un web service qui fonctionne avec l'Active Server Page ZYX.

+ + Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.
+ Les données viennent du NodeMCU !

+ + <% + zout("Il reste: "..node.heap().." de RAM !

\n") + %> + + Les arguments du web service (GET) sont:

+ <% + if (vars ~= nil) then + zout("
vars: "..vars.."
") + for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do + _GET[k] = v + zout(k..": "..v.."
") + if k == "field1" then + ztemp1_conc = v + elseif k == "field2" then + ztemp2_conc = v + elseif k == "field3" then + ztemp3_conc = v + end + end + end + zout("
Les températures récupérées sont: "..ztemp1_conc..", "..ztemp2_conc..", "..ztemp3_conc) + %> + + + + +

Yeah... cela fonctionne vachement bien !

+ + <% + zout("Il reste: "..node.heap().." de RAM !

\n") + %> + + + diff --git a/Mesures/temp/mario/zz_host_dir.lua b/Mesures/temp/mario/zz_host_dir.lua new file mode 100755 index 0000000..23e75ce --- /dev/null +++ b/Mesures/temp/mario/zz_host_dir.lua @@ -0,0 +1,67 @@ +#!/usr/local/bin/lua5.1 +-- script lua à faire tourner sur le host pour la taille de tous les fichiers +-- du dossier en cours, donc PAS sur le NodeMCU ! +-- source: https://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua (30%) + +-- usage dans la console: +-- ./zz_host_dir.lua +--[[ +./zz_host_dir.lua > thost +]] +-- usage dans Atom editor +-- il faut installer ceci: https://atom.io/packages/compare-files +-- puis sélectionner les deux fichiers dans l'explorateur à gauche puis CTRL+CMD+C + + +print("\n zz_host_dir.lua zf191124.1646 \n") + +function calc_chksum_file(name_file) + size_file = 0 chksum_file = 0 + local f = io.open(name_file, "r") +-- local f = file.open(name_file, "r") + while true do + local t = f:read(1) if t == nil then break end +-- chksum_file = chksum_file + size_file * string.byte(t) + size_file = size_file + 1 +-- if size_file%100 == 0 then uart.write(0,".") end + end + f:close() +-- print(name_file) +end + +function dirfile(k) + calc_chksum_file(k) + print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file) + size_file=nil chksum_file=nil k=nil +end + +function dir() + local zdir={} + local pfile = io.popen("ls -1r *.lua *.html") + for k in pfile:lines() do +-- local pfile = file.list() +-- for k,v in pairs(pfile) do + calc_chksum_file(k) + if (size_file ~= 1) and (chksum_file ~= 1) then + zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file + end + end + pfile:close() + table.sort(zdir) + for i=1, #zdir do + print(zdir[i]) + end + size_file=nil chksum_file=nil k=nil +end + +dir() +print("\n\nRappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C\n") + +--[[ +dir() +dirfile("dir2.lua") + +for k,v in pairs(_G) do print(k,v) end + +status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end +]] diff --git a/Mesures/temp/mario/zz_host_dir2.lua b/Mesures/temp/mario/zz_host_dir2.lua new file mode 100755 index 0000000..13cf1bc --- /dev/null +++ b/Mesures/temp/mario/zz_host_dir2.lua @@ -0,0 +1,67 @@ +#!/usr/local/bin/lua5.1 +-- script lua à faire tourner sur le host pour calculer le checksum de tous les fichiers +-- du dossier en cours, donc PAS sur le NodeMCU ! +-- source: https://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua (30%) + +-- usage dans la console: +-- ./zz_host_dir2.lua +--[[ +./zz_host_dir2.lua > thost +]] +-- usage dans Atom editor +-- il faut installer ceci: https://atom.io/packages/compare-files +-- puis sélectionner les deux fichiers dans l'explorateur à gauche puis CTRL+CMD+C + + +print("\n zz_host_dir2.lua zf191124.1634 \n") + +function calc_chksum_file(name_file) + size_file = 1 chksum_file = 0 + local f = io.open(name_file, "r") +-- local f = file.open(name_file, "r") + while true do + local t = f:read(1) if t == nil then break end + chksum_file = chksum_file + size_file * string.byte(t) + size_file = size_file + 1 +-- if size_file%100 == 0 then uart.write(0,".") end + end + f:close() +-- print(name_file) +end + +function dirfile(k) + calc_chksum_file(k) + print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file) + size_file=nil chksum_file=nil k=nil +end + +function dir() + local zdir={} + local pfile = io.popen("ls -1r ") + for k in pfile:lines() do +-- local pfile = file.list() +-- for k,v in pairs(pfile) do + calc_chksum_file(k) + if (size_file ~= 1) and (chksum_file ~= 1) then + zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file + end + end + pfile:close() + table.sort(zdir) + for i=1, #zdir do + print(zdir[i]) + end + size_file=nil chksum_file=nil k=nil +end + +dir() +print("\n\nRappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C\n") + +--[[ +dir() +dirfile("dir2.lua") + +for k,v in pairs(_G) do print(k,v) end + +status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end +]]