diff --git a/Genefunc/AD9833/README.md b/Genefunc/AD9833/README.md new file mode 100644 index 0000000..e034f1f --- /dev/null +++ b/Genefunc/AD9833/README.md @@ -0,0 +1,15 @@ +# AD9833, générateur de fonctions sinus, triangle et carré + +## Essais de pilotage d'un AD9833 via le bus SPI du NodeMCU + +Il n'y a pas de lib NodeMCU pour le AD9833, mais c'est relativement simple de le piloter par le bus SPI + + + + + + + + + +zf190504.1126 diff --git a/Genefunc/AD9833/boot.lua b/Genefunc/AD9833/boot.lua new file mode 100644 index 0000000..917e172 --- /dev/null +++ b/Genefunc/AD9833/boot.lua @@ -0,0 +1,32 @@ +-- Scripts à charger après le boot pour démarrer son appli + +print("\n boot.lua zf19422.1102 \n") + +function heartbeat() + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + flash_led_xfois() + boottimer1=tmr.create() + tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) +end + +f= "led_rgb.lua" if file.exists(f) then dofile(f) end +f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +f= "telnet_srv2.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 +--f= "set_time.lua" if file.exists(f) then dofile(f) end +--f= "dsleep.lua" if file.exists(f) then dofile(f) end +f= "a_no_linear.lua" if file.exists(f) then dofile(f) end + +f=nil +heartbeat=nil +--heartbeat() + + + + diff --git a/Genefunc/flash_led_xfois.lua b/Genefunc/AD9833/flash_led_xfois.lua similarity index 100% rename from Genefunc/flash_led_xfois.lua rename to Genefunc/AD9833/flash_led_xfois.lua diff --git a/Genefunc/goodies/a_tst_variables.lua b/Genefunc/AD9833/goodies/a_tst_variables.lua similarity index 100% rename from Genefunc/goodies/a_tst_variables.lua rename to Genefunc/AD9833/goodies/a_tst_variables.lua diff --git a/Genefunc/goodies/rm_files.lua b/Genefunc/AD9833/goodies/rm_files.lua similarity index 100% rename from Genefunc/goodies/rm_files.lua rename to Genefunc/AD9833/goodies/rm_files.lua diff --git a/Genefunc/goodies/wifi_off.lua b/Genefunc/AD9833/goodies/wifi_off.lua similarity index 100% rename from Genefunc/goodies/wifi_off.lua rename to Genefunc/AD9833/goodies/wifi_off.lua diff --git a/Genefunc/initz.lua b/Genefunc/AD9833/initz.lua similarity index 100% rename from Genefunc/initz.lua rename to Genefunc/AD9833/initz.lua diff --git a/Genefunc/AD9833/led_rgb.lua b/Genefunc/AD9833/led_rgb.lua new file mode 100644 index 0000000..7a5d396 --- /dev/null +++ b/Genefunc/AD9833/led_rgb.lua @@ -0,0 +1,37 @@ +-- Scripts juste pour allumer ou éteindre une LED sur un ruban RGB +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n led_rgb.lua zf190303.1436 \n") + +nbleds=3 +ws2812.init() +myLedStrip = ws2812.newBuffer(nbleds, 3) + +function RGB_clear() + myLedStrip:fill(0, 0, 0) ws2812.write(myLedStrip) +end + +function RGB_reform(R1, G1, B1) --conversion de RGB à BRG + rR1=B1 rG1=R1 rB1=G1 +end + +function zled_rgb(num_led, R1, G1, B1, zpower) + RGB_reform(R1, G1, B1) + myLedStrip:set(num_led, rR1*zpower, rG1*zpower, rB1*zpower) + ws2812.write(myLedStrip) +end + +function zled_write() + ws2812.write(myLedStrip) +end + + +RGB_clear() + +--[[ +zled_rgb(1,255,0,0,1) +zled_rgb(2,0,255,0,1) +zled_rgb(2,0,255,0,0.05) +zled_rgb(3,0,0,255,1) +]] diff --git a/Genefunc/set_time.lua b/Genefunc/AD9833/set_time.lua similarity index 100% rename from Genefunc/set_time.lua rename to Genefunc/AD9833/set_time.lua diff --git a/Genefunc/AD9833/simulation/Capture d’écran 2019-04-19 à 22.20.27.png b/Genefunc/AD9833/simulation/Capture d’écran 2019-04-19 à 22.20.27.png new file mode 100644 index 0000000..f906daa Binary files /dev/null and b/Genefunc/AD9833/simulation/Capture d’écran 2019-04-19 à 22.20.27.png differ diff --git a/Genefunc/AD9833/simulation/Capture d’écran 2019-04-20 à 09.05.41.png b/Genefunc/AD9833/simulation/Capture d’écran 2019-04-20 à 09.05.41.png new file mode 100644 index 0000000..2307d8c Binary files /dev/null and b/Genefunc/AD9833/simulation/Capture d’écran 2019-04-20 à 09.05.41.png differ diff --git a/Genefunc/AD9833/simulation/échelle sonde.xlsx b/Genefunc/AD9833/simulation/échelle sonde.xlsx new file mode 100644 index 0000000..21a2e7d Binary files /dev/null and b/Genefunc/AD9833/simulation/échelle sonde.xlsx differ diff --git a/Genefunc/AD9833/t1.csv b/Genefunc/AD9833/t1.csv new file mode 100644 index 0000000..7dc8514 --- /dev/null +++ b/Genefunc/AD9833/t1.csv @@ -0,0 +1,27 @@ +ohm,% +33,100 +36,96.77419355 +41,92.74193548 +45,88.70967742 +52,84.67741935 +56,80.64516129 +61,76.61290323 +67,72.58064516 +72,68.5483871 +79,64.51612903 +83,60.48387097 +91,56.4516129 +97,52.41935484 +104,48.38709677 +112,44.35483871 +117,40.32258065 +121,36.29032258 +128,32.25806452 +132,28.22580645 +139,24.19354839 +150,20.16129032 +166,16.12903226 +191,12.09677419 +207,8.064516129 +224,4.032258065 +240,0 \ No newline at end of file diff --git a/Genefunc/telnet_srv2.lua b/Genefunc/AD9833/telnet_srv2.lua similarity index 100% rename from Genefunc/telnet_srv2.lua rename to Genefunc/AD9833/telnet_srv2.lua diff --git a/Genefunc/web_ide2.lua b/Genefunc/AD9833/web_ide2.lua similarity index 100% rename from Genefunc/web_ide2.lua rename to Genefunc/AD9833/web_ide2.lua diff --git a/Genefunc/AD9833/web_srv2.lua b/Genefunc/AD9833/web_srv2.lua new file mode 100644 index 0000000..a7b5953 --- /dev/null +++ b/Genefunc/AD9833/web_srv2.lua @@ -0,0 +1,77 @@ +-- petit script de serveur WEB avec Active Server Page ZYX + +print("\n web_srv2.lua zf190422.1135 \n") + +ztemp=12 + +-- 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 = file_web:read('\n') + 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 + 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("request: \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/Genefunc/wifi_ap_start.lua b/Genefunc/AD9833/wifi_ap_start.lua similarity index 100% rename from Genefunc/wifi_ap_start.lua rename to Genefunc/AD9833/wifi_ap_start.lua diff --git a/Genefunc/wifi_cli_conf.lua b/Genefunc/AD9833/wifi_cli_conf.lua similarity index 100% rename from Genefunc/wifi_cli_conf.lua rename to Genefunc/AD9833/wifi_cli_conf.lua diff --git a/Genefunc/wifi_cli_start.lua b/Genefunc/AD9833/wifi_cli_start.lua similarity index 100% rename from Genefunc/wifi_cli_start.lua rename to Genefunc/AD9833/wifi_cli_start.lua diff --git a/Genefunc/wifi_get_ip.lua b/Genefunc/AD9833/wifi_get_ip.lua similarity index 100% rename from Genefunc/wifi_get_ip.lua rename to Genefunc/AD9833/wifi_get_ip.lua diff --git a/Genefunc/wifi_info.lua b/Genefunc/AD9833/wifi_info.lua similarity index 100% rename from Genefunc/wifi_info.lua rename to Genefunc/AD9833/wifi_info.lua diff --git a/Genefunc/AD9833/z_index.html b/Genefunc/AD9833/z_index.html new file mode 100644 index 0000000..dd689c8 --- /dev/null +++ b/Genefunc/AD9833/z_index.html @@ -0,0 +1,20 @@ + + + + + + ESP8266 home page + + + +

ESP8266 home page 190422.1052

+

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 qui n'existe pas !
+

+ + + diff --git a/Genefunc/AD9833/z_page1.html b/Genefunc/AD9833/z_page1.html new file mode 100644 index 0000000..c0bd757 --- /dev/null +++ b/Genefunc/AD9833/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/Genefunc/AD9833/z_page2.html b/Genefunc/AD9833/z_page2.html new file mode 100644 index 0000000..1516626 --- /dev/null +++ b/Genefunc/AD9833/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/Genefunc/AD9833/z_page3.html b/Genefunc/AD9833/z_page3.html new file mode 100644 index 0000000..f0be1e9 --- /dev/null +++ b/Genefunc/AD9833/z_page3.html @@ -0,0 +1,51 @@ + + + + + + ESP8266 page 3 + + + +

ESP8266 page 3 190422.1200

+
+ 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/Genefunc/a_gene1.lua b/Genefunc/serout/a_gene1.lua similarity index 100% rename from Genefunc/a_gene1.lua rename to Genefunc/serout/a_gene1.lua diff --git a/Genefunc/boot.lua b/Genefunc/serout/boot.lua similarity index 100% rename from Genefunc/boot.lua rename to Genefunc/serout/boot.lua diff --git a/Genefunc/serout/flash_led_xfois.lua b/Genefunc/serout/flash_led_xfois.lua new file mode 100644 index 0000000..ffea9b0 --- /dev/null +++ b/Genefunc/serout/flash_led_xfois.lua @@ -0,0 +1,37 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off + +function flash_led_xfois() + print("\n flash_led_xfois.lua zf190310.1533 \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) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end + end + +-- xfois =2 +-- blink_LED () +end + + + + diff --git a/Genefunc/serout/goodies/a_tst_variables.lua b/Genefunc/serout/goodies/a_tst_variables.lua new file mode 100644 index 0000000..bbae700 --- /dev/null +++ b/Genefunc/serout/goodies/a_tst_variables.lua @@ -0,0 +1,6 @@ +-- Scripts pour afficher toutes les variables et fonctions en cours dans le système + +print("\n a_tst_variable.lua zf190310.1525 \n") + +for n in pairs (_G) do print(n) end + diff --git a/Genefunc/serout/goodies/rm_files.lua b/Genefunc/serout/goodies/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/Genefunc/serout/goodies/rm_files.lua @@ -0,0 +1,12 @@ +-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU + +print("\n rm_files.lua zf180907.1511 \n") + + +l=file.list() i=0 +for k,v in pairs(l) do + i=i+v + file.remove(k) +end +print("-------------------------------") +print("\nC'est tout effaced :-) \n") diff --git a/Genefunc/serout/goodies/wifi_off.lua b/Genefunc/serout/goodies/wifi_off.lua new file mode 100644 index 0000000..c1c7235 --- /dev/null +++ b/Genefunc/serout/goodies/wifi_off.lua @@ -0,0 +1,9 @@ +-- Déconnecte le WIFI +print("\n wifi_off.lua zf180822.0959 \n") + +wifi.setmode(wifi.NULLMODE) + +--[[ +print(wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP) +print(wifi.getmode()) +]] diff --git a/Genefunc/serout/initz.lua b/Genefunc/serout/initz.lua new file mode 100644 index 0000000..771f253 --- /dev/null +++ b/Genefunc/serout/initz.lua @@ -0,0 +1,52 @@ +--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 zf190310.1549 \n") + +zswitch=3 --switch flash +gpio.mode(zswitch, gpio.INT, gpio.PULLUP) + +function hvbouton() +-- gpio.trig(zswitch, "none") + tmr.unregister(initalarme) + f= "boot.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() + tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function() + f= "boot.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 +elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 6 then + print("external reset") + second_chance() +-- f= "boot.lua" if file.exists(f) then dofile(f) end +else + print("autre raison") + second_chance() +end + diff --git a/Genefunc/serout/set_time.lua b/Genefunc/serout/set_time.lua new file mode 100644 index 0000000..748cc95 --- /dev/null +++ b/Genefunc/serout/set_time.lua @@ -0,0 +1,29 @@ +-- 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 zf190217.1426 \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) + 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() +print(ztime_format(rtctime.get())) + diff --git a/Genefunc/serout/telnet_srv2.lua b/Genefunc/serout/telnet_srv2.lua new file mode 100644 index 0000000..821358c --- /dev/null +++ b/Genefunc/serout/telnet_srv2.lua @@ -0,0 +1,87 @@ +-- 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 zf181215.1326 \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 + + 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/Genefunc/serout/web_ide2.lua b/Genefunc/serout/web_ide2.lua new file mode 100644 index 0000000..16d00f2 --- /dev/null +++ b/Genefunc/serout/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/Genefunc/web_srv2.lua b/Genefunc/serout/web_srv2.lua similarity index 100% rename from Genefunc/web_srv2.lua rename to Genefunc/serout/web_srv2.lua diff --git a/Genefunc/serout/wifi_ap_start.lua b/Genefunc/serout/wifi_ap_start.lua new file mode 100644 index 0000000..f7ade0d --- /dev/null +++ b/Genefunc/serout/wifi_ap_start.lua @@ -0,0 +1,19 @@ +-- Démarre le WIFI en mode AP + +function wifi_ap_start() + print("\n wifi_ap_start.lua zf190310.1511 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) + elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" }) + --f= "wifi_info.lua" if file.exists(f) then dofile(f) end +end + +wifi_ap_start() +wifi_ap_start=nil diff --git a/Genefunc/serout/wifi_cli_conf.lua b/Genefunc/serout/wifi_cli_conf.lua new file mode 100644 index 0000000..99b5767 --- /dev/null +++ b/Genefunc/serout/wifi_cli_conf.lua @@ -0,0 +1,20 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +function wifi_cli_conf() + print("\n wifi_cli_conf.lua zf190310.1527 \n") + + --credentials par défaut + --cli_ssid="3g-s7" + cli_ssid="3G-zf" + cli_pwd="12234567" + + --ses propre credentials + f= "credentials.lua" if file.exists(f) then dofile(f) end + + wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true} +end + +wifi_cli_conf() +wifi_cli_conf=nil +cli_ssid=nil +cli_pwd=nil diff --git a/Genefunc/serout/wifi_cli_start.lua b/Genefunc/serout/wifi_cli_start.lua new file mode 100644 index 0000000..045957e --- /dev/null +++ b/Genefunc/serout/wifi_cli_start.lua @@ -0,0 +1,20 @@ +-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM + +function wifi_cli_start() + print("\n wifi_cli_start.lua zf190310.1519 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode CLI only") + wifi.setmode(wifi.STATION) + elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.sta.autoconnect(1) + wifi.sta.connect() + --f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end +end + +wifi_cli_start() +wifi_cli_start=nil diff --git a/Genefunc/serout/wifi_get_ip.lua b/Genefunc/serout/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/Genefunc/serout/wifi_get_ip.lua @@ -0,0 +1,12 @@ +-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi +print("\n wifi_get_ip.lua zf181119.2318 \n") + +wifitimer1=tmr.create() +tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + else + tmr.stop(wifitimer1) + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + end +end) diff --git a/Genefunc/serout/wifi_info.lua b/Genefunc/serout/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/Genefunc/serout/wifi_info.lua @@ -0,0 +1,31 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf181119.0014 \n") + +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()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP") + print("AP MAC:\n",wifi.ap.getmac()) + print("AP IP:\n",wifi.ap.getip()) + print("AP Connect:\n",wifi.ap.getconfig()) +elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end + print("AP MAC: "..wifi.ap.getmac()) + print("AP IP: "..wifi.ap.getip()) +end diff --git a/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua index 828e65d..9664a47 100644 --- a/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua +++ b/LED_RGB_WS2812/guirlandes noël/a_guirlande.lua @@ -2,11 +2,11 @@ -- tout sur la couleur: https://www.w3schools.com/colors/default.asp -- roue des couleurs: https://iro.js.org/?ref=oldsite -print("\n a_guirlande.lua zf181216.0131 \n") +print("\n a_guirlande.lua zf190428.1824 \n") znbleds_max=300 znbleds=300 -zstep=5 +zstep=3 zpower=1 zleds={} diff --git a/LED_RGB_WS2812/guirlandes noël/boot.lua b/LED_RGB_WS2812/guirlandes noël/boot.lua index eb5bbdd..6c7e8fb 100644 --- a/LED_RGB_WS2812/guirlandes noël/boot.lua +++ b/LED_RGB_WS2812/guirlandes noël/boot.lua @@ -1,6 +1,6 @@ -- Scripts à charger après le boot pour démarrer son appli -print("\n boot.lua zf181216.0028 \n") +print("\n boot.lua zf190428.1823 \n") function heartbeat() f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end @@ -11,11 +11,12 @@ function heartbeat() end) end -f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end -f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end -f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end -f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end -f= "web_ide2.lua" if file.exists(f) then dofile(f) end +--f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end +f= "wifi_stop.lua" if file.exists(f) then dofile(f) end +--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end +--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +--f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end +--f= "web_ide2.lua" if file.exists(f) then dofile(f) end --f= "az_init_led.lua" if file.exists(f) then dofile(f) end --f= "webleds.lua" if file.exists(f) then dofile(f) end f= "a_guirlande.lua" if file.exists(f) then dofile(f) end diff --git a/No_linear/simulation/Capture d’écran 2019-04-19 à 22.20.27.png b/No_linear/simulation/Capture d’écran 2019-04-19 à 22.20.27.png new file mode 100644 index 0000000..f906daa Binary files /dev/null and b/No_linear/simulation/Capture d’écran 2019-04-19 à 22.20.27.png differ diff --git a/No_linear/simulation/Capture d’écran 2019-04-20 à 09.05.41.png b/No_linear/simulation/Capture d’écran 2019-04-20 à 09.05.41.png new file mode 100644 index 0000000..2307d8c Binary files /dev/null and b/No_linear/simulation/Capture d’écran 2019-04-20 à 09.05.41.png differ diff --git a/No_linear/simulation/échelle sonde.xlsx b/No_linear/simulation/échelle sonde.xlsx new file mode 100644 index 0000000..21a2e7d Binary files /dev/null and b/No_linear/simulation/échelle sonde.xlsx differ diff --git a/Tests/a_tst1_serial.lua b/Tests/a_tst1_serial.lua new file mode 100644 index 0000000..4458540 --- /dev/null +++ b/Tests/a_tst1_serial.lua @@ -0,0 +1,17 @@ +-- Juste pour tester le port série, envoie le caractères U toute les seconde +--- U en binaire c'est 1010101, parfait pour le 'voir' avec un oscilloscope + +print("\n a_tst1_serial.lua zf190504.1316 \n") + + +test_1=tmr.create() +tmr.alarm(test_1, 1*1000, tmr.ALARM_AUTO, function() +--tmr.alarm(test_1, 2.5*1000, tmr.ALARM_SINGLE, function() + print("U") +end) + +--[[ +tmr.stop(test_1) +tmr.start(test_1) +]] + diff --git a/Workshop/oscilloscope/tst_oscillo/README.md b/Workshop/oscilloscope/tst_oscillo/README.md new file mode 100644 index 0000000..f5c8c5b --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/README.md @@ -0,0 +1,21 @@ +# Petit banc tests pour tester un oscilloscope low cost + +## Buts + +Quand on achète un oscilloscope à 25 balles on ne sait pas trop l'utiliser et encore moins ce qu'il vaut !
+ +On va utiliser un NodeMCU pour: + +- envoyer le caractère U (u majuscule) sur la console. Le U à l'avantage d'avoir la suite 1010101 en ASCII. Facile donc de pouvoir le repérer à l'oscilloscope + +- envoyer la fréquence xx sur la pin x + +- envoyer un signal PWM de 30/70% sur la pin y + + + +zf190504.1335 + + + + diff --git a/Workshop/oscilloscope/tst_oscillo/a_gene1.lua b/Workshop/oscilloscope/tst_oscillo/a_gene1.lua new file mode 100644 index 0000000..af9a5b6 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/a_gene1.lua @@ -0,0 +1,27 @@ +-- Générerateur de fonction signal carré de fréquence variable et de rqtio variable + +print("\n a_gene1.lua zf190504.1912 \n") + +pin_gene = 5 +gpio.mode(pin_gene,gpio.OUTPUT) +gpio.write(pin_gene,gpio.LOW) + +function genepulse(zpulse) + print("tutu") + gpio.serout(pin_gene,gpio.HIGH,{zpulse/2,zpulse},1000000,genesquare) +end + +function genesquare() + print("toto") + zdemieperiode=1/zfreq*1000000/2 + print("Demie période: ",zdemieperiode) + genepulse(zdemieperiode) + print("titi") +end + +zfreq=5000*(10/9.43) +genesquare() + +--[[ +genesquare(0) +]] diff --git a/Workshop/oscilloscope/tst_oscillo/a_tst1_serial.lua b/Workshop/oscilloscope/tst_oscillo/a_tst1_serial.lua new file mode 100644 index 0000000..fc59470 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/a_tst1_serial.lua @@ -0,0 +1,21 @@ +-- Juste pour tester le port série, envoie une suite de caractère ASCCI toutes les seconde +-- On envoie 5x le caractère U +-- U en binaire c'est 1010101 +-- on peut ainsi bien 'voir' avec un oscilloscope le port série + +print("\n a_tst1_serial.lua zf190504.1502 \n") + + +test_1=tmr.create() +tmr.alarm(test_1, 0.020*1000, tmr.ALARM_AUTO, function() +--tmr.alarm(test_1, 2.5*1000, tmr.ALARM_SINGLE, function() +-- print(" ### ") +-- uart.write(0, string.char(0)..string.char(0)..string.char(1)..string.char(3)..string.char(0).."U") + uart.write(0, "UUUUU") +end) + +--[[ +tmr.stop(test_1) +tmr.start(test_1) +]] + diff --git a/Workshop/oscilloscope/tst_oscillo/boot.lua b/Workshop/oscilloscope/tst_oscillo/boot.lua new file mode 100644 index 0000000..4e7f874 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/boot.lua @@ -0,0 +1,35 @@ +-- Scripts à charger après le boot pour démarrer son appli + +print("\n boot.lua zf190504.1918 \n") + +function heartbeat() + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + flash_led_xfois() + boottimer1=tmr.create() + tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) +end + +f= "led_rgb.lua" if file.exists(f) then dofile(f) end +f= "wifi_off.lua" if file.exists(f) then dofile(f) end +--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end +--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end +--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +--f= "telnet_srv2.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 +--f= "set_time.lua" if file.exists(f) then dofile(f) end +--f= "dsleep.lua" if file.exists(f) then dofile(f) end +--f= "a_no_linear.lua" if file.exists(f) then dofile(f) end +f= "a_tst1_serial.lua" if file.exists(f) then dofile(f) end +f= "a_gene1.lua" if file.exists(f) then dofile(f) end + +f=nil +heartbeat=nil +--heartbeat() + + + + diff --git a/Workshop/oscilloscope/tst_oscillo/flash_led_xfois.lua b/Workshop/oscilloscope/tst_oscillo/flash_led_xfois.lua new file mode 100644 index 0000000..ffea9b0 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/flash_led_xfois.lua @@ -0,0 +1,37 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off + +function flash_led_xfois() + print("\n flash_led_xfois.lua zf190310.1533 \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) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end + end + +-- xfois =2 +-- blink_LED () +end + + + + diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/a_tst_variables.lua b/Workshop/oscilloscope/tst_oscillo/goodies/a_tst_variables.lua new file mode 100644 index 0000000..bbae700 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/a_tst_variables.lua @@ -0,0 +1,6 @@ +-- Scripts pour afficher toutes les variables et fonctions en cours dans le système + +print("\n a_tst_variable.lua zf190310.1525 \n") + +for n in pairs (_G) do print(n) end + diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/rm_files.lua b/Workshop/oscilloscope/tst_oscillo/goodies/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/rm_files.lua @@ -0,0 +1,12 @@ +-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU + +print("\n rm_files.lua zf180907.1511 \n") + + +l=file.list() i=0 +for k,v in pairs(l) do + i=i+v + file.remove(k) +end +print("-------------------------------") +print("\nC'est tout effaced :-) \n") diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/set_time.lua b/Workshop/oscilloscope/tst_oscillo/goodies/set_time.lua new file mode 100644 index 0000000..748cc95 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/set_time.lua @@ -0,0 +1,29 @@ +-- 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 zf190217.1426 \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) + 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() +print(ztime_format(rtctime.get())) + diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/t1.csv b/Workshop/oscilloscope/tst_oscillo/goodies/t1.csv new file mode 100644 index 0000000..7dc8514 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/t1.csv @@ -0,0 +1,27 @@ +ohm,% +33,100 +36,96.77419355 +41,92.74193548 +45,88.70967742 +52,84.67741935 +56,80.64516129 +61,76.61290323 +67,72.58064516 +72,68.5483871 +79,64.51612903 +83,60.48387097 +91,56.4516129 +97,52.41935484 +104,48.38709677 +112,44.35483871 +117,40.32258065 +121,36.29032258 +128,32.25806452 +132,28.22580645 +139,24.19354839 +150,20.16129032 +166,16.12903226 +191,12.09677419 +207,8.064516129 +224,4.032258065 +240,0 \ No newline at end of file diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/telnet_srv2.lua b/Workshop/oscilloscope/tst_oscillo/goodies/telnet_srv2.lua new file mode 100644 index 0000000..821358c --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/telnet_srv2.lua @@ -0,0 +1,87 @@ +-- 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 zf181215.1326 \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 + + 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/Workshop/oscilloscope/tst_oscillo/goodies/web_ide2.lua b/Workshop/oscilloscope/tst_oscillo/goodies/web_ide2.lua new file mode 100644 index 0000000..16d00f2 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/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/Workshop/oscilloscope/tst_oscillo/goodies/web_srv2.lua b/Workshop/oscilloscope/tst_oscillo/goodies/web_srv2.lua new file mode 100644 index 0000000..a7b5953 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/web_srv2.lua @@ -0,0 +1,77 @@ +-- petit script de serveur WEB avec Active Server Page ZYX + +print("\n web_srv2.lua zf190422.1135 \n") + +ztemp=12 + +-- 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 = file_web:read('\n') + 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 + 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("request: \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/Workshop/oscilloscope/tst_oscillo/goodies/wifi_ap_start.lua b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_ap_start.lua new file mode 100644 index 0000000..f7ade0d --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_ap_start.lua @@ -0,0 +1,19 @@ +-- Démarre le WIFI en mode AP + +function wifi_ap_start() + print("\n wifi_ap_start.lua zf190310.1511 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) + elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" }) + --f= "wifi_info.lua" if file.exists(f) then dofile(f) end +end + +wifi_ap_start() +wifi_ap_start=nil diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_conf.lua b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_conf.lua new file mode 100644 index 0000000..99b5767 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_conf.lua @@ -0,0 +1,20 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +function wifi_cli_conf() + print("\n wifi_cli_conf.lua zf190310.1527 \n") + + --credentials par défaut + --cli_ssid="3g-s7" + cli_ssid="3G-zf" + cli_pwd="12234567" + + --ses propre credentials + f= "credentials.lua" if file.exists(f) then dofile(f) end + + wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true} +end + +wifi_cli_conf() +wifi_cli_conf=nil +cli_ssid=nil +cli_pwd=nil diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_start.lua b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_start.lua new file mode 100644 index 0000000..045957e --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_start.lua @@ -0,0 +1,20 @@ +-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM + +function wifi_cli_start() + print("\n wifi_cli_start.lua zf190310.1519 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode CLI only") + wifi.setmode(wifi.STATION) + elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.sta.autoconnect(1) + wifi.sta.connect() + --f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end +end + +wifi_cli_start() +wifi_cli_start=nil diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/wifi_get_ip.lua b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/wifi_get_ip.lua @@ -0,0 +1,12 @@ +-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi +print("\n wifi_get_ip.lua zf181119.2318 \n") + +wifitimer1=tmr.create() +tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + else + tmr.stop(wifitimer1) + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + end +end) diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/z_index.html b/Workshop/oscilloscope/tst_oscillo/goodies/z_index.html new file mode 100644 index 0000000..dd689c8 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/z_index.html @@ -0,0 +1,20 @@ + + + + + + ESP8266 home page + + + +

ESP8266 home page 190422.1052

+

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 qui n'existe pas !
+

+ + + diff --git a/Workshop/oscilloscope/tst_oscillo/goodies/z_page1.html b/Workshop/oscilloscope/tst_oscillo/goodies/z_page1.html new file mode 100644 index 0000000..c0bd757 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/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/Workshop/oscilloscope/tst_oscillo/goodies/z_page2.html b/Workshop/oscilloscope/tst_oscillo/goodies/z_page2.html new file mode 100644 index 0000000..1516626 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/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/Workshop/oscilloscope/tst_oscillo/goodies/z_page3.html b/Workshop/oscilloscope/tst_oscillo/goodies/z_page3.html new file mode 100644 index 0000000..f0be1e9 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/goodies/z_page3.html @@ -0,0 +1,51 @@ + + + + + + ESP8266 page 3 + + + +

ESP8266 page 3 190422.1200

+
+ 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/Workshop/oscilloscope/tst_oscillo/initz.lua b/Workshop/oscilloscope/tst_oscillo/initz.lua new file mode 100644 index 0000000..771f253 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/initz.lua @@ -0,0 +1,52 @@ +--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 zf190310.1549 \n") + +zswitch=3 --switch flash +gpio.mode(zswitch, gpio.INT, gpio.PULLUP) + +function hvbouton() +-- gpio.trig(zswitch, "none") + tmr.unregister(initalarme) + f= "boot.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() + tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function() + f= "boot.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 +elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 6 then + print("external reset") + second_chance() +-- f= "boot.lua" if file.exists(f) then dofile(f) end +else + print("autre raison") + second_chance() +end + diff --git a/Workshop/oscilloscope/tst_oscillo/led_rgb.lua b/Workshop/oscilloscope/tst_oscillo/led_rgb.lua new file mode 100644 index 0000000..7a5d396 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/led_rgb.lua @@ -0,0 +1,37 @@ +-- Scripts juste pour allumer ou éteindre une LED sur un ruban RGB +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n led_rgb.lua zf190303.1436 \n") + +nbleds=3 +ws2812.init() +myLedStrip = ws2812.newBuffer(nbleds, 3) + +function RGB_clear() + myLedStrip:fill(0, 0, 0) ws2812.write(myLedStrip) +end + +function RGB_reform(R1, G1, B1) --conversion de RGB à BRG + rR1=B1 rG1=R1 rB1=G1 +end + +function zled_rgb(num_led, R1, G1, B1, zpower) + RGB_reform(R1, G1, B1) + myLedStrip:set(num_led, rR1*zpower, rG1*zpower, rB1*zpower) + ws2812.write(myLedStrip) +end + +function zled_write() + ws2812.write(myLedStrip) +end + + +RGB_clear() + +--[[ +zled_rgb(1,255,0,0,1) +zled_rgb(2,0,255,0,1) +zled_rgb(2,0,255,0,0.05) +zled_rgb(3,0,0,255,1) +]] diff --git a/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-19 à 22.20.27.png b/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-19 à 22.20.27.png new file mode 100644 index 0000000..f906daa Binary files /dev/null and b/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-19 à 22.20.27.png differ diff --git a/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-20 à 09.05.41.png b/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-20 à 09.05.41.png new file mode 100644 index 0000000..2307d8c Binary files /dev/null and b/Workshop/oscilloscope/tst_oscillo/simulation/Capture d’écran 2019-04-20 à 09.05.41.png differ diff --git a/Workshop/oscilloscope/tst_oscillo/simulation/échelle sonde.xlsx b/Workshop/oscilloscope/tst_oscillo/simulation/échelle sonde.xlsx new file mode 100644 index 0000000..21a2e7d Binary files /dev/null and b/Workshop/oscilloscope/tst_oscillo/simulation/échelle sonde.xlsx differ diff --git a/Workshop/oscilloscope/tst_oscillo/wifi_info.lua b/Workshop/oscilloscope/tst_oscillo/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/wifi_info.lua @@ -0,0 +1,31 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf181119.0014 \n") + +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()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP") + print("AP MAC:\n",wifi.ap.getmac()) + print("AP IP:\n",wifi.ap.getip()) + print("AP Connect:\n",wifi.ap.getconfig()) +elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end + print("AP MAC: "..wifi.ap.getmac()) + print("AP IP: "..wifi.ap.getip()) +end diff --git a/Workshop/oscilloscope/tst_oscillo/wifi_off.lua b/Workshop/oscilloscope/tst_oscillo/wifi_off.lua new file mode 100644 index 0000000..c1c7235 --- /dev/null +++ b/Workshop/oscilloscope/tst_oscillo/wifi_off.lua @@ -0,0 +1,9 @@ +-- Déconnecte le WIFI +print("\n wifi_off.lua zf180822.0959 \n") + +wifi.setmode(wifi.NULLMODE) + +--[[ +print(wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP) +print(wifi.getmode()) +]] diff --git a/zpackage/README.md b/zpackage/README.md new file mode 100644 index 0000000..1dfd9b6 --- /dev/null +++ b/zpackage/README.md @@ -0,0 +1,12 @@ +# zPackage + +## Environnement complet à installer dans un NodeMCU pour pouvoir bien travailler + + + + + + + + +zf190504.1325 diff --git a/zpackage/boot.lua b/zpackage/boot.lua new file mode 100644 index 0000000..917e172 --- /dev/null +++ b/zpackage/boot.lua @@ -0,0 +1,32 @@ +-- Scripts à charger après le boot pour démarrer son appli + +print("\n boot.lua zf19422.1102 \n") + +function heartbeat() + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + flash_led_xfois() + boottimer1=tmr.create() + tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) +end + +f= "led_rgb.lua" if file.exists(f) then dofile(f) end +f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end +f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end +f= "telnet_srv2.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 +--f= "set_time.lua" if file.exists(f) then dofile(f) end +--f= "dsleep.lua" if file.exists(f) then dofile(f) end +f= "a_no_linear.lua" if file.exists(f) then dofile(f) end + +f=nil +heartbeat=nil +--heartbeat() + + + + diff --git a/zpackage/flash_led_xfois.lua b/zpackage/flash_led_xfois.lua new file mode 100644 index 0000000..ffea9b0 --- /dev/null +++ b/zpackage/flash_led_xfois.lua @@ -0,0 +1,37 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off + +function flash_led_xfois() + print("\n flash_led_xfois.lua zf190310.1533 \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) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end + end + +-- xfois =2 +-- blink_LED () +end + + + + diff --git a/zpackage/goodies/a_tst_variables.lua b/zpackage/goodies/a_tst_variables.lua new file mode 100644 index 0000000..bbae700 --- /dev/null +++ b/zpackage/goodies/a_tst_variables.lua @@ -0,0 +1,6 @@ +-- Scripts pour afficher toutes les variables et fonctions en cours dans le système + +print("\n a_tst_variable.lua zf190310.1525 \n") + +for n in pairs (_G) do print(n) end + diff --git a/zpackage/goodies/rm_files.lua b/zpackage/goodies/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/zpackage/goodies/rm_files.lua @@ -0,0 +1,12 @@ +-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU + +print("\n rm_files.lua zf180907.1511 \n") + + +l=file.list() i=0 +for k,v in pairs(l) do + i=i+v + file.remove(k) +end +print("-------------------------------") +print("\nC'est tout effaced :-) \n") diff --git a/zpackage/goodies/wifi_off.lua b/zpackage/goodies/wifi_off.lua new file mode 100644 index 0000000..c1c7235 --- /dev/null +++ b/zpackage/goodies/wifi_off.lua @@ -0,0 +1,9 @@ +-- Déconnecte le WIFI +print("\n wifi_off.lua zf180822.0959 \n") + +wifi.setmode(wifi.NULLMODE) + +--[[ +print(wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP) +print(wifi.getmode()) +]] diff --git a/zpackage/initz.lua b/zpackage/initz.lua new file mode 100644 index 0000000..771f253 --- /dev/null +++ b/zpackage/initz.lua @@ -0,0 +1,52 @@ +--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 zf190310.1549 \n") + +zswitch=3 --switch flash +gpio.mode(zswitch, gpio.INT, gpio.PULLUP) + +function hvbouton() +-- gpio.trig(zswitch, "none") + tmr.unregister(initalarme) + f= "boot.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() + tmr.alarm(initalarme, 4*1000, tmr.ALARM_SINGLE, function() + f= "boot.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 +elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 6 then + print("external reset") + second_chance() +-- f= "boot.lua" if file.exists(f) then dofile(f) end +else + print("autre raison") + second_chance() +end + diff --git a/zpackage/led_rgb.lua b/zpackage/led_rgb.lua new file mode 100644 index 0000000..7a5d396 --- /dev/null +++ b/zpackage/led_rgb.lua @@ -0,0 +1,37 @@ +-- Scripts juste pour allumer ou éteindre une LED sur un ruban RGB +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n led_rgb.lua zf190303.1436 \n") + +nbleds=3 +ws2812.init() +myLedStrip = ws2812.newBuffer(nbleds, 3) + +function RGB_clear() + myLedStrip:fill(0, 0, 0) ws2812.write(myLedStrip) +end + +function RGB_reform(R1, G1, B1) --conversion de RGB à BRG + rR1=B1 rG1=R1 rB1=G1 +end + +function zled_rgb(num_led, R1, G1, B1, zpower) + RGB_reform(R1, G1, B1) + myLedStrip:set(num_led, rR1*zpower, rG1*zpower, rB1*zpower) + ws2812.write(myLedStrip) +end + +function zled_write() + ws2812.write(myLedStrip) +end + + +RGB_clear() + +--[[ +zled_rgb(1,255,0,0,1) +zled_rgb(2,0,255,0,1) +zled_rgb(2,0,255,0,0.05) +zled_rgb(3,0,0,255,1) +]] diff --git a/zpackage/set_time.lua b/zpackage/set_time.lua new file mode 100644 index 0000000..748cc95 --- /dev/null +++ b/zpackage/set_time.lua @@ -0,0 +1,29 @@ +-- 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 zf190217.1426 \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) + 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() +print(ztime_format(rtctime.get())) + diff --git a/zpackage/simulation/Capture d’écran 2019-04-19 à 22.20.27.png b/zpackage/simulation/Capture d’écran 2019-04-19 à 22.20.27.png new file mode 100644 index 0000000..f906daa Binary files /dev/null and b/zpackage/simulation/Capture d’écran 2019-04-19 à 22.20.27.png differ diff --git a/zpackage/simulation/Capture d’écran 2019-04-20 à 09.05.41.png b/zpackage/simulation/Capture d’écran 2019-04-20 à 09.05.41.png new file mode 100644 index 0000000..2307d8c Binary files /dev/null and b/zpackage/simulation/Capture d’écran 2019-04-20 à 09.05.41.png differ diff --git a/zpackage/simulation/échelle sonde.xlsx b/zpackage/simulation/échelle sonde.xlsx new file mode 100644 index 0000000..21a2e7d Binary files /dev/null and b/zpackage/simulation/échelle sonde.xlsx differ diff --git a/zpackage/t1.csv b/zpackage/t1.csv new file mode 100644 index 0000000..7dc8514 --- /dev/null +++ b/zpackage/t1.csv @@ -0,0 +1,27 @@ +ohm,% +33,100 +36,96.77419355 +41,92.74193548 +45,88.70967742 +52,84.67741935 +56,80.64516129 +61,76.61290323 +67,72.58064516 +72,68.5483871 +79,64.51612903 +83,60.48387097 +91,56.4516129 +97,52.41935484 +104,48.38709677 +112,44.35483871 +117,40.32258065 +121,36.29032258 +128,32.25806452 +132,28.22580645 +139,24.19354839 +150,20.16129032 +166,16.12903226 +191,12.09677419 +207,8.064516129 +224,4.032258065 +240,0 \ No newline at end of file diff --git a/zpackage/telnet_srv2.lua b/zpackage/telnet_srv2.lua new file mode 100644 index 0000000..821358c --- /dev/null +++ b/zpackage/telnet_srv2.lua @@ -0,0 +1,87 @@ +-- 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 zf181215.1326 \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 + + 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/zpackage/web_ide2.lua b/zpackage/web_ide2.lua new file mode 100644 index 0000000..16d00f2 --- /dev/null +++ b/zpackage/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/zpackage/web_srv2.lua b/zpackage/web_srv2.lua new file mode 100644 index 0000000..a7b5953 --- /dev/null +++ b/zpackage/web_srv2.lua @@ -0,0 +1,77 @@ +-- petit script de serveur WEB avec Active Server Page ZYX + +print("\n web_srv2.lua zf190422.1135 \n") + +ztemp=12 + +-- 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 = file_web:read('\n') + 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 + 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("request: \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/zpackage/wifi_ap_start.lua b/zpackage/wifi_ap_start.lua new file mode 100644 index 0000000..f7ade0d --- /dev/null +++ b/zpackage/wifi_ap_start.lua @@ -0,0 +1,19 @@ +-- Démarre le WIFI en mode AP + +function wifi_ap_start() + print("\n wifi_ap_start.lua zf190310.1511 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) + elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" }) + --f= "wifi_info.lua" if file.exists(f) then dofile(f) end +end + +wifi_ap_start() +wifi_ap_start=nil diff --git a/zpackage/wifi_cli_conf.lua b/zpackage/wifi_cli_conf.lua new file mode 100644 index 0000000..99b5767 --- /dev/null +++ b/zpackage/wifi_cli_conf.lua @@ -0,0 +1,20 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +function wifi_cli_conf() + print("\n wifi_cli_conf.lua zf190310.1527 \n") + + --credentials par défaut + --cli_ssid="3g-s7" + cli_ssid="3G-zf" + cli_pwd="12234567" + + --ses propre credentials + f= "credentials.lua" if file.exists(f) then dofile(f) end + + wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true} +end + +wifi_cli_conf() +wifi_cli_conf=nil +cli_ssid=nil +cli_pwd=nil diff --git a/zpackage/wifi_cli_start.lua b/zpackage/wifi_cli_start.lua new file mode 100644 index 0000000..045957e --- /dev/null +++ b/zpackage/wifi_cli_start.lua @@ -0,0 +1,20 @@ +-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM + +function wifi_cli_start() + print("\n wifi_cli_start.lua zf190310.1519 \n") + + local zmodewifi=wifi.getmode() + if zmodewifi == wifi.NULLMODE then + print("WIFI mode CLI only") + wifi.setmode(wifi.STATION) + elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) + end + wifi.sta.autoconnect(1) + wifi.sta.connect() + --f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end +end + +wifi_cli_start() +wifi_cli_start=nil diff --git a/zpackage/wifi_get_ip.lua b/zpackage/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/zpackage/wifi_get_ip.lua @@ -0,0 +1,12 @@ +-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi +print("\n wifi_get_ip.lua zf181119.2318 \n") + +wifitimer1=tmr.create() +tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + else + tmr.stop(wifitimer1) + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + end +end) diff --git a/zpackage/wifi_info.lua b/zpackage/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/zpackage/wifi_info.lua @@ -0,0 +1,31 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf181119.0014 \n") + +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()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP") + print("AP MAC:\n",wifi.ap.getmac()) + print("AP IP:\n",wifi.ap.getip()) + print("AP Connect:\n",wifi.ap.getconfig()) +elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end + print("AP MAC: "..wifi.ap.getmac()) + print("AP IP: "..wifi.ap.getip()) +end diff --git a/zpackage/z_index.html b/zpackage/z_index.html new file mode 100644 index 0000000..dd689c8 --- /dev/null +++ b/zpackage/z_index.html @@ -0,0 +1,20 @@ + + + + + + ESP8266 home page + + + +

ESP8266 home page 190422.1052

+

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 qui n'existe pas !
+

+ + + diff --git a/zpackage/z_page1.html b/zpackage/z_page1.html new file mode 100644 index 0000000..c0bd757 --- /dev/null +++ b/zpackage/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/zpackage/z_page2.html b/zpackage/z_page2.html new file mode 100644 index 0000000..1516626 --- /dev/null +++ b/zpackage/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/zpackage/z_page3.html b/zpackage/z_page3.html new file mode 100644 index 0000000..f0be1e9 --- /dev/null +++ b/zpackage/z_page3.html @@ -0,0 +1,51 @@ + + + + + + ESP8266 page 3 + + + +

ESP8266 page 3 190422.1200

+
+ 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") + %> + + + +