Commencé l'update de la mesure de puissance monophasée (clip transfo de courant) avec le nouveau code de base utilisé pour la mesure de température solar grafana
This commit is contained in:
27
Mesures/energy/transfo_courant_clip_1p/0_btn_flipflop.lua
Normal file
27
Mesures/energy/transfo_courant_clip_1p/0_btn_flipflop.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
-- Petit scripts pour faire un flip flop avec le bouton et la led du nodemcu
|
||||
-- Très intéressant la techno utilisée ici pour enlever les rebonds du micro switch
|
||||
-- dans la variable b se trouve l'heure à laquelle l'interruption est arrivée, il suffit juste alors de lui mettre un petit délai de 300mS
|
||||
|
||||
print("\n 0_btn_flipflop.lua zf200216.1457 \n")
|
||||
|
||||
gpio.write(zLED,1) gpio.mode(zLED,gpio.OUTPUT)
|
||||
gpio.mode(zBTN,gpio.INT)
|
||||
|
||||
d=tmr.now()
|
||||
|
||||
function zled (a,b,c)
|
||||
--print("a: "..a..",b: "..b..",c: "..c)
|
||||
if b-d > 300*1000 then
|
||||
if verbose then
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
verbose=false
|
||||
else
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(200000) gpio.write(zLED, gpio.HIGH)
|
||||
verbose=true
|
||||
end
|
||||
d=b
|
||||
print("verbose:",verbose)
|
||||
end
|
||||
end
|
||||
|
||||
gpio.trig(zBTN, "down", zled)
|
||||
@@ -1,13 +1,41 @@
|
||||
-- Petit script pour faire office de crontab pour les
|
||||
--mesures
|
||||
print("\n 0_cron.lua zf190917.0033 \n")
|
||||
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
xfois =2
|
||||
-- Petit script pour faire office de crontab pour les mesures
|
||||
print("\n 0_cron.lua zf200527.1827 \n")
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
|
||||
blink_LED ()
|
||||
send_data()
|
||||
if verbose then print("cron1........................") end
|
||||
if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
|
||||
http_post(influxdb_url,"energy,memory=cron1_"..yellow_id.." ram="..node.heap())
|
||||
|
||||
f = "0_1_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
http_post(influxdb_url,"energy,capteur=th1 temperature="..ztemp1)
|
||||
http_post(influxdb_url,"energy,capteur=th1 humidity="..zhum1)
|
||||
|
||||
f = "0_2_htu21d.lua" if file.exists(f) then dofile(f) end
|
||||
http_post(influxdb_url,"energy,capteur=th2 temperature="..ztemp2)
|
||||
http_post(influxdb_url,"energy,capteur=th2 humidity="..zhum2)
|
||||
|
||||
ztemp1=nil zhum1=nil ztemp2=nil zhum2=nil
|
||||
|
||||
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f=nil
|
||||
|
||||
if verbose then print("End cron:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end)
|
||||
|
||||
--[[
|
||||
cron1:stop()
|
||||
cron1:start()
|
||||
|
||||
sec, usec = rtctime.get()
|
||||
print(sec,usec)
|
||||
|
||||
print(ztime_format(rtctime.get()))
|
||||
|
||||
|
||||
|
||||
]]
|
||||
|
||||
47
Mesures/energy/transfo_courant_clip_1p/0_http_post.lua
Normal file
47
Mesures/energy/transfo_courant_clip_1p/0_http_post.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
-- Petit script pour envoyer en // es valeurs sur un serveur WEB (InfluxDB)
|
||||
-- via un http POST à travers un FIFO
|
||||
|
||||
if verbose then print("\n 0_http_post.lua zf200527.1836 \n") end
|
||||
|
||||
t_zurl={} t_zarg={} f_zpost=false
|
||||
|
||||
function tprint(t)
|
||||
for key,value in pairs(t) do print(key, value) end
|
||||
end
|
||||
|
||||
function zpost()
|
||||
f_zpost=true zurl=t_zurl[1] zarg=t_zarg[1]
|
||||
if verbose then print("zurl: "..zurl) end if verbose then print("zarg: "..zarg) end
|
||||
|
||||
http.post(zurl, 'Content-Type: application/x-www-form-urlencoded\r\n', zarg, function(code, data)
|
||||
if (code < 0) then
|
||||
print("HTTP request failed")
|
||||
print("zuzu", code, data)
|
||||
else
|
||||
if verbose then print(code, data) end
|
||||
end
|
||||
|
||||
table.remove(t_zurl, 1) table.remove(t_zarg, 1)
|
||||
if t_zurl[1]==nil then
|
||||
f_zpost=false
|
||||
else
|
||||
zpost()
|
||||
end
|
||||
if verbose then print("End zpost:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
|
||||
end)
|
||||
|
||||
zurl=nil zarg=nil
|
||||
end
|
||||
|
||||
|
||||
function http_post(zurl,zarg)
|
||||
table.insert(t_zurl, zurl) table.insert(t_zarg, zarg)
|
||||
if verbose then print("t_zurl:") tprint(t_zurl) print("t_zarg:") tprint(t_zarg) end
|
||||
if f_zpost==false then zpost() end
|
||||
if verbose then print("End http_post:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end
|
||||
197
Mesures/energy/transfo_courant_clip_1p/0_tst3_socat.lua
Normal file
197
Mesures/energy/transfo_courant_clip_1p/0_tst3_socat.lua
Normal file
@@ -0,0 +1,197 @@
|
||||
--[[
|
||||
tests connection reverse telnet commande à faire tourner sur le GATEWAY !
|
||||
|
||||
1ere console
|
||||
pour une liaison directe:
|
||||
socat TCP-LISTEN:23043,fork,reuseaddr STDIO
|
||||
pour une console sur un port:
|
||||
socat TCP-LISTEN:23043,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1
|
||||
|
||||
2e console
|
||||
telnet -r localhost 23000
|
||||
]]
|
||||
|
||||
--[[
|
||||
tests connection reverse telnet commande à faire tourner sur le GATEWAY ET sur sa MACHINE !
|
||||
|
||||
1ere console sur le GATEWAY
|
||||
socat TCP-LISTEN:23043,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1
|
||||
|
||||
2e console sur sa MACHINE
|
||||
ssh -L 23000:localhost:23000 user@GATEWAY
|
||||
|
||||
3e console sur sa MACHINE (~.return pour sortir !)
|
||||
telnet -r localhost 23000
|
||||
ou sur MAC
|
||||
telnet -rN localhost 23000
|
||||
]]
|
||||
|
||||
|
||||
print("\n 0_tst3_socat.lua zf200530.1132 \n")
|
||||
|
||||
local node, table, tmr, uwrite, tostring =
|
||||
node, table, tmr, 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
|
||||
fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, nil, nil
|
||||
--insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
|
||||
--wdclr, cnt = nil, nil
|
||||
node.output(nil)
|
||||
print("disconnected...")
|
||||
-- print("rt_retry:",rt_retry)
|
||||
-- rt_retry=rt_retry-1
|
||||
-- print("rt_retry:",rt_retry)
|
||||
-- if rt_retry>=0 then
|
||||
print("on ressaie en vitesse une fois ;-)")
|
||||
rt_connect()
|
||||
-- end
|
||||
end
|
||||
|
||||
--zzz
|
||||
local function zconnection(s)
|
||||
print("Welcome on ne devrait jamais passer par là to NodeMCU world.")
|
||||
end
|
||||
|
||||
socket:on("connection", zconnection)
|
||||
socket:on("receive", receiveLine)
|
||||
socket:on("disconnection", disconnect)
|
||||
socket:on("sent", sendLine)
|
||||
node.output(queueLine, 0)
|
||||
end
|
||||
|
||||
--net.createServer(net.TCP, 180):listen(23, telnet_listener)
|
||||
print("Revers telnet server running...\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function rt_connect()
|
||||
if verbose then
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
print("trying connect to "..console_host..":"..console_port)
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
srv_rt = nil srv_rt = net.createConnection(net.TCP, 0)
|
||||
srv_rt:on("connection", function(sck)
|
||||
if verbose then
|
||||
print("connected on "..console_host..":"..console_port)
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
telnet_listener(sck)
|
||||
print("Welcome to NodeMCU world.")
|
||||
end)
|
||||
srv_rt:connect(console_port,console_host)
|
||||
end
|
||||
|
||||
tmr_socat1=tmr.create()
|
||||
tmr_socat1:alarm(15*1000, tmr.ALARM_AUTO , function()
|
||||
rt_retry=1
|
||||
-- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
|
||||
if srv_rt~=nil then
|
||||
if console_port == srv_rt:getpeer() then
|
||||
--cela tourne...
|
||||
if verbose then gpio.write(zLED, gpio.LOW) end
|
||||
else
|
||||
--on relance...
|
||||
rt_connect()
|
||||
end
|
||||
else
|
||||
--on relance...
|
||||
rt_connect()
|
||||
end
|
||||
end)
|
||||
|
||||
rt_retry=3
|
||||
rt_connect()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
tmr_socat1:unregister()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
print(srv_rt:getpeer())
|
||||
|
||||
srv_rt:connect(console_port,console_host)
|
||||
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
if console_port == srv_rt:getpeer() then
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
else
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
end
|
||||
|
||||
|
||||
]]
|
||||
33
Mesures/energy/transfo_courant_clip_1p/0_zdyndns.lua
Normal file
33
Mesures/energy/transfo_courant_clip_1p/0_zdyndns.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Petit script pour s'inregistrer sur zdyndns
|
||||
|
||||
function send_zdyndns()
|
||||
if verbose then print("\n 0_zdyndns.lua zf200525.1403 \n") end
|
||||
|
||||
zip = wifi.sta.getip()
|
||||
zdyndns_str = "s "..node_id..","..console_host..":"..tostring(console_port).." "..zip.."\n"
|
||||
if verbose then print("zdyndns_str: /"..zdyndns_str.."/") end
|
||||
|
||||
srv_zdyndns = net.createConnection(net.TCP, 0)
|
||||
|
||||
srv_zdyndns:on("receive", function(conn, pl)
|
||||
print("receiving...")
|
||||
print(pl)
|
||||
end)
|
||||
|
||||
srv_zdyndns:on("connection", function(sck)
|
||||
if verbose then print("connected & sending...") end
|
||||
sck:send(zdyndns_str, function(sk)
|
||||
sk:close()
|
||||
if verbose then print("close...") end
|
||||
zdyndns_str=nil zip=nil srv_zdyndns=nil send_zdyndns=nil
|
||||
if verbose then print("End zdyndns:\n"..node.heap()) end
|
||||
collectgarbage()
|
||||
if verbose then print(node.heap()) end
|
||||
end)
|
||||
end)
|
||||
|
||||
srv_zdyndns:connect(zdyndns_port,zdyndns_host)
|
||||
|
||||
end
|
||||
|
||||
send_zdyndns()
|
||||
37
Mesures/energy/transfo_courant_clip_1p/_secrets_project.lua_
Normal file
37
Mesures/energy/transfo_courant_clip_1p/_secrets_project.lua_
Normal file
@@ -0,0 +1,37 @@
|
||||
-- Petit script pour configurer les secrets dans ce projet
|
||||
-- et que l'on n'aimerait pas être exportés sur Internet (github)
|
||||
-- Il faut donc modifier le .gitignore avec secrets*.lua
|
||||
-- il faut le renommer en 'secrets_project.lua' et sera exécuté
|
||||
-- par 'wifi_init.lua' au moment du boot
|
||||
|
||||
-- pour récupérer l'ID de son NodeMCU il faut faire:
|
||||
-- print(node.chipid())
|
||||
|
||||
|
||||
function secrets_project()
|
||||
print("\n secrets_project.lua zf200131.1058 \n")
|
||||
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
zBTN=3
|
||||
|
||||
node_id = "generic"
|
||||
if node.chipid() == 6734851 then node_id = "sonoff_1" zLED=7 end
|
||||
if node.chipid() == 16110605 then node_id = "sonoff_2" zLED=7 end
|
||||
if node.chipid() == 3049119 then node_id = "adc_1" end
|
||||
if node.chipid() == 3048906 then
|
||||
node_id = "bolo_1"
|
||||
thingspeak_url="http://api.thingspeak.com/update?api_key=kkk&"
|
||||
end
|
||||
if node.chipid() == 3049014 then
|
||||
node_id = "tst_temp_1"
|
||||
thingspeak_url="http://api.thingspeak.com/update?api_key=kkk&"
|
||||
end
|
||||
print("node_id: "..node_id)
|
||||
end
|
||||
secrets_project()
|
||||
secrets_project=nil
|
||||
|
||||
--[[
|
||||
=node.chipid()
|
||||
]]
|
||||
18
Mesures/energy/transfo_courant_clip_1p/_secrets_wifi.lua_
Normal file
18
Mesures/energy/transfo_courant_clip_1p/_secrets_wifi.lua_
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Petit script pour configurer les secrets utilisés pour le wifi
|
||||
-- et que l'on n'aimerait pas être exportés sur Internet (github)
|
||||
-- Il faut donc modifier le .gitignore avec eus_params* et secret*
|
||||
-- il faut le renommer en 'secrets_wifi.lua' et sera exécuté
|
||||
-- par 'wifi_init.lua' une fois pour la configuration du WIFI
|
||||
|
||||
function secrets_wifi()
|
||||
print("\n secrets_wifi.lua zf191222.2002 \n")
|
||||
f= "eus_params.lua" if file.exists(f) then p = dofile(f) end
|
||||
if p ~= nil then
|
||||
cli_ssid = p.wifi_ssid cli_pwd = p.wifi_password p=nil
|
||||
else
|
||||
cli_ssid = "" cli_pwd = ""
|
||||
end
|
||||
ap_ssid="NodeMCU" ap_pwd="ppp"
|
||||
end
|
||||
|
||||
secrets_wifi()
|
||||
@@ -1,5 +1,49 @@
|
||||
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
|
||||
# zf191026.0913
|
||||
# zf200527.1853
|
||||
|
||||
|
||||
Todo à faire pour ce projet !
|
||||
|
||||
|
||||
- faire la documentation pour le fonctionnement de concept de rtelnet dans un fichier à part .md
|
||||
- y regarder pour faire tourner en MEME temps le reverse et le forward telnet
|
||||
- z lancement ou arrêt du WEBIDE via la home page
|
||||
v- ajouter fonction restart dans z_index.html (ATTENTION avec un argument restart, pas besoin de faire une page restart.html !)
|
||||
v- ajouter l'adresse du zdyndns dans les secrets projets
|
||||
v- ajouter l'affichage du node_id dans z_index.html
|
||||
v- ajouter le web_srv2 dans boot au lieu de boot2
|
||||
v- ajouter un état du RELAY et de la LED dans z_index.html
|
||||
v- ajouter une page affichage variables globales
|
||||
v- améliorer api_sonoff.html, il faut ajouter 'home' sur la page
|
||||
v- améliorer le résultat de api_sonoff.html, il faut sortir l'état des IO lors d'un changement comme confirmation
|
||||
v- arrêter de demander de connecter le WIFI automatiquement en mode station juste après le boot dans la config wifiinit (automatic connect)
|
||||
v- clignoter la led à chaque mesure en fonction de verbose
|
||||
v- copier secrets_project et secrets_wifi dans _secrets_project_ _secrets_wifi_ pour la documentation
|
||||
v- déplacer le mode AP dans wifi_init
|
||||
v- enlever la ligne wifi init dans z_index.html
|
||||
v- faire la page web service pour allumer la LED
|
||||
v- faire la page web service pour allumer le relay
|
||||
v- faire que send_data et read_temp soient lancés à la volée afin d'économiser de la RAM quand ce n'est pas utilisé
|
||||
v- garder variable node_id pour identification après poweron général, reattribution adrs ip sur modem 4G
|
||||
v- if verbose print partout dans *.lua
|
||||
v- le wifi setup ne fonctionne toujours pas quand il y a déjà un ap de connecté (problème du reboot quand adrs ip ok)!
|
||||
v- mettre le numéro jaune du nodemcu dans les secrets projet et prendre 23000+num_jaune comme numéro de port pour le reverse telnet
|
||||
v- passer à 10 secondes la seconde chance
|
||||
v- passer à 15x les tentatives de connexions au WIFI
|
||||
v- refaire le fichier _secrets_project.lua_ à partir de secrets_project.lua
|
||||
v- regarder pour mettre "Welcome to NodeMCU world." quand connected, en fait quand on arrive dans le telnet_listener après la redirection du port série !
|
||||
v- se connecter sur le zdyndns avec le numéro du port du telnet reverse utilisé
|
||||
v- terminer la page .html affichage de la température et de l'humidité
|
||||
v- terminer le reverse telnet ;-)
|
||||
v- trouver un moyen pour configurer la lED dans initz.lua sans le rendre dangereux en cas de problème (éviter le reflashing en cas de reboot loop)
|
||||
v- utiliser le bouton pour piloter le verbose
|
||||
v- vérifier le fonctionnement d'allumer la LED, car ne marche plus !
|
||||
x- ajouter argument ok dans wifi_init.html (sécurité)
|
||||
x- mettre ZLED2 et ZRELAY dans secrets_project
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# si luatool ne marche pas sur le MAC, il faut lire ceci:
|
||||
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0
|
||||
@@ -11,34 +55,167 @@
|
||||
|
||||
# définitions à faire AVANT !
|
||||
export luatool_tty="/dev/cu.wchusbserial1410"
|
||||
export zIP="192.168.0.135"
|
||||
|
||||
export zIP="192.168.0.182"
|
||||
export zport="23"
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="23000"
|
||||
ATTENTION: voir les tunnels tout à la fin !
|
||||
|
||||
|
||||
# ouvrir et fermer (ALT+n+.) une session telnet sur le NodeMCU avec l'adresse zIP)
|
||||
telnet -rN $zIP
|
||||
# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP)
|
||||
telnet -rN $zIP $zport
|
||||
~.
|
||||
node.restart()
|
||||
--node.restart()
|
||||
collectgarbage()
|
||||
=node.heap()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
|
||||
################################
|
||||
# commandes lua pour ce projet #
|
||||
################################
|
||||
ssh ubuntu@www.zuzu-test.ml killall -9 socat
|
||||
killall -9 ssh
|
||||
ssh ubuntu@www.zuzu-test.ml socat TCP-LISTEN:23043,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1 &
|
||||
watch -n 1 'ssh ubuntu@www.zuzu-test.ml netstat -nat |grep 230'
|
||||
ALT+CMD+F CTRL+C ALT+CMD+F
|
||||
ssh -N -L 23000:localhost:23000 ubuntu@www.zuzu-test.ml &
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="23000"
|
||||
|
||||
telnet -rN $zIP $zport
|
||||
verbose=false
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
verbose=true
|
||||
~.
|
||||
#zdyn
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f boot.lua
|
||||
./luatool.py --ip $zIP:$zport -f z_index.html
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f 0_send_data.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_cron.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_http_post.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_htu21d.lua
|
||||
|
||||
./luatool.py --ip $zIP:$zport --zrestart
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f api_sonoff.html
|
||||
http://192.168.0.182
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f dir.lua
|
||||
|
||||
telnet -rN $zIP $zport
|
||||
verbose=false
|
||||
verbose=true
|
||||
~.
|
||||
|
||||
=node.heap()
|
||||
collectgarbage()
|
||||
=node.heap()
|
||||
|
||||
|
||||
# commandes lua pour ce projet
|
||||
verbose=true
|
||||
verbose=false
|
||||
|
||||
|
||||
#commandes luatool pour ce projet
|
||||
./luatool.py --ip $zIP -f 0_get_data.lua
|
||||
./luatool.py --ip $zIP -f 0_send_data.lua
|
||||
./luatool.py --ip $zIP -f cat.lua
|
||||
dofile("dir.lua")
|
||||
dir()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
dofile("wifi_info.lua")
|
||||
|
||||
node.restart()
|
||||
|
||||
~.
|
||||
./luatool.py --ip $zIP -f head.lua
|
||||
telnet -rN $zIP
|
||||
./luatool.py --ip $zIP:$zport -f head.lua
|
||||
telnet -rN $zIP $zport
|
||||
dofile("head.lua")
|
||||
zhead("telnet_srv2.lua")
|
||||
zhead("boot.lua")
|
||||
|
||||
|
||||
|
||||
verbose=true
|
||||
verbose=false
|
||||
zsort_rssi() zshow()
|
||||
|
||||
|
||||
#commandes luatool pour ce projet le .137 est à jour avec la nouvelle version du wifi !
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
./luatool.py --ip $zIP:$zport -f wifi_init.lua
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f secrets_wifi.lua
|
||||
./luatool.py --ip $zIP:$zport -f initz.lua -t init.lua
|
||||
./luatool.py --ip $zIP:$zport -f boot.lua
|
||||
./luatool.py --ip $zIP:$zport -f boot2.lua
|
||||
./luatool.py --ip $zIP:$zport -f wifi_init.lua
|
||||
./luatool.py --ip $zIP:$zport -f set_time.lua
|
||||
./luatool.py --ip $zIP:$zport -f wifi_info.lua
|
||||
./luatool.py --ip $zIP:$zport -f c.lua
|
||||
./luatool.py --ip $zIP:$zport -f cat.lua
|
||||
./luatool.py --ip $zIP:$zport -f flash_led_xfois.lua
|
||||
./luatool.py --ip $zIP:$zport -f head.lua
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f b.lua
|
||||
./luatool.py --ip $zIP:$zport -f web_srv2.lua
|
||||
./luatool.py --ip $zIP:$zport -f z_index.html
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f wifi_get_conf.html
|
||||
./luatool.py --ip $zIP:$zport -f wifi_set_conf.html
|
||||
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f z_page1.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page2.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page3.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page4.html
|
||||
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_ap_start.lua
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_cli_conf.lua
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_cli_start.lua
|
||||
./luatool.py --ip $zIP:$zport --delete dir.lua
|
||||
./luatool.py --ip $zIP:$zport --delete initz.lua
|
||||
./luatool.py --ip $zIP:$zport --delete wifi_conf.lua
|
||||
|
||||
|
||||
|
||||
dofile("wifi_info.lua")
|
||||
--node.restart()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
t=12
|
||||
t=nil
|
||||
print(pcall(function () print("2"..t) end))
|
||||
|
||||
|
||||
|
||||
# ici c'est maintenant ;-)
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -f b.lua
|
||||
#./luatool.py --ip $zIP:$zport --zrestart
|
||||
telnet -rN $zIP $zport
|
||||
zsort_rssi() zshow()
|
||||
print(ztrig_rssi)
|
||||
ztrig_rssi=-1000
|
||||
ztrig_rssi=-90
|
||||
|
||||
|
||||
|
||||
# test de la gestion des erreurs
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -f c.lua
|
||||
#./luatool.py --ip $zIP:$zport --zrestart
|
||||
telnet -rN $zIP $zport
|
||||
status, err = pcall(function () dofile("c.lua") end) if status==false then print("Error: ",err) end
|
||||
zerr=nil
|
||||
zerr=1
|
||||
ztmr_tst_err:unregister()
|
||||
|
||||
|
||||
|
||||
|
||||
ztmr_tst_err:unregister()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
./luatool.py --ip $zIP --zrestart
|
||||
|
||||
|
||||
@@ -49,7 +226,91 @@ cat("boot2.lua")
|
||||
|
||||
# commandes luatool
|
||||
./luatool.py -h
|
||||
./luatool.py --ip $zIP -i
|
||||
./luatool.py --ip $zIP -l
|
||||
./luatool.py --ip $zIP -f toto.lua -d
|
||||
./luatool.py --ip $zIP --delete toto.lua
|
||||
./luatool.py --ip $zIP:$zport -i
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
./luatool.py --ip $zIP:$zport -f toto.lua -d
|
||||
./luatool.py --ip $zIP:$zport --delete toto.lua
|
||||
|
||||
|
||||
|
||||
****************************************************************************
|
||||
|
||||
|
||||
# création des tunnels ssh
|
||||
ATTENTION: dans un premier terminal !
|
||||
Pour Bolo à Ruchonnet:
|
||||
ssh -t -L 2323:localhost:2323 ubuntu@www.zuzu-test.ml ssh -N -L 2323:192.168.8.102:23 ubuntu@localhost -p 20223
|
||||
|
||||
Pour le Crêt
|
||||
ssh -N -L 2323:192.168.0.137:23 admin@z.zufferey.com -p 1822
|
||||
ssh -N -L 2323:192.168.0.122:23 admin@z.zufferey.com -p 1822
|
||||
ssh -N -L 2323:192.168.0.118:23 admin@z.zufferey.com -p 1822
|
||||
|
||||
ATTENTION: dans un deuxième terminal !
|
||||
export zIP="localhost"
|
||||
export zport="2323"
|
||||
telnet -rN $zIP $zport
|
||||
~.
|
||||
=node.heap()
|
||||
|
||||
verbose=false
|
||||
verbose=true
|
||||
|
||||
dofile("dir2.lua")
|
||||
dir()
|
||||
filec("head.lua")
|
||||
|
||||
dofile("head.lua")
|
||||
zhead("dir2.lua")
|
||||
|
||||
dofile("cat.lua")
|
||||
cat("head.lua")
|
||||
|
||||
~.
|
||||
--node.restart()
|
||||
=node.heap()
|
||||
|
||||
|
||||
status, err = pcall(function () fonction_a_tester() end) if status==false then print("Error: ",err) end
|
||||
status, err = pcall(function () toto() end) if status==false then print("Error: ",err) end
|
||||
|
||||
|
||||
|
||||
Gestion de la passerelle SSH reverse
|
||||
Puis depuis une autre console on peut faire directement pour aller sur l'OpiZ (ici le 20223):
|
||||
ssh -t ubuntu@www.zuzu-test.ml ssh ubuntu@localhost -p 20223
|
||||
|
||||
ou
|
||||
|
||||
1ère console
|
||||
On établit le tunnel local avec l'OpiZ
|
||||
ssh -N -L 20223:localhost:20223 ubuntu@www.zuzu-test.ml
|
||||
|
||||
|
||||
2ème console, on utilise le tunnel OpiZ en local sur sa machine
|
||||
pour aller sur l'OpiZ
|
||||
ssh ubuntu@localhost -p 20223
|
||||
|
||||
pour copier sa clef SSH depuis un MAC
|
||||
./ssh-copy-id -i ~/.ssh/id_rsa.pub 'ubuntu@localhost -p 20223'
|
||||
après on devrait pouvoir se connecter sans devoir entrer son password à chaque fois
|
||||
ssh ubuntu@localhost -p 20223
|
||||
|
||||
ou, on établit un tunnel pour telnet sur un NodeMCU
|
||||
ssh -L 2323:192.168.0.137:23 ubuntu@localhost -p 20223
|
||||
puis
|
||||
telnet -rN localhost 2323
|
||||
|
||||
ou, on établit un tunnel pour le rpimonotor sur l'OpiZ
|
||||
ssh -N -L 8888:192.168.0.113:8888 ubuntu@localhost -p 20223
|
||||
puis
|
||||
http://localhost:8888
|
||||
|
||||
ou, on établit un tunnel proxy Socket 5 pour le modem 4G HUAWEI sur l'OpiZ
|
||||
ssh -N -D 8080 ubuntu@localhost -p 20223
|
||||
puis depuis le browser FireFox avec le plugin FoxyProxy Socket 5 sur localhost port 8080
|
||||
http://192.168.8.1
|
||||
|
||||
|
||||
|
||||
.
|
||||
|
||||
@@ -1,15 +1,35 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot.lua zf190916.2359 \n")
|
||||
print("\n boot.lua zf200530.1211 \n")
|
||||
|
||||
-- charge ses propres secrets
|
||||
f= "secrets_energy.lua" if file.exists(f) then dofile(f) end
|
||||
-- function ztime_stamp() return tmr.now()/1000000 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_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
function boot()
|
||||
verbose = false
|
||||
print("On lance le boot...")
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
f = "0_http_post.lua" if file.exists(f) then dofile(f) end
|
||||
http_post(influxdb_url,"energy,memory=boot_"..yellow_id.." ram="..node.heap())
|
||||
|
||||
-- f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
-- print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
|
||||
-- print(node.heap()) collectgarbage() print(node.heap())
|
||||
|
||||
f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
print("verbose:",verbose) print("boot lancé...")
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
f=nil boot=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end
|
||||
boot()
|
||||
|
||||
--[[
|
||||
verbose = true
|
||||
verbose = false
|
||||
]]
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
-- fonction dir() pour afficher les fichiers dans la flash
|
||||
print("\n dir.lua zf180826.1019 \n")
|
||||
-- fonction dir() pour juste afficher les fichiers avec leur taille
|
||||
|
||||
print("\n dir2.lua zf191223.1455 \n")
|
||||
|
||||
function dir()
|
||||
print("\n-------------------------------")
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
|
||||
local zdir={}
|
||||
local pfile = file.list()
|
||||
for k,v in pairs(pfile) do
|
||||
zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v
|
||||
end
|
||||
print("-------------------------------")
|
||||
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
|
||||
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
|
||||
size_file=nil chksum_file=nil k=nil
|
||||
end
|
||||
|
||||
dir()
|
||||
print("\nusage:")
|
||||
print(" dir()")
|
||||
|
||||
--[[
|
||||
dir()
|
||||
dirc()
|
||||
filec("dir2.lua")
|
||||
|
||||
=node.heap()
|
||||
clear_dir()
|
||||
=node.heap()
|
||||
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
|
||||
]]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- fonction cat() pour afficher les 10 premières lignes d'un fichier dans la flash
|
||||
print("\n head.lua zf192026.0942 \n")
|
||||
print("\n head.lua zf192028.1516 \n")
|
||||
|
||||
function zhead(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
@@ -3,61 +3,82 @@
|
||||
-- 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 zf190917.0001 \n")
|
||||
print("\n init.lua zf200530.1228 \n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
function initz()
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
initalarme:unregister() initalarme2:unregister()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
function initz_end()
|
||||
print("initz_end...")
|
||||
f= "wifi_init.lua" if file.exists(f) then dofile(f) end
|
||||
f=nil initz=nil second_chance=nil hvbouton=nil initz_end=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
print("initz_end out...")
|
||||
end
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none") zswitch=nil
|
||||
print("hvbouton...")
|
||||
print(tmr.now())
|
||||
if tmr.now() > 5000000 then
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
print("on a demandé le setup wifi !")
|
||||
end
|
||||
initalarme1:unregister() initalarme1=nil second_chance=nil
|
||||
gpio.write(zLED, gpio.HIGH) zLED=nil
|
||||
reset_reason="hvbouton"
|
||||
initz_end()
|
||||
end
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
zLED=4 -- NodeMCU
|
||||
--zLED=7 -- SonOff
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
initalarme1=tmr.create()
|
||||
initalarme1:alarm(10*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.write(zLED, gpio.HIGH) zLED=nil
|
||||
gpio.trig(zswitch, "none") zswitch=nil
|
||||
reset_reason="seconde_chance"
|
||||
initz_end()
|
||||
end)
|
||||
zswitch=3 --switch flash ou SonOff
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
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")
|
||||
initz_end()
|
||||
elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
initz_end()
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
end
|
||||
initz()
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
end
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason:",reset_reason)
|
||||
if reset_reason == 0 then
|
||||
print("power on")
|
||||
second_chance()
|
||||
elseif reset_reason == 4 then
|
||||
print("node.restart")
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
second_chance=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
--[[
|
||||
zLED=7
|
||||
gpio.mode(zLED, gpio.OUTPUT)
|
||||
gpio.write(zLED, gpio.LOW) -- actif !
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
|
||||
zBTN=3
|
||||
gpio.mode(zBTN, gpio.INPUT)
|
||||
print(gpio.read(zBTN))
|
||||
|
||||
zRELAY=6
|
||||
gpio.mode(zRELAY, gpio.OUTPUT)
|
||||
gpio.write(zRELAY, gpio.HIGH) -- actif !
|
||||
gpio.write(zRELAY, gpio.LOW)
|
||||
]]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
version = "0.6.5 zf191021.1558"
|
||||
version = "0.6.8 zf191225.1428"
|
||||
|
||||
print("luatool.py ver " + version)
|
||||
|
||||
@@ -68,6 +68,8 @@ class AbstractTransport:
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writer(self, data):
|
||||
##zzz191124 enlève la fin de ligne afin de ne pas perturber la vérification finale
|
||||
data = data.rstrip('\r\n')
|
||||
self.writeln("file.writeline([==[" + data + "]==])\r")
|
||||
|
||||
def performcheck(self, expected):
|
||||
@@ -80,7 +82,7 @@ class AbstractTransport:
|
||||
raise Exception('No proper answer from MCU')
|
||||
if char == chr(13) or char == chr(10): # LF or CR
|
||||
if line != '':
|
||||
line = line.strip()
|
||||
#zzz191124 line = line.strip()
|
||||
# zzz191021 Affiche ce que l'on a reçu du NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzread0957: {" + line + "\n}\n")
|
||||
@@ -144,7 +146,10 @@ class SerialTransport(AbstractTransport):
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
##zzz191124 attend encore un petit peu avant d'envoyer
|
||||
sleep(self.delay)
|
||||
self.serial.write(data)
|
||||
sleep(self.delay)
|
||||
# zzz191021 Affiche ce que l'on a envoyé au NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzwrite0952: {" + data + "\n}\n")
|
||||
@@ -213,7 +218,7 @@ if __name__ == '__main__':
|
||||
# parse arguments or use defaults
|
||||
parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.')
|
||||
parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line')
|
||||
parser.add_argument('--delay', default=0.03, help='Delay in seconds between each write, default 0.03 sec.', type=float)
|
||||
parser.add_argument('--delay', default=0.025, help='Delay in seconds between each write, default 0.03 sec.', type=float)
|
||||
parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.')
|
||||
parser.add_argument('--ip', default=None, help='Connect via telnet server (--ip IP[:port])')
|
||||
parser.add_argument('--zrestart', action='store_true', help='Restart the NodeMCU.')
|
||||
@@ -242,7 +247,10 @@ if __name__ == '__main__':
|
||||
|
||||
if args.list:
|
||||
# zzz191020 Amélioré la sortie du listing des fichiers
|
||||
transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0)
|
||||
#transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0)
|
||||
# zzz191225 Amélioré encore la sortie du listing des fichiers (sort file)
|
||||
transport.writeln("zdir={};pfile = file.list();for k,v in pairs(pfile) do zdir[#zdir+1] = k..string.rep(' ',24-string.len(k))..' : '..v end;table.sort(zdir);print('\\n-----');for i=1, #zdir do print(zdir[i]) end;print('-----\\n');zdir=nil;pfile=nil;k=nil;v=nil;i=nil\r", 0)
|
||||
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62): # '' or '>'
|
||||
@@ -354,11 +362,13 @@ if __name__ == '__main__':
|
||||
sys.stderr.write("\r\nStage 3. Start writing data to flash memory...")
|
||||
if args.bar:
|
||||
for i in tqdm(range(0, num_lines)):
|
||||
transport.writer(line.strip())
|
||||
#zzz191124 transport.writer(line.strip())
|
||||
transport.writer(line)
|
||||
line = f.readline()
|
||||
else:
|
||||
while line != '':
|
||||
transport.writer(line.strip())
|
||||
#zzz191124 transport.writer(line.strip())
|
||||
transport.writer(line)
|
||||
line = f.readline()
|
||||
|
||||
# close both files
|
||||
|
||||
13
Mesures/energy/transfo_courant_clip_1p/oldies/0_cron.lua
Normal file
13
Mesures/energy/transfo_courant_clip_1p/oldies/0_cron.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Petit script pour faire office de crontab pour les
|
||||
--mesures
|
||||
print("\n 0_cron.lua zf190917.0033 \n")
|
||||
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
flash_led_xfois()
|
||||
xfois =2
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
|
||||
blink_LED ()
|
||||
send_data()
|
||||
end)
|
||||
@@ -0,0 +1,55 @@
|
||||
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
|
||||
# zf191026.0913
|
||||
|
||||
# si luatool ne marche pas sur le MAC, il faut lire ceci:
|
||||
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0
|
||||
|
||||
# raccourcis clavier
|
||||
# CTRL+ALT+ENTER envoie au terminal la ligne de l'éditeur
|
||||
# SHIT+CTRL+` ouvre le terminal (attention, ne pas oublier de copier le *path* dans le *tree* et le changer)
|
||||
# ALT+CMD+F bascule entre le terminal et l'éditeur
|
||||
|
||||
# définitions à faire AVANT !
|
||||
export luatool_tty="/dev/cu.wchusbserial1410"
|
||||
export zIP="192.168.0.135"
|
||||
|
||||
|
||||
# ouvrir et fermer (ALT+n+.) une session telnet sur le NodeMCU avec l'adresse zIP)
|
||||
telnet -rN $zIP
|
||||
~.
|
||||
node.restart()
|
||||
=node.heap()
|
||||
|
||||
|
||||
# commandes lua pour ce projet
|
||||
verbose=true
|
||||
verbose=false
|
||||
|
||||
|
||||
#commandes luatool pour ce projet
|
||||
./luatool.py --ip $zIP -f 0_get_data.lua
|
||||
./luatool.py --ip $zIP -f 0_send_data.lua
|
||||
./luatool.py --ip $zIP -f cat.lua
|
||||
|
||||
|
||||
~.
|
||||
./luatool.py --ip $zIP -f head.lua
|
||||
telnet -rN $zIP
|
||||
dofile("head.lua")
|
||||
zhead("telnet_srv2.lua")
|
||||
|
||||
|
||||
./luatool.py --ip $zIP --zrestart
|
||||
|
||||
|
||||
# faire un cat d'un fichier sur le NodeMCU
|
||||
dofile("cat.lua")
|
||||
cat("boot2.lua")
|
||||
|
||||
|
||||
# commandes luatool
|
||||
./luatool.py -h
|
||||
./luatool.py --ip $zIP -i
|
||||
./luatool.py --ip $zIP -l
|
||||
./luatool.py --ip $zIP -f toto.lua -d
|
||||
./luatool.py --ip $zIP --delete toto.lua
|
||||
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- ATTENTION, la longueur des lignes DOIT être <128 ! -->
|
||||
|
||||
<html lang="fr" dir="ltr">
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>API SonOff</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>API SonOff zf200118.1812</h1>
|
||||
<a href="/">Home...</a><br><br>
|
||||
<%
|
||||
if _GET.LED == "on" then
|
||||
gpio.write(zLED, gpio.LOW) gpio.mode(zLED, gpio.OUTPUT)
|
||||
zout("LED=".._GET.LED.."<br>")
|
||||
zout('<a href="api_sonoff.html?LED=off"> Off</a><br>')
|
||||
|
||||
end
|
||||
if _GET.LED == "off" then
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
zout("LED=".._GET.LED.."<br>")
|
||||
zout('<a href="api_sonoff.html?LED=on"> On</a>')
|
||||
end
|
||||
%>
|
||||
<%
|
||||
if _GET.RELAY == "on" then
|
||||
gpio.mode(zRELAY, gpio.OUTPUT) gpio.write(zRELAY, gpio.HIGH)
|
||||
zout("RELAY=".._GET.RELAY.."<br>")
|
||||
zout('<a href="api_sonoff.html?RELAY=off"> Off</a><br>')
|
||||
end
|
||||
if _GET.RELAY == "off" then
|
||||
gpio.mode(zRELAY, gpio.OUTPUT) gpio.write(zRELAY, gpio.LOW)
|
||||
zout("RELAY=".._GET.RELAY.."<br>")
|
||||
zout('<a href="api_sonoff.html?RELAY=on"> On</a>')
|
||||
end
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
15
Mesures/energy/transfo_courant_clip_1p/oldies/boot.lua
Normal file
15
Mesures/energy/transfo_courant_clip_1p/oldies/boot.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf190916.2359 \n")
|
||||
|
||||
-- charge ses propres secrets
|
||||
f= "secrets_energy.lua" if file.exists(f) then dofile(f) 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_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
15
Mesures/energy/transfo_courant_clip_1p/oldies/dir.lua
Normal file
15
Mesures/energy/transfo_courant_clip_1p/oldies/dir.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- fonction dir() pour afficher les fichiers dans la flash
|
||||
print("\n dir.lua zf180826.1019 \n")
|
||||
|
||||
function dir()
|
||||
print("\n-------------------------------")
|
||||
l=file.list() i=0
|
||||
for k,v in pairs(l) do
|
||||
i=i+v
|
||||
print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes")
|
||||
end
|
||||
print("-------------------------------")
|
||||
print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
|
||||
end
|
||||
|
||||
dir()
|
||||
23
Mesures/energy/transfo_courant_clip_1p/oldies/disp_temp.html
Normal file
23
Mesures/energy/transfo_courant_clip_1p/oldies/disp_temp.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>Affichage de la température et humidité</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Affichage de la température et humidité 200118.1800</h1>
|
||||
<a href="/">Home...</a><br>
|
||||
<%
|
||||
zout("<h1>"..node_id.." 200112.1919 </h1>")
|
||||
%>
|
||||
<br>
|
||||
<%
|
||||
zout("Température: "..readTemp().." °C<br>")
|
||||
zout("Humidité: "..readHumi().." %<br>")
|
||||
|
||||
zout("<br><br>RAM: "..node.heap().."<br>")
|
||||
%>
|
||||
</body>
|
||||
</html>
|
||||
19
Mesures/energy/transfo_courant_clip_1p/oldies/head.lua
Normal file
19
Mesures/energy/transfo_courant_clip_1p/oldies/head.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
-- fonction cat() pour afficher les 10 premières lignes d'un fichier dans la flash
|
||||
print("\n head.lua zf192026.0942 \n")
|
||||
|
||||
function zhead(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
zfilei = file.open(zfile, "r")
|
||||
i=1
|
||||
zline=file.readline()
|
||||
repeat
|
||||
-- print(i..": "..string.sub(zline,1,string.len(zline)-1))
|
||||
print(string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
if i>10 then break end
|
||||
until zline==nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
63
Mesures/energy/transfo_courant_clip_1p/oldies/initz.lua
Normal file
63
Mesures/energy/transfo_courant_clip_1p/oldies/initz.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
--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 zf190917.0001 \n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
initalarme:unregister() initalarme2:unregister()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
end
|
||||
|
||||
_, reset_reason = node.bootreason()
|
||||
print("reset_reason:",reset_reason)
|
||||
if reset_reason == 0 then
|
||||
print("power on")
|
||||
second_chance()
|
||||
elseif reset_reason == 4 then
|
||||
print("node.restart")
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
second_chance=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 5 then
|
||||
print("dsleep wake up")
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
|
||||
|
||||
398
Mesures/energy/transfo_courant_clip_1p/oldies/luatool.py
Executable file
398
Mesures/energy/transfo_courant_clip_1p/oldies/luatool.py
Executable file
@@ -0,0 +1,398 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
version = "0.6.5 zf191021.1558"
|
||||
|
||||
print("luatool.py ver " + version)
|
||||
|
||||
#Améliorations
|
||||
# Pour voir les améliorations il faut 'chercher' les zzz
|
||||
|
||||
|
||||
#
|
||||
# ESP8266 luatool
|
||||
# Author e-mail: 4ref0nt@gmail.com
|
||||
# Site: http://esp8266.ru
|
||||
# Contributions from: https://github.com/sej7278
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
||||
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
import sys
|
||||
import serial
|
||||
from time import sleep
|
||||
import socket
|
||||
import argparse
|
||||
from os.path import basename
|
||||
|
||||
|
||||
tqdm_installed = True
|
||||
try:
|
||||
from tqdm import tqdm
|
||||
except ImportError, e:
|
||||
if e.message == 'No module named tqdm':
|
||||
tqdm_installed = False
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
|
||||
class TransportError(Exception):
|
||||
"""Custom exception to represent errors with a transport
|
||||
"""
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
class AbstractTransport:
|
||||
def __init__(self):
|
||||
raise NotImplementedError('abstract transports cannot be instantiated.')
|
||||
|
||||
def close(self):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def read(self, length):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writer(self, data):
|
||||
self.writeln("file.writeline([==[" + data + "]==])\r")
|
||||
|
||||
def performcheck(self, expected):
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
if char == chr(13) or char == chr(10): # LF or CR
|
||||
if line != '':
|
||||
line = line.strip()
|
||||
# zzz191021 Affiche ce que l'on a reçu du NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzread0957: {" + line + "\n}\n")
|
||||
|
||||
if line+'\r' == expected and not args.bar:
|
||||
sys.stdout.write(" -> ok")
|
||||
elif line+'\r' != expected:
|
||||
if line[:4] == "lua:":
|
||||
sys.stdout.write("\r\n\r\nLua ERROR: %s" % line)
|
||||
raise Exception('ERROR from Lua interpreter\r\n\r\n')
|
||||
else:
|
||||
expected = expected.split("\r")[0]
|
||||
sys.stdout.write("\r\n\r\nERROR")
|
||||
sys.stdout.write("\r\n send string : '%s'" % expected)
|
||||
sys.stdout.write("\r\n expected echo : '%s'" % expected)
|
||||
sys.stdout.write("\r\n but got answer : '%s'" % line)
|
||||
sys.stdout.write("\r\n\r\n")
|
||||
raise Exception('Error sending data to MCU\r\n\r\n')
|
||||
line = ''
|
||||
else:
|
||||
line += char
|
||||
if char == chr(62) and expected[i] == char:
|
||||
char = ''
|
||||
i += 1
|
||||
|
||||
|
||||
class SerialTransport(AbstractTransport):
|
||||
def __init__(self, port, baud, delay):
|
||||
self.port = port
|
||||
self.baud = baud
|
||||
self.serial = None
|
||||
self.delay = delay
|
||||
|
||||
try:
|
||||
self.serial = serial.Serial(port, baud)
|
||||
except serial.SerialException as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
self.serial.timeout = 3
|
||||
self.serial.interCharTimeout = 3
|
||||
|
||||
# zzz191021 juste après l'ouverture du port série, on attend le caractère '>'
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
line += char
|
||||
i += 1
|
||||
if args.verbose:
|
||||
print("line: ." + line + ".")
|
||||
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
# zzz191020 on fait une petite pause avant l'envoi de chaque ligne
|
||||
sleep(self.delay)
|
||||
if self.serial.inWaiting() > 0:
|
||||
self.serial.flushInput()
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
self.serial.write(data)
|
||||
# zzz191021 Affiche ce que l'on a envoyé au NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzwrite0952: {" + data + "\n}\n")
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.serial.read(length)
|
||||
|
||||
def close(self):
|
||||
self.serial.flush()
|
||||
self.serial.close()
|
||||
|
||||
|
||||
class TcpSocketTransport(AbstractTransport):
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.socket = None
|
||||
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
try:
|
||||
self.socket.connect((host, port))
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
# read intro from telnet server (see telnet_srv.lua)
|
||||
self.socket.recv(50)
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
self.socket.sendall(data)
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.socket.recv(length)
|
||||
|
||||
def close(self):
|
||||
self.socket.close()
|
||||
|
||||
|
||||
def decidetransport(cliargs):
|
||||
if cliargs.ip:
|
||||
data = cliargs.ip.split(':')
|
||||
host = data[0]
|
||||
if len(data) == 2:
|
||||
port = int(data[1])
|
||||
else:
|
||||
port = 23
|
||||
return TcpSocketTransport(host, port)
|
||||
else:
|
||||
return SerialTransport(cliargs.port, cliargs.baud, cliargs.delay)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# parse arguments or use defaults
|
||||
parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.')
|
||||
parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line')
|
||||
parser.add_argument('--delay', default=0.03, help='Delay in seconds between each write, default 0.03 sec.', type=float)
|
||||
parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.')
|
||||
parser.add_argument('--ip', default=None, help='Connect via telnet server (--ip IP[:port])')
|
||||
parser.add_argument('--zrestart', action='store_true', help='Restart the NodeMCU.')
|
||||
parser.add_argument('-a', '--append', action='store_true', help='Append source file to destination file.')
|
||||
parser.add_argument('-b', '--baud', default=115200, help='Baudrate, default 115200')
|
||||
parser.add_argument('-c', '--compile', action='store_true', help='Compile lua to lc after upload')
|
||||
parser.add_argument('-d', '--dofile', action='store_true', help='Run the Lua script after upload')
|
||||
parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.')
|
||||
parser.add_argument('-f', '--src', default='main.lua', help='Source file on computer, default main.lua')
|
||||
parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.')
|
||||
parser.add_argument('-l', '--list', action='store_true', help='List files on device')
|
||||
parser.add_argument('-p', '--port', default='/dev/ttyUSB0', help='Device name, default /dev/ttyUSB0')
|
||||
parser.add_argument('-r', '--restart', action='store_true', help='Restart MCU after upload')
|
||||
parser.add_argument('-t', '--dest', default=None, help='Destination file on MCU, default to source file name')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help="Show progress messages.")
|
||||
parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.')
|
||||
args = parser.parse_args()
|
||||
|
||||
transport = decidetransport(args)
|
||||
|
||||
if args.bar and not tqdm_installed:
|
||||
sys.stdout.write("You must install the tqdm library to use the bar feature\n")
|
||||
sys.stdout.write("To install, at the prompt type: \"pip install tqdm\"\n")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if args.list:
|
||||
# zzz191020 Amélioré la sortie du listing des fichiers
|
||||
transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0)
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62): # '' or '>'
|
||||
break
|
||||
sys.stdout.write(char)
|
||||
sys.exit(0)
|
||||
|
||||
if args.id:
|
||||
transport.writeln("=node.chipid()\r", 0)
|
||||
id=""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char.isdigit():
|
||||
id += char
|
||||
print("\n"+id)
|
||||
sys.exit(0)
|
||||
|
||||
# zzz191020 Ajouté la fonction restart seule
|
||||
if args.zrestart:
|
||||
transport.writeln("node.restart()\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.wipe:
|
||||
transport.writeln("local l = file.list();for k,v in pairs(l) do print(k)end\r", 0)
|
||||
file_list = []
|
||||
fn = ""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char not in ['\r', '\n']:
|
||||
fn += char
|
||||
else:
|
||||
if fn:
|
||||
file_list.append(fn.strip())
|
||||
fn = ''
|
||||
for fn in file_list[1:]: # first line is the list command sent to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("Delete file {} from device.\r\n".format(fn))
|
||||
transport.writeln("file.remove(\"" + fn + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.delete:
|
||||
transport.writeln("file.remove(\"" + args.delete + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.dest is None:
|
||||
args.dest = basename(args.src)
|
||||
# zzz191020 Affiche le fichier à envoyer
|
||||
print("File: " + args.src)
|
||||
|
||||
# open source file for reading
|
||||
try:
|
||||
try:
|
||||
f = open(args.src, "rt")
|
||||
except:
|
||||
import os
|
||||
base_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
f = open(os.path.join(base_dir, args.src), "rt")
|
||||
os.chdir(base_dir)
|
||||
except:
|
||||
sys.stderr.write("Could not open input file \"%s\"\n" % args.src)
|
||||
sys.exit(1)
|
||||
|
||||
# Verify the selected file will not exceed the size of the serial buffer.
|
||||
# The size of the buffer is 256. This script does not accept files with
|
||||
# lines longer than 230 characters to have some room for command overhead.
|
||||
num_lines = 0
|
||||
for ln in f:
|
||||
if len(ln) > 230:
|
||||
sys.stderr.write("File \"%s\" contains a line with more than 240 "
|
||||
"characters. This exceeds the size of the serial buffer.\n"
|
||||
% args.src)
|
||||
f.close()
|
||||
sys.exit(1)
|
||||
num_lines += 1
|
||||
|
||||
# Go back to the beginning of the file after verifying it has the correct
|
||||
# line length
|
||||
f.seek(0)
|
||||
|
||||
# set serial timeout
|
||||
if args.verbose:
|
||||
sys.stderr.write("Upload starting\r\n")
|
||||
|
||||
# remove existing file on device
|
||||
if args.append==False:
|
||||
if args.verbose:
|
||||
sys.stderr.write("Stage 1. Deleting old file from flash memory")
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w\")\r")
|
||||
transport.writeln("file.close()\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
else:
|
||||
if args.verbose:
|
||||
sys.stderr.write("[SKIPPED] Stage 1. Deleting old file from flash memory [SKIPPED]")
|
||||
|
||||
|
||||
# read source file line by line and write to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 2. Creating file in flash memory and write first line")
|
||||
if args.append:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"a+\")\r")
|
||||
else:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w+\")\r")
|
||||
line = f.readline()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 3. Start writing data to flash memory...")
|
||||
if args.bar:
|
||||
for i in tqdm(range(0, num_lines)):
|
||||
transport.writer(line.strip())
|
||||
line = f.readline()
|
||||
else:
|
||||
while line != '':
|
||||
transport.writer(line.strip())
|
||||
line = f.readline()
|
||||
|
||||
# close both files
|
||||
f.close()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 4. Flush data and closing file")
|
||||
transport.writeln("file.flush()\r")
|
||||
transport.writeln("file.close()\r")
|
||||
|
||||
# compile?
|
||||
if args.compile:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 5. Compiling")
|
||||
transport.writeln("node.compile(\"" + args.dest + "\")\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
|
||||
# restart or dofile
|
||||
if args.restart:
|
||||
transport.writeln("node.restart()\r")
|
||||
|
||||
if args.dofile: # never exec if restart=1
|
||||
transport.writeln("dofile(\"" + args.dest + "\")\r", 0)
|
||||
|
||||
if args.echo:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nEchoing MCU output, press Ctrl-C to exit")
|
||||
while True:
|
||||
sys.stdout.write(transport.read(1))
|
||||
|
||||
# close serial port
|
||||
transport.close()
|
||||
|
||||
# flush screen
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
if not args.bar:
|
||||
sys.stderr.write("\r\n--->>> All done <<<---\r\n")
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Petit WEB IDE tout simple autonome
|
||||
-- ATTENTION: tourne sur le port 88 !
|
||||
|
||||
print("\n web_ide2.lua zf190706.1430 \n")
|
||||
print("\n _web_ide2.lua zf181221.1137 \n")
|
||||
|
||||
--[[
|
||||
XChip's NodeMCU IDE
|
||||
@@ -14,8 +14,8 @@ http://<mcu_ip>/newfile.lua?edit allows to creates or edits the specified scrip
|
||||
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)
|
||||
srv=net.createServer(net.TCP)
|
||||
srv:listen(88,function(conn)
|
||||
|
||||
local rnrn=0
|
||||
local Status = 0
|
||||
@@ -24,15 +24,15 @@ srv:listen(88,function(conn)
|
||||
local url=""
|
||||
local vars=""
|
||||
|
||||
conn:on("receive",function(conn,payload)
|
||||
|
||||
conn:on("receive",function(conn,payload)
|
||||
|
||||
if Status==0 then
|
||||
_, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP")
|
||||
print(method, url, vars)
|
||||
print(method, url, vars)
|
||||
end
|
||||
|
||||
|
||||
if method=="POST" then
|
||||
|
||||
|
||||
if Status==0 then
|
||||
--print("status", Status)
|
||||
_,_,DataToGet, payload = string.find(payload, "Content%-Length: (%d+)(.+)")
|
||||
@@ -40,120 +40,120 @@ srv:listen(88,function(conn)
|
||||
DataToGet = tonumber(DataToGet)
|
||||
--print(DataToGet)
|
||||
rnrn=1
|
||||
Status = 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
|
||||
for i=1, payloadlen do
|
||||
if string.byte(mark, rnrn) == string.byte(payload, i) then
|
||||
rnrn=rnrn+1
|
||||
if rnrn==5 then
|
||||
if rnrn==5 then
|
||||
payload = string.sub(payload, i+1,payloadlen)
|
||||
file.open(url, "w")
|
||||
file.close()
|
||||
file.close()
|
||||
Status=2
|
||||
break
|
||||
end
|
||||
else
|
||||
rnrn=1
|
||||
end
|
||||
end
|
||||
if Status==1 then
|
||||
return
|
||||
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()
|
||||
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")
|
||||
if DataToGet==0 then
|
||||
conn:send("HTTP/1.1 200 OK\r\n\r\nOK")
|
||||
Status=0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
DataToGet = -1
|
||||
|
||||
|
||||
if url == "favicon.ico" then
|
||||
conn:send("HTTP/1.1 404 file not found")
|
||||
return
|
||||
end
|
||||
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
|
||||
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>")
|
||||
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(")
|
||||
conn:send("[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
|
||||
for k,v in pairs(l) do
|
||||
conn:send("<a href='"..k.."?edit'>"..k.."</a>, size:"..v.."<br>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
conn:send("</body></html>")
|
||||
|
||||
|
||||
end)
|
||||
conn:on("sent",function(conn)
|
||||
conn:on("sent",function(conn)
|
||||
if DataToGet>=0 and method=="GET" then
|
||||
if file.open(url, "r") 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
|
||||
|
||||
DataToGet = DataToGet + 512
|
||||
|
||||
if (string.len(line)==512) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
conn:close()
|
||||
|
||||
conn:close()
|
||||
end)
|
||||
end)
|
||||
print("listening, free:", node.heap())
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
-- petit script de serveur WEB avec Active Server Page ZYX
|
||||
-- permet d'exécuter du code LUA inline dans l'HTML !
|
||||
|
||||
print("\n web_srv2.lua zf190728.1021 \n")
|
||||
|
||||
ztemp=12
|
||||
print("\n web_srv2.lua zf200112.1926 \n")
|
||||
|
||||
-- envoie sur le port ouvert mais depuis l'environnement global !
|
||||
function zout(zstring)
|
||||
zzclient:send(zstring) -- envoie le résultat du code lua inline
|
||||
if string.len(zstring) > 0 then
|
||||
zzclient:send(zstring) -- envoie le résultat du code lua inline
|
||||
end
|
||||
end
|
||||
|
||||
-- envoie un fichier HTML sur le port. ATTENTION: longueur de la ligne maximale de 1'024 bytes !
|
||||
@@ -15,45 +16,36 @@ function send_file(zclient, zfilename)
|
||||
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
|
||||
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')
|
||||
local line = file_web:readline()
|
||||
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 !
|
||||
lua_code = nil
|
||||
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
|
||||
until not line
|
||||
file_web:close() file_web = nil flag_lua_code=nil zzclient=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("zrequest: \n---\n"..request.."---")
|
||||
|
||||
-- print("method: ", method) print("path: ", path) print("vars: ", vars)
|
||||
|
||||
if not string.find(request, "/favicon.ico") then
|
||||
print("coucou")
|
||||
if (method == nil) then
|
||||
@@ -68,11 +60,8 @@ srv:listen(80, function(conn)
|
||||
end
|
||||
end
|
||||
file_html=string.gsub(path, "/", "")
|
||||
-- print("file_html: ",file_html)
|
||||
send_file(client, file_html)
|
||||
send_file(client, file_html) file_html=nil _GET=nil
|
||||
end
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
|
||||
|
||||
33
Mesures/energy/transfo_courant_clip_1p/oldies/wifi_info.lua
Normal file
33
Mesures/energy/transfo_courant_clip_1p/oldies/wifi_info.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf190727.1220 \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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP")
|
||||
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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
print("AP MAC: ", wifi.ap.getmac())
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
end
|
||||
23
Mesures/energy/transfo_courant_clip_1p/oldies/z_index.html
Normal file
23
Mesures/energy/transfo_courant_clip_1p/oldies/z_index.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!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 190727.0941</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="z_page4.html?field1=11&field2=12&field3=13">Page 4, test de récupération d'arguments pour un web service.</a><br>
|
||||
<a href="api_hub_temp.html?field1=11&field2=12&field3=13">API HUB Temp, test d'un web service hub de mesures de température.</a><br>
|
||||
<a href="disp_temp.html">Affichage des températures, affiche les températures mesurées.</a><br>
|
||||
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||
</h3>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
48
Mesures/energy/transfo_courant_clip_1p/upload_s.sh
Normal file
48
Mesures/energy/transfo_courant_clip_1p/upload_s.sh
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
# Petit script pour télécharger facilement tout le binz via le port série
|
||||
#zf191228.2313
|
||||
|
||||
# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !
|
||||
# Il est préférable de télécharger en premier les *gros* fichiers .lua !
|
||||
|
||||
# ATTENTION: cela efface tout le NodeMCU !
|
||||
|
||||
luatool_tty="/dev/cu.wchusbserial1410"
|
||||
|
||||
echo ""
|
||||
read -p "ATTENTION, cela va effacer tout le NodeMCU !"
|
||||
read -p "Etes-vous vraiment certain ?"
|
||||
|
||||
chmod +x luatool.py
|
||||
|
||||
./luatool.py --port $luatool_tty -w
|
||||
./luatool.py --port $luatool_tty -l
|
||||
read -p "Est-ce bien vide ?"
|
||||
|
||||
./luatool.py --port $luatool_tty --bar -f z_index.html
|
||||
./luatool.py --port $luatool_tty --bar -f wifi_init.lua
|
||||
./luatool.py --port $luatool_tty --bar -f wifi_info.lua
|
||||
./luatool.py --port $luatool_tty --bar -f wifi_clear.html
|
||||
./luatool.py --port $luatool_tty --bar -f web_srv2.lua
|
||||
./luatool.py --port $luatool_tty --bar -f web_ide2.lua
|
||||
./luatool.py --port $luatool_tty --bar -f telnet_srv2.lua
|
||||
./luatool.py --port $luatool_tty --bar -f set_time.lua
|
||||
./luatool.py --port $luatool_tty --bar -f secrets_wifi.lua
|
||||
./luatool.py --port $luatool_tty --bar -f secrets_project.lua
|
||||
./luatool.py --port $luatool_tty --bar -f head.lua
|
||||
./luatool.py --port $luatool_tty --bar -f eus_params.lua
|
||||
./luatool.py --port $luatool_tty --bar -f disp_temp.html
|
||||
./luatool.py --port $luatool_tty --bar -f dir2.lua
|
||||
./luatool.py --port $luatool_tty --bar -f cat.lua
|
||||
./luatool.py --port $luatool_tty --bar -f boot2.lua
|
||||
./luatool.py --port $luatool_tty --bar -f boot.lua
|
||||
./luatool.py --port $luatool_tty --bar -f 0_send_data.lua
|
||||
#./luatool.py --port $luatool_tty --bar -f 0_htu21d.lua
|
||||
./luatool.py --port $luatool_tty --bar -f 0_cron.lua
|
||||
|
||||
./luatool.py --port $luatool_tty -l
|
||||
read -p "Pas eu d'erreur, on part à fond avec le init.lua ?"
|
||||
|
||||
./luatool.py --port $luatool_tty --bar -f initz.lua -t init.lua
|
||||
./luatool.py --port $luatool_tty -l
|
||||
echo -e "\nC'est tout bon ;-)"
|
||||
@@ -1,33 +1,45 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf190727.1220 \n")
|
||||
print("\n wifi_info.lua zf200106.1803 \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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP")
|
||||
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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
print("AP MAC: ", wifi.ap.getmac())
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
function wifi_info()
|
||||
local zmodewifi=wifi.getmode()
|
||||
|
||||
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
|
||||
|
||||
if zmodewifi == wifi.NULLMODE then
|
||||
print("WIFI OFF")
|
||||
elseif zmodewifi == wifi.STATION then
|
||||
print("WIFI mode CLI")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP\n")
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
print("Current AP config:")
|
||||
local ap_config=wifi.ap.getconfig(true)
|
||||
print("\tssid:", ap_config.ssid)
|
||||
print("\tpassword:", ap_config.pwd)
|
||||
print("\tbssid:", wifi.ap.getmac())
|
||||
elseif zmodewifi == wifi.STATIONAP then
|
||||
print("WIFI mode CLI+AP\n")
|
||||
print("CLIENT IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current CLIENT config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid.."\n")
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
print("Current AP config:")
|
||||
local ap_config=wifi.ap.getconfig(true)
|
||||
print("\tssid:", ap_config.ssid)
|
||||
print("\tpassword:", ap_config.pwd)
|
||||
print("\tbssid:", wifi.ap.getmac())
|
||||
end
|
||||
wifi_info=nil
|
||||
end
|
||||
wifi_info()
|
||||
|
||||
|
||||
87
Mesures/energy/transfo_courant_clip_1p/wifi_init.lua
Normal file
87
Mesures/energy/transfo_courant_clip_1p/wifi_init.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf200530.1142 \n")
|
||||
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
function wifi_init_end()
|
||||
tmr_wifi_init1:unregister() i=nil
|
||||
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
|
||||
f=nil secrets_wifi=nil cli_pwd=nil cli_ssid=nil
|
||||
tmr_wifi_init1=nil wifi_init=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
-- f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
|
||||
-- f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
zdelay=1 if reset_reason=="seconde_chance" then zdelay=20 end
|
||||
tmr_wifi_init3=tmr.create()
|
||||
tmr_wifi_init3:alarm(zdelay*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
tmr_wifi_init3:unregister() tmr_wifi_init3=nil wifi_init_end=nil
|
||||
reset_reason=nil zdelay=nil
|
||||
end)
|
||||
end
|
||||
|
||||
if file.exists("_setup_wifi_") then
|
||||
print("setup wifi...")
|
||||
file.remove("_setup_wifi_")
|
||||
wifi.sta.config{ssid="", pwd=""} wifi.sta.connect()
|
||||
if zLED == nil then zLED = 4 end
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
|
||||
tmr_wifi_init4=tmr.create()
|
||||
tmr_wifi_init4:alarm(0.1*1000, tmr.ALARM_AUTO , function()
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
end)
|
||||
tmr.create():alarm(90*1000, tmr.ALARM_SINGLE, function()
|
||||
node.restart()
|
||||
end)
|
||||
enduser_setup.start(function()
|
||||
print("on est sortit du setup wifi et on restart !")
|
||||
node.restart()
|
||||
end)
|
||||
print("setup gadget lancé...")
|
||||
else
|
||||
wifi.setmode(wifi.STATIONAP,true)
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd} wifi.sta.connect()
|
||||
if node_id == nil then node_id = "generic" ap_pwd = "12345678" end
|
||||
wifi.ap.config({ ssid = ap_ssid.."_"..node_id, pwd = ap_pwd, save=true })
|
||||
ap_ssid=nil ap_pwd=nil
|
||||
tmr_wifi_init2=tmr.create()
|
||||
tmr_wifi_init2:alarm(60*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de AP WIFI !")
|
||||
wifi.setmode(wifi.STATION,true) tmr_wifi_init2=nil
|
||||
print(node.heap()) collectgarbage() print(node.heap())
|
||||
end)
|
||||
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT) i=1
|
||||
tmr_wifi_init1=tmr.create()
|
||||
tmr_wifi_init1:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
if wifi.sta.getip() == nil then
|
||||
print(i,"Connecting to AP...")
|
||||
i=i+1
|
||||
if i > 30 then
|
||||
print("pas de wifi :-(")
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
print("on restart pour le setup wifi")
|
||||
node.restart()
|
||||
--tmr_wifi_init2:unregister() tmr_wifi_init2=nil
|
||||
--wifi.setmode(wifi.SOFTAP,true)
|
||||
--wifi_init_end()
|
||||
end
|
||||
else
|
||||
wifi_init_end()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
wifi_init()
|
||||
|
||||
--[[
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
file.remove("eus_params.lua")
|
||||
]]
|
||||
@@ -1,23 +1,103 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- ATTENTION, la longueur des lignes DOIT être <128 ! -->
|
||||
|
||||
<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>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<%
|
||||
zout("<title>"..node_id.."</title>")
|
||||
%>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 home page 190727.0941</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="z_page4.html?field1=11&field2=12&field3=13">Page 4, test de récupération d'arguments pour un web service.</a><br>
|
||||
<a href="api_hub_temp.html?field1=11&field2=12&field3=13">API HUB Temp, test d'un web service hub de mesures de température.</a><br>
|
||||
<a href="disp_temp.html">Affichage des températures, affiche les températures mesurées.</a><br>
|
||||
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||
</h3>
|
||||
</body>
|
||||
<%
|
||||
zout("<h1>"..node_id.." 200118.1804 </h1>")
|
||||
%>
|
||||
<a href="/">Home...</a><br>
|
||||
<h2>Menu:</h2>
|
||||
<h3>
|
||||
|
||||
LED
|
||||
<a href="api_sonoff.html?LED=on"> On</a>
|
||||
<a href="api_sonoff.html?LED=off"> Off</a><br>
|
||||
|
||||
<a href="disp_temp.html">Affichage de la température et humidité</a><br>
|
||||
<br>
|
||||
<a href="z_index.html?SetupWIFI=true">Wifi setup</a><br>
|
||||
</h3>
|
||||
|
||||
<%
|
||||
if _GET.SetupWIFI == "true" then
|
||||
print("On demande le setup wifi depuis le browser !")
|
||||
wifi_setup_ok=(math.floor(100*node.random()))
|
||||
zout("<br><br>Etes-vous vraiment certain ?<br>Si oui, faites: ")
|
||||
zout('<a href="/?SetupWIFI='..wifi_setup_ok..'"> Ok</a><br><br>')
|
||||
end
|
||||
%>
|
||||
|
||||
<%
|
||||
if (wifi_setup_ok ~= nil) and (_GET.SetupWIFI == tostring(wifi_setup_ok)) then
|
||||
print("On confirme le setup wifi depuis le browser !")
|
||||
zout("<br><br>Choisir comme WIFI AP: setup_gadget puis aller sur: http://192.168.4.1<br><br>")
|
||||
file.putcontents("_setup_wifi_", "toto")
|
||||
tmr.create():alarm(5*1000, tmr.ALARM_SINGLE, function()
|
||||
print("on restart pour le setup wifi")
|
||||
wifi.sta.config{ssid="", pwd="", auto=true, save=true}
|
||||
wifi.sta.autoconnect(1) wifi.sta.connect()
|
||||
node.restart()
|
||||
end)
|
||||
end
|
||||
%>
|
||||
|
||||
<%
|
||||
if _GET.RESTART == "true" then
|
||||
print("oups restart...")
|
||||
zout("<br><br>oups restart...<br><br>")
|
||||
tmr.create():alarm(5*1000, tmr.ALARM_SINGLE, function()
|
||||
print("on restart...")
|
||||
node.restart()
|
||||
end)
|
||||
end
|
||||
%>
|
||||
|
||||
<%
|
||||
zout("Etat de la LED:<nsp>")
|
||||
if gpio.read(zLED) == 1 then zout("OFF") else zout("ON") end
|
||||
zout("<br>")
|
||||
%>
|
||||
|
||||
<%
|
||||
if zRELAY ~= nil then
|
||||
zout("Etat du RELAY:<nsp>")
|
||||
if gpio.read(zRELAY) == 0 then zout("OFF") else zout("ON") end
|
||||
zout("<br>")
|
||||
end
|
||||
%>
|
||||
|
||||
<%
|
||||
a,b,c = wifi.sta.getip()
|
||||
if a ~= nil then
|
||||
zout("<br>IP: "..a.."<br>\n".."MASK: "..b.."<br>\n".."GATEWAY: "..c.."<br>\n")
|
||||
a=nil b=nil c=nil
|
||||
end
|
||||
collectgarbage() zout("RAM: "..node.heap().."<br>")
|
||||
%>
|
||||
|
||||
<%
|
||||
zout("<br>Etat des GLOBALS !<br>\n")
|
||||
zout("<table>\n")
|
||||
for k,v in pairs(_G) do
|
||||
if k ~= "lua_code" then
|
||||
v = tostring(v)
|
||||
zout("<tr>")
|
||||
zout("<td>"..k.."</td>") zout("<td>"..v.."</td>")
|
||||
zout("</tr>\n")
|
||||
end
|
||||
end
|
||||
zout("</table>")
|
||||
%>
|
||||
|
||||
<br><br><a href="/?RESTART=true"> Restart !</a><br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user