Pleins d'ajouts ;-)
* Ajouté le dossier zpackage contenant tout ce qu'il faut pour bien débuter un nouveau projet NodeMCU * Ajouté un dossier, générateur de signaux pour le workshop sur l'oscilloscope * Rangé le dossier genefunc * Ajouté le dossier AD9833 pour commencer à travailler avec le module générateur de fonction AD9833
15
Genefunc/AD9833/README.md
Normal file
@@ -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
|
||||||
32
Genefunc/AD9833/boot.lua
Normal file
@@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
37
Genefunc/AD9833/led_rgb.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 43 KiB |
BIN
Genefunc/AD9833/simulation/échelle sonde.xlsx
Normal file
27
Genefunc/AD9833/t1.csv
Normal file
@@ -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
|
||||||
|
77
Genefunc/AD9833/web_srv2.lua
Normal file
@@ -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("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
20
Genefunc/AD9833/z_index.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 home page</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 home page 190422.1052</h1>
|
||||||
|
<h2>Différentes pages HTML:</h2>
|
||||||
|
<h3>
|
||||||
|
<a href="z_page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
|
||||||
|
<a href="z_page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
|
||||||
|
<a href="z_page3.html">Page 3, affichage du capteur non linéaire corrigé.</a><br>
|
||||||
|
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||||
|
</h3>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
26
Genefunc/AD9833/z_page1.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 1</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 1 190127.1445</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 1 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
La température est:
|
||||||
|
|
||||||
|
<%
|
||||||
|
ztemp=ztemp+1
|
||||||
|
zout(ztemp.."°C")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Mais il fait encore trop froid !<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
51
Genefunc/AD9833/z_page2.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 2</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 2 190127.1449</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 2 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici un tableau dynamique écrit en Lua inline.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données du tableau viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- 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"}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<table border='1'>
|
||||||
|
<tr>
|
||||||
|
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
|
||||||
|
</tr>
|
||||||
|
<%
|
||||||
|
for k, v in pairs(zmac_adrs) do
|
||||||
|
zout("<tr>\n")
|
||||||
|
zout("\t<td>" .. k .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
|
||||||
|
zout("</tr>\n")
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
|
||||||
|
zmac_adrs=nil
|
||||||
|
%>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
51
Genefunc/AD9833/z_page3.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 3</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 3 190422.1200</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 3 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici le résultat du capteur non linéaire corrigé avec une table
|
||||||
|
d'interpolation dans un fichier .csv sur la flash.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=83
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=91
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=100
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Yeah... cela fonctionne vachement bien !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
37
Genefunc/serout/flash_led_xfois.lua
Normal file
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
6
Genefunc/serout/goodies/a_tst_variables.lua
Normal file
@@ -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
|
||||||
|
|
||||||
12
Genefunc/serout/goodies/rm_files.lua
Normal file
@@ -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")
|
||||||
9
Genefunc/serout/goodies/wifi_off.lua
Normal file
@@ -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())
|
||||||
|
]]
|
||||||
52
Genefunc/serout/initz.lua
Normal file
@@ -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
|
||||||
|
|
||||||
29
Genefunc/serout/set_time.lua
Normal file
@@ -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()))
|
||||||
|
|
||||||
87
Genefunc/serout/telnet_srv2.lua
Normal file
@@ -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")
|
||||||
159
Genefunc/serout/web_ide2.lua
Normal file
@@ -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://<mcu_ip>/ will list all the files in the MCU
|
||||||
|
http://<mcu_ip>/newfile.lua displays the file on your browser
|
||||||
|
http://<mcu_ip>/newfile.lua?edit allows to creates or edits the specified script in your browser
|
||||||
|
http://<mcu_ip>/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("<html><body><h1>NodeMCU IDE</h1>")
|
||||||
|
|
||||||
|
if vars=="edit" then
|
||||||
|
conn:send("<script>function tag(c){document.getElementsByTagName('w')[0].innerHTML=c};\n")
|
||||||
|
conn:send("var x=new XMLHttpRequest()\nx.onreadystatechange=function(){if(x.readyState==4) document.getElementsByName('t')[0].value = x.responseText; };\nx.open('GET',location.pathname,true)\nx.send()</script>")
|
||||||
|
conn:send("<h2><a href='/'>Back to file list</a>\n")
|
||||||
|
conn:send("<br><br><button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")
|
||||||
|
conn:send("</h2><br><textarea name=t cols=110 rows=50></textarea></br>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if vars=="run" then
|
||||||
|
conn:send("<verbatim>")
|
||||||
|
local st, result=pcall(dofile, url)
|
||||||
|
conn:send(tostring(result))
|
||||||
|
conn:send("</verbatim>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if url=="" then
|
||||||
|
local l = file.list();
|
||||||
|
for k,v in pairs(l) do
|
||||||
|
conn:send("<a href='"..k.."?edit'>"..k.."</a>, size:"..v.."<br>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
conn:send("</body></html>")
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
19
Genefunc/serout/wifi_ap_start.lua
Normal file
@@ -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
|
||||||
20
Genefunc/serout/wifi_cli_conf.lua
Normal file
@@ -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
|
||||||
20
Genefunc/serout/wifi_cli_start.lua
Normal file
@@ -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
|
||||||
12
Genefunc/serout/wifi_get_ip.lua
Normal file
@@ -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)
|
||||||
31
Genefunc/serout/wifi_info.lua
Normal file
@@ -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
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
-- tout sur la couleur: https://www.w3schools.com/colors/default.asp
|
||||||
-- roue des couleurs: https://iro.js.org/?ref=oldsite
|
-- 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_max=300
|
||||||
znbleds=300
|
znbleds=300
|
||||||
zstep=5
|
zstep=3
|
||||||
zpower=1
|
zpower=1
|
||||||
|
|
||||||
zleds={}
|
zleds={}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
-- Scripts à charger après le boot pour démarrer son appli
|
-- 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()
|
function heartbeat()
|
||||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||||
@@ -11,11 +11,12 @@ function heartbeat()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) 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_stop.lua" if file.exists(f) then dofile(f) end
|
||||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||||
f= "web_ide2.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= "az_init_led.lua" if file.exists(f) then dofile(f) end
|
||||||
--f= "webleds.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
|
f= "a_guirlande.lua" if file.exists(f) then dofile(f) end
|
||||||
|
|||||||
BIN
No_linear/simulation/Capture d’écran 2019-04-19 à 22.20.27.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
No_linear/simulation/Capture d’écran 2019-04-20 à 09.05.41.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
No_linear/simulation/échelle sonde.xlsx
Normal file
17
Tests/a_tst1_serial.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
|
|
||||||
21
Workshop/oscilloscope/tst_oscillo/README.md
Normal file
@@ -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 !<br>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
27
Workshop/oscilloscope/tst_oscillo/a_gene1.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
21
Workshop/oscilloscope/tst_oscillo/a_tst1_serial.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
|
|
||||||
35
Workshop/oscilloscope/tst_oscillo/boot.lua
Normal file
@@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
37
Workshop/oscilloscope/tst_oscillo/flash_led_xfois.lua
Normal file
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|
||||||
12
Workshop/oscilloscope/tst_oscillo/goodies/rm_files.lua
Normal file
@@ -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")
|
||||||
29
Workshop/oscilloscope/tst_oscillo/goodies/set_time.lua
Normal file
@@ -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()))
|
||||||
|
|
||||||
27
Workshop/oscilloscope/tst_oscillo/goodies/t1.csv
Normal file
@@ -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
|
||||||
|
87
Workshop/oscilloscope/tst_oscillo/goodies/telnet_srv2.lua
Normal file
@@ -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")
|
||||||
159
Workshop/oscilloscope/tst_oscillo/goodies/web_ide2.lua
Normal file
@@ -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://<mcu_ip>/ will list all the files in the MCU
|
||||||
|
http://<mcu_ip>/newfile.lua displays the file on your browser
|
||||||
|
http://<mcu_ip>/newfile.lua?edit allows to creates or edits the specified script in your browser
|
||||||
|
http://<mcu_ip>/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("<html><body><h1>NodeMCU IDE</h1>")
|
||||||
|
|
||||||
|
if vars=="edit" then
|
||||||
|
conn:send("<script>function tag(c){document.getElementsByTagName('w')[0].innerHTML=c};\n")
|
||||||
|
conn:send("var x=new XMLHttpRequest()\nx.onreadystatechange=function(){if(x.readyState==4) document.getElementsByName('t')[0].value = x.responseText; };\nx.open('GET',location.pathname,true)\nx.send()</script>")
|
||||||
|
conn:send("<h2><a href='/'>Back to file list</a>\n")
|
||||||
|
conn:send("<br><br><button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")
|
||||||
|
conn:send("</h2><br><textarea name=t cols=110 rows=50></textarea></br>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if vars=="run" then
|
||||||
|
conn:send("<verbatim>")
|
||||||
|
local st, result=pcall(dofile, url)
|
||||||
|
conn:send(tostring(result))
|
||||||
|
conn:send("</verbatim>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if url=="" then
|
||||||
|
local l = file.list();
|
||||||
|
for k,v in pairs(l) do
|
||||||
|
conn:send("<a href='"..k.."?edit'>"..k.."</a>, size:"..v.."<br>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
conn:send("</body></html>")
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
77
Workshop/oscilloscope/tst_oscillo/goodies/web_srv2.lua
Normal file
@@ -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("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
19
Workshop/oscilloscope/tst_oscillo/goodies/wifi_ap_start.lua
Normal file
@@ -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
|
||||||
20
Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_conf.lua
Normal file
@@ -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
|
||||||
20
Workshop/oscilloscope/tst_oscillo/goodies/wifi_cli_start.lua
Normal file
@@ -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
|
||||||
12
Workshop/oscilloscope/tst_oscillo/goodies/wifi_get_ip.lua
Normal file
@@ -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)
|
||||||
20
Workshop/oscilloscope/tst_oscillo/goodies/z_index.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 home page</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 home page 190422.1052</h1>
|
||||||
|
<h2>Différentes pages HTML:</h2>
|
||||||
|
<h3>
|
||||||
|
<a href="z_page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
|
||||||
|
<a href="z_page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
|
||||||
|
<a href="z_page3.html">Page 3, affichage du capteur non linéaire corrigé.</a><br>
|
||||||
|
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||||
|
</h3>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
26
Workshop/oscilloscope/tst_oscillo/goodies/z_page1.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 1</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 1 190127.1445</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 1 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
La température est:
|
||||||
|
|
||||||
|
<%
|
||||||
|
ztemp=ztemp+1
|
||||||
|
zout(ztemp.."°C")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Mais il fait encore trop froid !<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
51
Workshop/oscilloscope/tst_oscillo/goodies/z_page2.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 2</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 2 190127.1449</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 2 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici un tableau dynamique écrit en Lua inline.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données du tableau viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- 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"}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<table border='1'>
|
||||||
|
<tr>
|
||||||
|
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
|
||||||
|
</tr>
|
||||||
|
<%
|
||||||
|
for k, v in pairs(zmac_adrs) do
|
||||||
|
zout("<tr>\n")
|
||||||
|
zout("\t<td>" .. k .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
|
||||||
|
zout("</tr>\n")
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
|
||||||
|
zmac_adrs=nil
|
||||||
|
%>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
51
Workshop/oscilloscope/tst_oscillo/goodies/z_page3.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 3</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 3 190422.1200</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 3 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici le résultat du capteur non linéaire corrigé avec une table
|
||||||
|
d'interpolation dans un fichier .csv sur la flash.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=83
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=91
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=100
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Yeah... cela fonctionne vachement bien !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
52
Workshop/oscilloscope/tst_oscillo/initz.lua
Normal file
@@ -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
|
||||||
|
|
||||||
37
Workshop/oscilloscope/tst_oscillo/led_rgb.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 43 KiB |
BIN
Workshop/oscilloscope/tst_oscillo/simulation/échelle sonde.xlsx
Normal file
31
Workshop/oscilloscope/tst_oscillo/wifi_info.lua
Normal file
@@ -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
|
||||||
9
Workshop/oscilloscope/tst_oscillo/wifi_off.lua
Normal file
@@ -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())
|
||||||
|
]]
|
||||||
12
zpackage/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# zPackage
|
||||||
|
|
||||||
|
## Environnement complet à installer dans un NodeMCU pour pouvoir bien travailler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
zf190504.1325
|
||||||
32
zpackage/boot.lua
Normal file
@@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
37
zpackage/flash_led_xfois.lua
Normal file
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
6
zpackage/goodies/a_tst_variables.lua
Normal file
@@ -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
|
||||||
|
|
||||||
12
zpackage/goodies/rm_files.lua
Normal file
@@ -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")
|
||||||
9
zpackage/goodies/wifi_off.lua
Normal file
@@ -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())
|
||||||
|
]]
|
||||||
52
zpackage/initz.lua
Normal file
@@ -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
|
||||||
|
|
||||||
37
zpackage/led_rgb.lua
Normal file
@@ -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)
|
||||||
|
]]
|
||||||
29
zpackage/set_time.lua
Normal file
@@ -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()))
|
||||||
|
|
||||||
BIN
zpackage/simulation/Capture d’écran 2019-04-19 à 22.20.27.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
zpackage/simulation/Capture d’écran 2019-04-20 à 09.05.41.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
zpackage/simulation/échelle sonde.xlsx
Normal file
27
zpackage/t1.csv
Normal file
@@ -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
|
||||||
|
87
zpackage/telnet_srv2.lua
Normal file
@@ -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")
|
||||||
159
zpackage/web_ide2.lua
Normal file
@@ -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://<mcu_ip>/ will list all the files in the MCU
|
||||||
|
http://<mcu_ip>/newfile.lua displays the file on your browser
|
||||||
|
http://<mcu_ip>/newfile.lua?edit allows to creates or edits the specified script in your browser
|
||||||
|
http://<mcu_ip>/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("<html><body><h1>NodeMCU IDE</h1>")
|
||||||
|
|
||||||
|
if vars=="edit" then
|
||||||
|
conn:send("<script>function tag(c){document.getElementsByTagName('w')[0].innerHTML=c};\n")
|
||||||
|
conn:send("var x=new XMLHttpRequest()\nx.onreadystatechange=function(){if(x.readyState==4) document.getElementsByName('t')[0].value = x.responseText; };\nx.open('GET',location.pathname,true)\nx.send()</script>")
|
||||||
|
conn:send("<h2><a href='/'>Back to file list</a>\n")
|
||||||
|
conn:send("<br><br><button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")
|
||||||
|
conn:send("</h2><br><textarea name=t cols=110 rows=50></textarea></br>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if vars=="run" then
|
||||||
|
conn:send("<verbatim>")
|
||||||
|
local st, result=pcall(dofile, url)
|
||||||
|
conn:send(tostring(result))
|
||||||
|
conn:send("</verbatim>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if url=="" then
|
||||||
|
local l = file.list();
|
||||||
|
for k,v in pairs(l) do
|
||||||
|
conn:send("<a href='"..k.."?edit'>"..k.."</a>, size:"..v.."<br>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
conn:send("</body></html>")
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
77
zpackage/web_srv2.lua
Normal file
@@ -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("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
19
zpackage/wifi_ap_start.lua
Normal file
@@ -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
|
||||||
20
zpackage/wifi_cli_conf.lua
Normal file
@@ -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
|
||||||
20
zpackage/wifi_cli_start.lua
Normal file
@@ -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
|
||||||
12
zpackage/wifi_get_ip.lua
Normal file
@@ -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)
|
||||||
31
zpackage/wifi_info.lua
Normal file
@@ -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
|
||||||
20
zpackage/z_index.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 home page</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 home page 190422.1052</h1>
|
||||||
|
<h2>Différentes pages HTML:</h2>
|
||||||
|
<h3>
|
||||||
|
<a href="z_page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
|
||||||
|
<a href="z_page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
|
||||||
|
<a href="z_page3.html">Page 3, affichage du capteur non linéaire corrigé.</a><br>
|
||||||
|
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||||
|
</h3>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
26
zpackage/z_page1.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 1</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 1 190127.1445</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 1 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
La température est:
|
||||||
|
|
||||||
|
<%
|
||||||
|
ztemp=ztemp+1
|
||||||
|
zout(ztemp.."°C")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Mais il fait encore trop froid !<br>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
51
zpackage/z_page2.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 2</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 2 190127.1449</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 2 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici un tableau dynamique écrit en Lua inline.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données du tableau viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- 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"}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<table border='1'>
|
||||||
|
<tr>
|
||||||
|
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
|
||||||
|
</tr>
|
||||||
|
<%
|
||||||
|
for k, v in pairs(zmac_adrs) do
|
||||||
|
zout("<tr>\n")
|
||||||
|
zout("\t<td>" .. k .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
|
||||||
|
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
|
||||||
|
zout("</tr>\n")
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%
|
||||||
|
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
|
||||||
|
zmac_adrs=nil
|
||||||
|
%>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
51
zpackage/z_page3.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr" dir="ltr">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
|
<title>ESP8266 page 3</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>ESP8266 page 3 190422.1200</h1>
|
||||||
|
<br>
|
||||||
|
Coucou c'est la page 3 !<br>
|
||||||
|
<a href="/">Retour à la home page...</a><br><br><br>
|
||||||
|
|
||||||
|
Voici le résultat du capteur non linéaire corrigé avec une table
|
||||||
|
d'interpolation dans un fichier .csv sur la flash.<br><br>
|
||||||
|
|
||||||
|
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||||
|
Les données viennent du NodeMCU !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=83
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=91
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zx0=100
|
||||||
|
get_correction(zx0)
|
||||||
|
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||||
|
%>
|
||||||
|
|
||||||
|
<br>Yeah... cela fonctionne vachement bien !<br><br>
|
||||||
|
|
||||||
|
<%
|
||||||
|
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||||
|
%>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||