Commencé le projet pet_tracker_2, une nouvelle évolution avec mes nouveaux outils de l'ancien pet-tracker
This commit is contained in:
49
DeepSleep/Pet_tracker_2/0_cron.lua
Normal file
49
DeepSleep/Pet_tracker_2/0_cron.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
-- Petit script pour faire office de crontab pour les mesures
|
||||
print("\n 0_cron.lua zf200705.2247 \n")
|
||||
|
||||
cron1=tmr.create()
|
||||
cron1:alarm(15*1000, tmr.ALARM_AUTO, function()
|
||||
-- if verbose then print("cron1........................") end
|
||||
-- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
|
||||
|
||||
-- rt_launch()
|
||||
|
||||
|
||||
-- http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1")
|
||||
|
||||
-- http_post(influxdb_url,"energy,memory=cron1_"..yellow_id.." ram="..node.heap())
|
||||
|
||||
-- if yellow_id == 60 then http_post(influxdb_url,"energy,compteur=3 puissance="..zpower/1000) end
|
||||
-- if yellow_id == 64 then http_post(influxdb_url,"energy,compteur=4 puissance="..zpower/1000) end
|
||||
|
||||
|
||||
if yellow_id == 69 then
|
||||
local zmes="bolo_ruru,capteur="..node_id.." level="..zlevel
|
||||
zmes=zmes.."\n".."bolo_ruru,capteur="..node_id.." hauteur="..zlength
|
||||
http_post(influxdb_url,zmes)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- http_post(influxdb_url,"energy,value=test2_"..yellow_id.." val=2")
|
||||
-- http_post(influxdb_url,"energy,value=test3_"..yellow_id.." val=3")
|
||||
-- http_post(influxdb_url,"energy,value=test4_"..yellow_id.." val=4")
|
||||
|
||||
|
||||
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
-- f=nil
|
||||
|
||||
-- if verbose then print("End cron:") end
|
||||
collectgarbage()
|
||||
-- if verbose then print(node.heap()) end
|
||||
end)
|
||||
|
||||
|
||||
--[[
|
||||
cron1:stop()
|
||||
cron1:start()
|
||||
]]
|
||||
45
DeepSleep/Pet_tracker_2/0_http_post.lua
Normal file
45
DeepSleep/Pet_tracker_2/0_http_post.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
-- 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 zf200625.1137 \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 local zurl=t_zurl[1] local zarg=t_zarg[1]
|
||||
-- zarg=zarg.."\n".."energy,value=nb_waiting_"..yellow_id.." val="..#t_zurl
|
||||
-- zarg=zarg.."\n".."energy,memory=zpost_"..yellow_id.." ram="..node.heap()
|
||||
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)
|
||||
if debug_rec~=nil then debug_rec("HTTP request failed: ", code, data) end
|
||||
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:") end
|
||||
collectgarbage()
|
||||
-- if verbose then print(node.heap()) end
|
||||
end)
|
||||
end
|
||||
|
||||
function http_post(zurl,zarg)
|
||||
if #t_zurl <=10 then table.insert(t_zurl, zurl) table.insert(t_zarg, zarg) end
|
||||
-- if verbose then print("Nb wait: "..#t_zurl) print(node.heap()) end
|
||||
-- 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:") end
|
||||
collectgarbage()
|
||||
-- if verbose then print(node.heap()) end
|
||||
end
|
||||
148
DeepSleep/Pet_tracker_2/0_rtelnet1.lua
Normal file
148
DeepSleep/Pet_tracker_2/0_rtelnet1.lua
Normal file
@@ -0,0 +1,148 @@
|
||||
-- script telnet pour le socat
|
||||
|
||||
function telnet_listener(socket)
|
||||
print("\n 0_rtelnet1.lua zf200621.2309 \n")
|
||||
|
||||
-- node, table, tmr, uwrite, tostring =
|
||||
-- node, table, tmr, uart.write, tostring
|
||||
|
||||
print("................telnet_listener")
|
||||
-- insert, remove, concat, heap, gc =
|
||||
-- table.insert, table.remove, table.concat, node.heap, collectgarbage
|
||||
fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0
|
||||
-- local s -- s is a copy of the TCP socket if and only if sending is in progress
|
||||
|
||||
function flushGarbage()
|
||||
if node.heap() < 13440 then collectgarbage() end
|
||||
end
|
||||
|
||||
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
|
||||
table.insert(fifo2,table.concat(fifo1))
|
||||
fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0
|
||||
end
|
||||
rec = table.remove(fifo2,1)..(table.remove(fifo2,1) or '') ..(table.remove(fifo2,1) or '') .. (table.remove(fifo2,1) or '')
|
||||
fifo2l = fifo2l - #rec
|
||||
flushGarbage()
|
||||
if srv_rt:getpeer()~=nil then
|
||||
s:send(rec)
|
||||
end
|
||||
end
|
||||
|
||||
local F1_SIZE = 256
|
||||
|
||||
function queueLine(str)
|
||||
while #str > 0 do -- this is because str might be longer than the packet size!
|
||||
k, l = F1_SIZE - fifo1l, #str
|
||||
if #fifo1 >= 32 or (k < l and k < 16) then
|
||||
table.insert(fifo2, table.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
|
||||
table.insert(fifo1, chunk)
|
||||
fifo1l = fifo1l + #chunk
|
||||
end
|
||||
if not s and socket then
|
||||
s = socket
|
||||
sendLine()
|
||||
else
|
||||
flushGarbage()
|
||||
end
|
||||
end
|
||||
|
||||
function receiveLine(s, line)
|
||||
node.input(line)
|
||||
end
|
||||
|
||||
function disconnect(_,zerr)
|
||||
node.output(nil)
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
print("................disconnect")
|
||||
|
||||
if socket~=nil then
|
||||
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
|
||||
print("................disconnect 2e", socket, socket:getpeer())
|
||||
socket:on("connection", nil)
|
||||
socket:on("reconnection", nil)
|
||||
socket:on("disconnection", nil)
|
||||
socket:on("receive", nil)
|
||||
socket:on("sent", nil)
|
||||
|
||||
socket=nil
|
||||
end
|
||||
|
||||
-- fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, nil, nil
|
||||
print("disconnected... "..zerr..", "..node.heap())
|
||||
-- if debug_rec~=nil then debug_rec("disconnect, disconnected, "..zerr..", "..node.heap()) end
|
||||
|
||||
|
||||
-- node, table, tmr, uwrite, tostring = nil, nil, nil, nil, nil
|
||||
-- insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
|
||||
-- fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
|
||||
-- rec = nil
|
||||
-- s = nil
|
||||
-- socket = nil
|
||||
-- flushGarbage = nil
|
||||
-- sendLine = nil
|
||||
-- queueLine = nil
|
||||
-- receiveLine = nil
|
||||
-- zconnection = nil
|
||||
-- disconnect = nil
|
||||
-- -- telnet_listener=nil
|
||||
|
||||
|
||||
|
||||
fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
|
||||
rec = nil
|
||||
k = nil
|
||||
l = nil
|
||||
s = nil
|
||||
chunk = nil
|
||||
socket = nil
|
||||
flushGarbage = nil
|
||||
sendLine = nil
|
||||
queueLine = nil
|
||||
receiveLine = nil
|
||||
zconnection = nil
|
||||
disconnect = nil
|
||||
telnet_listener=nil
|
||||
srv_rt=nil
|
||||
|
||||
|
||||
-- collectgarbage()
|
||||
rt_connect()
|
||||
end
|
||||
|
||||
--zzz
|
||||
function zconnection(s)
|
||||
print("socket: ",socket)
|
||||
if socket~=nil then
|
||||
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
|
||||
print(socket:getpeer())
|
||||
end
|
||||
|
||||
local zstr="zconnection, Oups, on ne devrait jamais passer par là to NodeMCU world."
|
||||
print(zstr) if debug_rec~=nil then debug_rec(zstr) end
|
||||
socket=nil
|
||||
end
|
||||
|
||||
socket:on("connection", zconnection)
|
||||
socket:on("receive", receiveLine)
|
||||
socket:on("disconnection", disconnect)
|
||||
socket:on("sent", sendLine)
|
||||
|
||||
node.output(queueLine, 0)
|
||||
-- print(queueLine, 0)
|
||||
end
|
||||
|
||||
115
DeepSleep/Pet_tracker_2/0_tst5_socat.lua
Normal file
115
DeepSleep/Pet_tracker_2/0_tst5_socat.lua
Normal file
@@ -0,0 +1,115 @@
|
||||
--[[
|
||||
tests connection reverse telnet commande à faire tourner sur le GATEWAY !
|
||||
|
||||
1ere console
|
||||
pour une liaison directe:
|
||||
socat TCP-LISTEN:23064,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_tst5_socat.lua zf200628.1458 \n")
|
||||
|
||||
function rt_connect()
|
||||
-- print("................rt_connect")
|
||||
collectgarbage()
|
||||
local zlaps=tmr.now()/1000000-ztime_connect
|
||||
-- print("time of retry connect... "..zlaps)
|
||||
-- if debug_rec~=nil then debug_rec("time of retry connect... "..zlaps..", "..node.heap()) end
|
||||
if zlaps>1 then
|
||||
local zstr="trying connect to "..console_host..":"..console_port..", "..node.heap()
|
||||
-- if debug_rec~=nil then debug_rec(zstr) end
|
||||
if verbose==verbose then
|
||||
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
|
||||
-- print(zstr)
|
||||
end
|
||||
if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_try_con_"..yellow_id.." ram="..node.heap()) end
|
||||
ztime_connect=tmr.now()/1000000
|
||||
|
||||
srv_rt=nil
|
||||
srv_rt = net.createConnection(net.TCP, 0)
|
||||
|
||||
srv_rt:on("connection", function(sck)
|
||||
print("................connection")
|
||||
if debug_rec~=nil then debug_rec("rt_connect, srv_rt:on, connected on, "..node.heap()) end
|
||||
collectgarbage()
|
||||
-- if verbose then
|
||||
gpio.write(zLED, gpio.LOW)
|
||||
print("connected on "..console_host..":"..console_port..", "..node.heap())
|
||||
print(node.heap())
|
||||
-- end
|
||||
if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_connected_"..yellow_id.." ram="..node.heap()) end
|
||||
dofile("0_rtelnet1.lua")
|
||||
telnet_listener(sck)
|
||||
print("Welcome to NodeMCU world.")
|
||||
end)
|
||||
|
||||
srv_rt:on("reconnection", function(sck)
|
||||
-- print(";;;;;;;;;;;;;;;;reconnection")
|
||||
srv_rt:on("connection", nil)
|
||||
srv_rt:on("reconnection", nil)
|
||||
end)
|
||||
|
||||
-- srv_rt:on("disconnection", function(sck)
|
||||
-- print(";;;;;;;;;;;;;;;;disconnection")
|
||||
-- end)
|
||||
--
|
||||
-- srv_rt:on("receive", function(sck)
|
||||
-- print(";;;;;;;;;;;;;;;;receive")
|
||||
-- end)
|
||||
--
|
||||
-- srv_rt:on("sent", function(sck)
|
||||
-- print(";;;;;;;;;;;;;;;;sent")
|
||||
-- end)
|
||||
|
||||
|
||||
srv_rt:connect(console_port,console_host)
|
||||
else
|
||||
print("on ne se reconnecte pas vite 1x...")
|
||||
end
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function rt_launch()
|
||||
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=tmr_socat1_"..yellow_id.." ram="..node.heap()) end
|
||||
if srv_rt~=nil then
|
||||
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
|
||||
if console_port ~= srv_rt:getpeer() then
|
||||
rt_connect()
|
||||
end
|
||||
else
|
||||
rt_connect()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
tmr_socat1=tmr.create()
|
||||
tmr_socat1:alarm(20*1000, tmr.ALARM_AUTO , rt_launch)
|
||||
|
||||
|
||||
ztime_connect=tmr.now()/1000000-10
|
||||
|
||||
rt_launch()
|
||||
|
||||
print("Revers telnet server running...\n")
|
||||
163
DeepSleep/Pet_tracker_2/README.md
Normal file
163
DeepSleep/Pet_tracker_2/README.md
Normal file
@@ -0,0 +1,163 @@
|
||||
# Mesure de hauteur d'eau dans un réservoir
|
||||
|
||||
zf200627.1330
|
||||
|
||||
|
||||
<!-- TOC titleSize:2 tabSpaces:2 depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 skip:1 title:1 charForUnorderedList:* -->
|
||||
## Table of Contents
|
||||
* [Buts](#buts)
|
||||
* [Astuces de mesures de la distance au moyen du senseur ultrason](#astuces-de-mesures-de-la-distance-au-moyen-du-senseur-ultrason)
|
||||
* [Schéma](#schéma)
|
||||
* [Astuces](#astuces)
|
||||
* [Installation](#installation)
|
||||
* [Utilisation](#utilisation)
|
||||
* [Upload Lua code](#upload-lua-code)
|
||||
* [Secrets pour le projet](#secrets-pour-le-projet)
|
||||
* [Rename initz.lua pour le boot automatique](#rename-initzlua-pour-le-boot-automatique)
|
||||
* [Utilisation de la console du NodeMCU en remote](#utilisation-de-la-console-du-nodemcu-en-remote)
|
||||
* [Visualisation sur Grafana/InfluxDB](#visualisation-sur-grafanainfluxdb)
|
||||
<!-- /TOC -->
|
||||
|
||||
## Buts
|
||||
|
||||
Petit projet pour mesurer la hauteur d'eau dans un réservoir de 100l au moyen d'un senseur à ultrason utilisé pour de la robotique récréative.
|
||||
|
||||
Le but est de mesurer la distance entre le haut du bidon et la surface de l'eau dans le bidon et ainsi pouvoir en déduire le pourcentage de remplissage du bidon.
|
||||
|
||||

|
||||
Senseur à ultrason, très bon marché, permettant de mesurer la distance
|
||||
|
||||
|
||||

|
||||
NodeMCU autonome, alimenté ici par une batterie, faisant la lecture de la hauteur d'eau et envoyant le résultat dans une DB InfluxDB via le WIFI
|
||||
|
||||
|
||||

|
||||
Banc test dans le jardin pour vérifier le bon fonctionnement du système
|
||||
|
||||

|
||||
Graphique obtenu lors du banc test avec de l'eau dans le jardin
|
||||
|
||||
|
||||
<br><br>
|
||||
On peut voir ici, avec ce projet assez complet, toutes les possibilités offertes de la programmation des NodeMCU en LUA, en mode événementiel. <br>
|
||||
Choses qui ne seraient pas possible si on l'avait fait en C++ (mode Arduino), comme par exemple:
|
||||
|
||||
* crontab, horloge pour les mesures
|
||||
* envoi des données sur la DB InfluxDB
|
||||
* serveur reverse TELNET, traversant tous les routers sans devoir en modifier la configuration, permettant d'accéder à la console série (USB) du NodeMCU
|
||||
|
||||
Toutes les fonctions sont bien séparées dans des scripts, cela *complexifie* le projet mais ce qui facilite la portabilité entre les projets et aussi sa mise au point.
|
||||
|
||||
|
||||
|
||||
## Astuces de mesures de la distance au moyen du senseur ultrason
|
||||
|
||||
Dans ce projet il y a 1x NodeMCU qui mesure la hauteur d'eau dans le bidon au moyen d'un senseur à ultrason utilisé pour de la robotique récréative très bon marché, 0.70FS
|
||||
|
||||
https://www.aliexpress.com/item/32477198302.html
|
||||
|
||||
https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
|
||||
|
||||
Il n'y a pas de *module* NodeMCU pour ce senseur, mais son utilisation en Lua est vraiment très simple, il suffit juste d'envoyer une *pulse* de 10uS sur la pin *trig* et de *connecter* une interruption du NodeMCU sur la pin *echo*. <br>
|
||||
Après une simple règle de trois en relation avec la vitesse du son dans l'air et on a la distance en cm.
|
||||
|
||||
|
||||
### Schéma
|
||||
|
||||

|
||||
|
||||
Le schéma est vraiment très simple !
|
||||
|
||||
|
||||
### Astuces
|
||||
|
||||
* La seul problématique dans ce projet c'est que le senseur DOIT absolument être alimenté en 5V et que le NodeMCU lui est en 3.3V. <br>
|
||||
Il faut donc lui ajouter une petite résistance, R1, d'adaptation du niveau pour le signal pour l'interruption du NodeMCU.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Il faut *flasher* le NodeMCU avec ce firmware:
|
||||
|
||||
https://github.com/zuzu59/NodeMCU_Lua/blob/master/Firmware/nodemcu-master-19-modules-2019-12-31-16-40-12-float.bin
|
||||
|
||||
|
||||
Avec ces modules:
|
||||
|
||||
https://github.com/zuzu59/NodeMCU_Lua/blob/master/Firmware/nodemcu-master-19-modules-2019-12-31-16-40-12-float.pdf
|
||||
|
||||
|
||||
## Utilisation
|
||||
|
||||
### Upload Lua code
|
||||
Après avoir *flashé* le NodeMCU avec le bon *firmware* il faut télécharger tous les fichiers \*.lua sur le NodeMCU.
|
||||
|
||||
|
||||
### Secrets pour le projet
|
||||
Mais il faut aussi bien *remplir* et charger sur le NodeMCU, le fichier des secrets du projet:
|
||||
```
|
||||
secrets_project.lua
|
||||
```
|
||||
|
||||
ainsi que le fichier des secrets pour le WIFI
|
||||
```
|
||||
secrets_wifi.lua
|
||||
```
|
||||
Tout en sachant que les variables utilisées pour les secrets sont utiles pour:
|
||||
|
||||
* **znode_chipid == nnn then**<br>
|
||||
C'est l'id du NodeMCU que chaque NodeMCU ont gravé dans leur mémoire, on peut le lire avec cette commande:
|
||||
```
|
||||
=node.chipid()
|
||||
```
|
||||
|
||||
* **node_id = "ttt"**<br>
|
||||
C'est le nom de *fonction* du NodeMCU qui sera *visible* dans la DB InfluxDB
|
||||
|
||||
* **yellow_id = nn**<br>
|
||||
C'est le *numéro* du NodeMCU que l'on indique sur une *petite étiquette jaune collée* sur le NodeMCU. Ce *numéro* permet par la suite de connaitre très facilement le numéro du *port* utilisé pour le *reverse telnet* quand on veut accéder à la console série du NodeMCU
|
||||
|
||||
* **-- thingspeak_url="http://api.thingspeak.com/update?api_key=kkk"**<br>
|
||||
Pas utilisé dans ce projet
|
||||
|
||||
* **influxdb_url="http://uuu:8086/write?db=ddd&u=admin&p=ppp"**<br>
|
||||
Secrets utilisés pour envoyer des données sur le DB InfluxDB
|
||||
|
||||
* **console_host = "uuu" console_port = 23000+yellow_id**<br>
|
||||
Serveur utilisé pour le *tremplin* du reverse telnet utilisé pour accéder à la console série du NodeMCU au moyen d'un *socat*. L'information d'utilisation se trouve dans le fichier 0_tst5_socat.lua
|
||||
|
||||
* **-- zdyndns_host = "hhh" zdyndns_port = nnn**<br>
|
||||
Pas utilisé dans ce projet
|
||||
|
||||
|
||||
### Rename initz.lua pour le boot automatique
|
||||
Ne pas oublier après avoir vérifié que tout fonctionne bien de *renommer* le fichier **initz.lua** en **init.lua** afin que quand le NodeMCU puisse démarrer automatiquement le code et bien fonctionner de manière autonome.
|
||||
|
||||
|
||||
### Utilisation de la console du NodeMCU en remote
|
||||
|
||||
Très pratique pour le debug, on peut directement modifier le code source Lua du NodeMCU en remote via un *reverse telnet*. Plus d'info dans le fichier 0_tst5_socat.lua.
|
||||
On peut aussi modifier le code Lua du NodeMCU en remote avec l'utilitaire *luatools.py*
|
||||
|
||||
|
||||
### Visualisation sur Grafana/InfluxDB
|
||||

|
||||
Graphique obtenu lors du banc test avec de l'eau dans le jardin
|
||||
|
||||
La totale en détail
|
||||
|
||||
https://github.com/zuzu59/docker-influxdb-grafana
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pense bête:
|
||||
|
||||
```
|
||||
file.open("hello.lua","w+")
|
||||
file.writeline([[print("hello nodemcu")]])
|
||||
file.writeline([[print(node.heap())]])
|
||||
file.close()
|
||||
```
|
||||
35
DeepSleep/Pet_tracker_2/_secrets_project.lua_
Normal file
35
DeepSleep/Pet_tracker_2/_secrets_project.lua_
Normal file
@@ -0,0 +1,35 @@
|
||||
-- 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
|
||||
|
||||
function secrets_project()
|
||||
print("\n secrets_project.lua zf200625.1146 \n")
|
||||
|
||||
zLED=4 zBTN=3 node_id = "generic"
|
||||
znode_chipid=node.chipid() print("znode_chipid:",znode_chipid)
|
||||
|
||||
if znode_chipid == iii then node_id = "sonoff_1" zLED=7 end
|
||||
|
||||
if znode_chipid == iii then node_id = "sonoff_2" zLED=7 end
|
||||
|
||||
if znode_chipid == iii then
|
||||
node_id = "level1"
|
||||
yellow_id = nn
|
||||
-- thingspeak_url="http://api.thingspeak.com/update?api_key=kkk"
|
||||
influxdb_url="http://uuu:8086/write?db=ddd&u=admin&p=ppp"
|
||||
print("influxdb_url: "..influxdb_url)
|
||||
console_host = "uuu" console_port = 23000+yellow_id
|
||||
-- zdyndns_host = "hhh" zdyndns_port = nnn
|
||||
end
|
||||
|
||||
znode_chipid=nil
|
||||
print("node_id: "..node_id..", console_port: "..console_port)
|
||||
end
|
||||
secrets_project()
|
||||
secrets_project=nil
|
||||
|
||||
--[[
|
||||
=node.chipid()
|
||||
]]
|
||||
18
DeepSleep/Pet_tracker_2/_secrets_wifi.lua_
Normal file
18
DeepSleep/Pet_tracker_2/_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="sss" ap_pwd="ppp"
|
||||
end
|
||||
|
||||
secrets_wifi()
|
||||
79
DeepSleep/Pet_tracker_2/_zlocal_cmd.txt
Normal file
79
DeepSleep/Pet_tracker_2/_zlocal_cmd.txt
Normal file
@@ -0,0 +1,79 @@
|
||||
zf200621.2337
|
||||
|
||||
srv_rt:on("connection", nil)
|
||||
|
||||
|
||||
|
||||
|
||||
=node.heap()
|
||||
rt_connect()
|
||||
|
||||
fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
|
||||
rec = nil
|
||||
k = nil
|
||||
l = nil
|
||||
s = nil
|
||||
chunk = nil
|
||||
socket = nil
|
||||
flushGarbage = nil
|
||||
sendLine = nil
|
||||
queueLine = nil
|
||||
receiveLine = nil
|
||||
zconnection = nil
|
||||
disconnect = nil
|
||||
telnet_listener=nil
|
||||
srv_rt=nil
|
||||
=node.heap()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
=node.heap()
|
||||
dofile("0_rtelnet1.lua")
|
||||
=node.heap()
|
||||
telnet_listener=nil
|
||||
=node.heap()
|
||||
srv_rt=nil
|
||||
=node.heap()
|
||||
|
||||
|
||||
|
||||
for k,v in ipairs(debug.getregistry()) do print(k,v) end
|
||||
|
||||
|
||||
|
||||
node.stripdebug(3)
|
||||
node.compile('0_tst4_socat.lua')
|
||||
|
||||
print(srv_rt)
|
||||
print(srv_rt:getpeer())
|
||||
srv_rt:close()
|
||||
|
||||
print(socket)
|
||||
print(socket:getpeer())
|
||||
socket:close()
|
||||
|
||||
verbose=true
|
||||
node.output(nil)
|
||||
|
||||
http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1") print("toto",node.heap(),#t_zurl)
|
||||
|
||||
|
||||
=srv_rt:getaddr()
|
||||
tmr_socat1:unregister()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
total_allocated, estimated_used = node.egc.meminfo()
|
||||
print(total_allocated, estimated_used)
|
||||
|
||||
print(console_port)
|
||||
|
||||
srv_rt = nil collectgarbage()
|
||||
|
||||
|
||||
301
DeepSleep/Pet_tracker_2/_zremote_cmd.txt
Normal file
301
DeepSleep/Pet_tracker_2/_zremote_cmd.txt
Normal file
@@ -0,0 +1,301 @@
|
||||
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
|
||||
# zf200704.2310
|
||||
|
||||
|
||||
Todo à faire pour ce projet !
|
||||
|
||||
???
|
||||
|
||||
# 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.182"
|
||||
#export zport="23"
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="23000"
|
||||
|
||||
|
||||
# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP)
|
||||
telnet -rN $zIP $zport
|
||||
~.
|
||||
--node.restart()
|
||||
collectgarbage()
|
||||
=node.heap()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
|
||||
################################
|
||||
# commandes lua pour ce projet #
|
||||
################################
|
||||
# pour les tests en direct sur la gateway
|
||||
ssh ubuntu@www.zuzu-test.ml
|
||||
socat TCP-LISTEN:23069,fork,reuseaddr STDIO
|
||||
################################
|
||||
# pour les tests en remote
|
||||
killall -9 ssh
|
||||
ssh ubuntu@www.zuzu-test.ml killall -9 socat
|
||||
|
||||
ssh ubuntu@www.zuzu-test.ml socat TCP-LISTEN:23069,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1 &
|
||||
# SHIFT+CMD+K SHIFT+CMD+K ALT+CMD+F
|
||||
|
||||
watch -n 1 'ssh ubuntu@www.zuzu-test.ml netstat -nat |grep 230'
|
||||
|
||||
# ALT+CMD+F CTRL+C ALT+CMD+F
|
||||
|
||||
export zIP="localhost"
|
||||
export zport="23000"
|
||||
|
||||
ssh -N -L 23000:localhost:23000 ubuntu@www.zuzu-test.ml &
|
||||
|
||||
telnet -rN $zIP $zport
|
||||
|
||||
verbose=false
|
||||
~.
|
||||
|
||||
=node.heap()
|
||||
verbose=true
|
||||
node.restart()
|
||||
|
||||
dofile("head.lua")
|
||||
zhead("0_ultra_son.lua")
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f boot.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_get_power.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_tst5_socat.lua
|
||||
./luatool.py --ip $zIP:$zport -f 0_ultra_son.lua
|
||||
|
||||
./luatool.py --ip $zIP:$zport --zrestart
|
||||
|
||||
|
||||
= node.bootreason()
|
||||
# https://nodemcu.readthedocs.io/en/master/modules/node/#nodebootreason
|
||||
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
verbose=true
|
||||
#zdyn
|
||||
|
||||
|
||||
|
||||
|
||||
./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()
|
||||
|
||||
|
||||
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:$zport -f head.lua
|
||||
telnet -rN $zIP $zport
|
||||
dofile("head.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
|
||||
|
||||
|
||||
# faire un cat d'un fichier sur le NodeMCU
|
||||
dofile("cat.lua")
|
||||
cat("boot2.lua")
|
||||
|
||||
|
||||
# commandes luatool
|
||||
./luatool.py -h
|
||||
./luatool.py --ip $zIP:$zport -i
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
./luatool.py --ip $zIP:$zport -f toto.lua -d
|
||||
./luatool.py --ip $zIP:$zport --delete toto.lua
|
||||
|
||||
|
||||
|
||||
****************************************************************************
|
||||
|
||||
|
||||
# création des tunnels ssh
|
||||
ATTENTION: dans un premier terminal !
|
||||
Pour 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
|
||||
|
||||
|
||||
|
||||
.
|
||||
40
DeepSleep/Pet_tracker_2/a.lua
Normal file
40
DeepSleep/Pet_tracker_2/a.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- Scripts pour tester l'écoute des AP WIFI
|
||||
|
||||
print("\n a.lua zf181211.0016 \n")
|
||||
|
||||
--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_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
-- print AP list in new format
|
||||
function a()
|
||||
ztime()
|
||||
function listap(t)
|
||||
print("")
|
||||
for k,v in pairs(t) do
|
||||
print(k.." : "..v)
|
||||
end
|
||||
print("")
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
end
|
||||
|
||||
--a()
|
||||
|
||||
--[[
|
||||
-- Print AP list that is easier to read
|
||||
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
|
||||
print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
|
||||
for bssid,v in pairs(t) do
|
||||
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
|
||||
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
|
||||
|
||||
]]
|
||||
57
DeepSleep/Pet_tracker_2/a_test_power_wifi.lua
Normal file
57
DeepSleep/Pet_tracker_2/a_test_power_wifi.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
-- Scripts pour tester la consommation des différents mode du WIFI
|
||||
|
||||
print("\n a_test_power_wifi zf181209.1718 \n")
|
||||
|
||||
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_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
print("mode physique: ", wifi.getphymode())
|
||||
print("defaut mode: ", wifi.getdefaultmode())
|
||||
print("wifi stat status: ", wifi.sta.status())
|
||||
|
||||
|
||||
-- print AP list in old format (format not defined)
|
||||
function listap(t)
|
||||
for k,v in pairs(t) do
|
||||
print(k.." : "..v)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(listap)
|
||||
|
||||
-- Print AP list that is easier to read
|
||||
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
|
||||
print("\n"..string.format("%32s","SSID").."\tBSSID\t\t\t\t RSSI\t\tAUTHMODE\tCHANNEL")
|
||||
for ssid,v in pairs(t) do
|
||||
local authmode, rssi, bssid, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]+)")
|
||||
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(listap)
|
||||
|
||||
|
||||
|
||||
|
||||
-- print AP list in new format
|
||||
function listap(t)
|
||||
for k,v in pairs(t) do
|
||||
print(k.." : "..v)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
|
||||
-- Print AP list that is easier to read
|
||||
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
|
||||
print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL")
|
||||
for bssid,v in pairs(t) do
|
||||
local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)")
|
||||
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
|
||||
end
|
||||
end
|
||||
wifi.sta.getap(1, listap)
|
||||
|
||||
|
||||
65
DeepSleep/Pet_tracker_2/boot.lua
Normal file
65
DeepSleep/Pet_tracker_2/boot.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
function boot()
|
||||
print("\n boot.lua zf200720.1828 \n")
|
||||
print("On lance le boot...")
|
||||
collectgarbage() print(node.heap())
|
||||
local f
|
||||
-- f = "0_http_post.lua" if file.exists(f) then dofile(f) end
|
||||
-- collectgarbage() print(node.heap())
|
||||
|
||||
-- local _, boot_reason = node.bootreason()
|
||||
-- zarg_boot= "energy,memory=boot_"..yellow_id.." ram="..node.heap().."\n"
|
||||
-- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason
|
||||
-- http_post(influxdb_url,zarg_boot)
|
||||
|
||||
-- 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
|
||||
-- collectgarbage() print(node.heap())
|
||||
|
||||
-- f="0_ultra_son.lua" if file.exists(f) then dofile(f) end
|
||||
-- collectgarbage() print(node.heap())
|
||||
|
||||
-- f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
-- collectgarbage() print(node.heap())
|
||||
|
||||
verbose = true
|
||||
print("verbose: ",verbose,"\nle boot est lancé...")
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
f=nil boot=nil
|
||||
end
|
||||
|
||||
-- function debug_rec(zdebug)
|
||||
-- local sec, usec = rtctime.get() local tm = rtctime.epoch2cal(sec + 2*3600)
|
||||
-- local ztm = string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])
|
||||
-- file.open("00_debug.txt", "a+") file.writeline(ztm.."."..usec..", "..zdebug) file.close()
|
||||
-- end
|
||||
--
|
||||
-- function rec_boot()
|
||||
-- sntp.sync(nil, nil, nil, 1)
|
||||
-- tmr_rec_boot1=tmr.create()
|
||||
-- tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
-- print("beep...")
|
||||
-- if rtctime.get() > 0 then
|
||||
-- tmr_rec_boot1:unregister()
|
||||
-- print("Voilà on à l'heure, on peut enregistrer la raison du boot...")
|
||||
-- local _, zboot_reason, zboot_detail = node.bootreason()
|
||||
-- debug_rec("boot reason: "..zboot_reason)
|
||||
-- tmr_rec_boot1=nil rec_boot=nil
|
||||
-- collectgarbage() print(node.heap())
|
||||
-- end
|
||||
-- end)
|
||||
-- end
|
||||
|
||||
verbose=true
|
||||
if rec_boot~=nil then rec_boot() end
|
||||
boot()
|
||||
collectgarbage() print(node.heap())
|
||||
|
||||
|
||||
--[[
|
||||
verbose = true
|
||||
verbose = false
|
||||
]]
|
||||
18
DeepSleep/Pet_tracker_2/cat.lua
Normal file
18
DeepSleep/Pet_tracker_2/cat.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf192026.0858 \n")
|
||||
|
||||
function cat(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()
|
||||
until zline== nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
31
DeepSleep/Pet_tracker_2/dir.lua
Normal file
31
DeepSleep/Pet_tracker_2/dir.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
-- fonction dir() pour juste afficher les fichiers avec leur taille
|
||||
|
||||
print("\n dir.lua zf191223.1455 \n")
|
||||
|
||||
function dir()
|
||||
local zdir={}
|
||||
local pfile = file.list()
|
||||
for k,v in pairs(pfile) do
|
||||
zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v
|
||||
end
|
||||
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
|
||||
size_file=nil chksum_file=nil k=nil
|
||||
end
|
||||
|
||||
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
|
||||
]]
|
||||
52
DeepSleep/Pet_tracker_2/dir3.lua
Normal file
52
DeepSleep/Pet_tracker_2/dir3.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
-- fonction dir_vers() pour afficher toutes les versions de tous les fichiers *.lua sur le NodeMCU !
|
||||
-- fonction filec(fichier) pour afficher la version d'un seul fichiers sur le NodeMCU !
|
||||
|
||||
function dir3()
|
||||
|
||||
print("\n 0_dir3.lua zf200611.1714 \n")
|
||||
|
||||
function file_vers(name_file)
|
||||
local z=""
|
||||
if string.find(name_file,"%.lua") then
|
||||
z=name_file..":"
|
||||
-- print("fichier: "..name_file)
|
||||
local f,i1,i2,j1,j2,k,t = f,i1,i2,j1,j2,k,t
|
||||
f = file.open(name_file, "r")
|
||||
while true do
|
||||
local t = f:readline() if t == nil then break end
|
||||
-- recherche de l'entête de version [print("\n ]
|
||||
-- ATTENTION, il faut échapper la '(' avec un % et convertir le '\' en char(92)
|
||||
k='print%("'..string.char(92)..'n '
|
||||
i1,j1 = string.find(t,k)
|
||||
if i1 ~= nil then
|
||||
k=string.char(92)..'n"%)'
|
||||
i2,j2 = string.find(t,k,j1)
|
||||
z=name_file..": "..string.sub(t,j1+1,i2-2)
|
||||
break
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
uart.write(0,".")
|
||||
end
|
||||
return z
|
||||
end
|
||||
|
||||
zdir={} list_files={}
|
||||
local k,v = k,v local pfile = file.list()
|
||||
for k,v in pairs(pfile) do
|
||||
zdir[#zdir+1] = file_vers(k)
|
||||
end
|
||||
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
|
||||
|
||||
dir_vers=nil file_vers=nil list_files=nil zdir=nil
|
||||
dir3=nil
|
||||
|
||||
end
|
||||
dir3()
|
||||
|
||||
--[[
|
||||
|
||||
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
|
||||
|
||||
]]
|
||||
|
||||
64
DeepSleep/Pet_tracker_2/dsleep.lua
Normal file
64
DeepSleep/Pet_tracker_2/dsleep.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
-- Teste le deep sleep !
|
||||
-- s'endore pendant xx secondes après xx secondes
|
||||
|
||||
-- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k !
|
||||
|
||||
print("\n dsleep.lua zf181211.0018 \n")
|
||||
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
function dsleep_on()
|
||||
print("timer dsleep on...")
|
||||
ztmr_SLEEP = tmr.create()
|
||||
tmr.alarm(ztmr_SLEEP, 10*1000, tmr.ALARM_SINGLE, function ()
|
||||
print("Je dors...")
|
||||
tmr.delay(100*1000)
|
||||
-- node.dsleep(4*1000*1000)
|
||||
rtctime.dsleep(30*1000*1000)
|
||||
end)
|
||||
end
|
||||
|
||||
function dsleep_off()
|
||||
print("timer dsleep off...")
|
||||
tmr.unregister(ztmr_SLEEP)
|
||||
end
|
||||
|
||||
function watch_wifi_on()
|
||||
dsleep_on()
|
||||
ztmr_watch_wifi_on=tmr.create()
|
||||
tmr.alarm(ztmr_watch_wifi_on, 1000, tmr.ALARM_AUTO , function()
|
||||
if wifi.sta.getip() == nil then
|
||||
-- print("Unconnected... (on)")
|
||||
else
|
||||
tmr.stop(ztmr_watch_wifi_on)
|
||||
print("Connected... (on)")
|
||||
-- f= "wifi_info.lua" if file.exists(f) then dofile(f) end
|
||||
watch_wifi_off()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function watch_wifi_off()
|
||||
dsleep_off()
|
||||
tmr.unregister(ztmr_watch_wifi_on)
|
||||
ztmr_watch_wifi_off=tmr.create()
|
||||
tmr.alarm(ztmr_watch_wifi_off, 1000, tmr.ALARM_AUTO , function()
|
||||
if wifi.sta.getip() == nil then
|
||||
tmr.stop(ztmr_watch_wifi_off)
|
||||
print("Unconnected... (off)")
|
||||
watch_wifi_on()
|
||||
tmr.unregister(ztmr_watch_wifi_off)
|
||||
else
|
||||
-- print("Connected... (off)")
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
print("Coucou, je suis réveillé...")
|
||||
print("Et il est: ")
|
||||
ztime()
|
||||
|
||||
watch_wifi_on()
|
||||
|
||||
19
DeepSleep/Pet_tracker_2/head.lua
Normal file
19
DeepSleep/Pet_tracker_2/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 zf192028.1516 \n")
|
||||
|
||||
function zhead(zfile)
|
||||
print("\n"..zfile.."\n-------------------------------")
|
||||
|
||||
zfilei = file.open(zfile, "r")
|
||||
i=1
|
||||
zline=file.readline()
|
||||
repeat
|
||||
-- print(i..": "..string.sub(zline,1,string.len(zline)-1))
|
||||
print(string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
if i>10 then break end
|
||||
until zline==nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
86
DeepSleep/Pet_tracker_2/initz.lua
Normal file
86
DeepSleep/Pet_tracker_2/initz.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
--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 zf200612.1632 \n")
|
||||
|
||||
verbose = true
|
||||
|
||||
function initz()
|
||||
|
||||
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()
|
||||
|
||||
--[[
|
||||
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)
|
||||
]]
|
||||
408
DeepSleep/Pet_tracker_2/luatool.py
Executable file
408
DeepSleep/Pet_tracker_2/luatool.py
Executable file
@@ -0,0 +1,408 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
version = "0.6.8 zf191225.1428"
|
||||
|
||||
print("luatool.py ver " + version)
|
||||
|
||||
#Améliorations
|
||||
# Pour voir les améliorations il faut 'chercher' les zzz
|
||||
|
||||
|
||||
#
|
||||
# ESP8266 luatool
|
||||
# Author e-mail: 4ref0nt@gmail.com
|
||||
# Site: http://esp8266.ru
|
||||
# Contributions from: https://github.com/sej7278
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
||||
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
import sys
|
||||
import serial
|
||||
from time import sleep
|
||||
import socket
|
||||
import argparse
|
||||
from os.path import basename
|
||||
|
||||
|
||||
tqdm_installed = True
|
||||
try:
|
||||
from tqdm import tqdm
|
||||
except ImportError, e:
|
||||
if e.message == 'No module named tqdm':
|
||||
tqdm_installed = False
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
|
||||
class TransportError(Exception):
|
||||
"""Custom exception to represent errors with a transport
|
||||
"""
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
class AbstractTransport:
|
||||
def __init__(self):
|
||||
raise NotImplementedError('abstract transports cannot be instantiated.')
|
||||
|
||||
def close(self):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def read(self, length):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writer(self, data):
|
||||
##zzz191124 enlève la fin de ligne afin de ne pas perturber la vérification finale
|
||||
data = data.rstrip('\r\n')
|
||||
self.writeln("file.writeline([==[" + data + "]==])\r")
|
||||
|
||||
def performcheck(self, expected):
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
if char == chr(13) or char == chr(10): # LF or CR
|
||||
if line != '':
|
||||
#zzz191124 line = line.strip()
|
||||
# zzz191021 Affiche ce que l'on a reçu du NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzread0957: {" + line + "\n}\n")
|
||||
|
||||
if line+'\r' == expected and not args.bar:
|
||||
sys.stdout.write(" -> ok")
|
||||
elif line+'\r' != expected:
|
||||
if line[:4] == "lua:":
|
||||
sys.stdout.write("\r\n\r\nLua ERROR: %s" % line)
|
||||
raise Exception('ERROR from Lua interpreter\r\n\r\n')
|
||||
else:
|
||||
expected = expected.split("\r")[0]
|
||||
sys.stdout.write("\r\n\r\nERROR")
|
||||
sys.stdout.write("\r\n send string : '%s'" % expected)
|
||||
sys.stdout.write("\r\n expected echo : '%s'" % expected)
|
||||
sys.stdout.write("\r\n but got answer : '%s'" % line)
|
||||
sys.stdout.write("\r\n\r\n")
|
||||
raise Exception('Error sending data to MCU\r\n\r\n')
|
||||
line = ''
|
||||
else:
|
||||
line += char
|
||||
if char == chr(62) and expected[i] == char:
|
||||
char = ''
|
||||
i += 1
|
||||
|
||||
|
||||
class SerialTransport(AbstractTransport):
|
||||
def __init__(self, port, baud, delay):
|
||||
self.port = port
|
||||
self.baud = baud
|
||||
self.serial = None
|
||||
self.delay = delay
|
||||
|
||||
try:
|
||||
self.serial = serial.Serial(port, baud)
|
||||
except serial.SerialException as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
self.serial.timeout = 3
|
||||
self.serial.interCharTimeout = 3
|
||||
|
||||
# zzz191021 juste après l'ouverture du port série, on attend le caractère '>'
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
line += char
|
||||
i += 1
|
||||
if args.verbose:
|
||||
print("line: ." + line + ".")
|
||||
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
# zzz191020 on fait une petite pause avant l'envoi de chaque ligne
|
||||
sleep(self.delay)
|
||||
if self.serial.inWaiting() > 0:
|
||||
self.serial.flushInput()
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
##zzz191124 attend encore un petit peu avant d'envoyer
|
||||
sleep(self.delay)
|
||||
self.serial.write(data)
|
||||
sleep(self.delay)
|
||||
# zzz191021 Affiche ce que l'on a envoyé au NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzwrite0952: {" + data + "\n}\n")
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.serial.read(length)
|
||||
|
||||
def close(self):
|
||||
self.serial.flush()
|
||||
self.serial.close()
|
||||
|
||||
|
||||
class TcpSocketTransport(AbstractTransport):
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.socket = None
|
||||
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
try:
|
||||
self.socket.connect((host, port))
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
# read intro from telnet server (see telnet_srv.lua)
|
||||
self.socket.recv(50)
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
self.socket.sendall(data)
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.socket.recv(length)
|
||||
|
||||
def close(self):
|
||||
self.socket.close()
|
||||
|
||||
|
||||
def decidetransport(cliargs):
|
||||
if cliargs.ip:
|
||||
data = cliargs.ip.split(':')
|
||||
host = data[0]
|
||||
if len(data) == 2:
|
||||
port = int(data[1])
|
||||
else:
|
||||
port = 23
|
||||
return TcpSocketTransport(host, port)
|
||||
else:
|
||||
return SerialTransport(cliargs.port, cliargs.baud, cliargs.delay)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# parse arguments or use defaults
|
||||
parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.')
|
||||
parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line')
|
||||
parser.add_argument('--delay', default=0.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.')
|
||||
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)
|
||||
# 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 '>'
|
||||
break
|
||||
sys.stdout.write(char)
|
||||
sys.exit(0)
|
||||
|
||||
if args.id:
|
||||
transport.writeln("=node.chipid()\r", 0)
|
||||
id=""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char.isdigit():
|
||||
id += char
|
||||
print("\n"+id)
|
||||
sys.exit(0)
|
||||
|
||||
# zzz191020 Ajouté la fonction restart seule
|
||||
if args.zrestart:
|
||||
transport.writeln("node.restart()\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.wipe:
|
||||
transport.writeln("local l = file.list();for k,v in pairs(l) do print(k)end\r", 0)
|
||||
file_list = []
|
||||
fn = ""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char not in ['\r', '\n']:
|
||||
fn += char
|
||||
else:
|
||||
if fn:
|
||||
file_list.append(fn.strip())
|
||||
fn = ''
|
||||
for fn in file_list[1:]: # first line is the list command sent to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("Delete file {} from device.\r\n".format(fn))
|
||||
transport.writeln("file.remove(\"" + fn + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.delete:
|
||||
transport.writeln("file.remove(\"" + args.delete + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.dest is None:
|
||||
args.dest = basename(args.src)
|
||||
# zzz191020 Affiche le fichier à envoyer
|
||||
print("File: " + args.src)
|
||||
|
||||
# open source file for reading
|
||||
try:
|
||||
try:
|
||||
f = open(args.src, "rt")
|
||||
except:
|
||||
import os
|
||||
base_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
f = open(os.path.join(base_dir, args.src), "rt")
|
||||
os.chdir(base_dir)
|
||||
except:
|
||||
sys.stderr.write("Could not open input file \"%s\"\n" % args.src)
|
||||
sys.exit(1)
|
||||
|
||||
# Verify the selected file will not exceed the size of the serial buffer.
|
||||
# The size of the buffer is 256. This script does not accept files with
|
||||
# lines longer than 230 characters to have some room for command overhead.
|
||||
num_lines = 0
|
||||
for ln in f:
|
||||
if len(ln) > 230:
|
||||
sys.stderr.write("File \"%s\" contains a line with more than 240 "
|
||||
"characters. This exceeds the size of the serial buffer.\n"
|
||||
% args.src)
|
||||
f.close()
|
||||
sys.exit(1)
|
||||
num_lines += 1
|
||||
|
||||
# Go back to the beginning of the file after verifying it has the correct
|
||||
# line length
|
||||
f.seek(0)
|
||||
|
||||
# set serial timeout
|
||||
if args.verbose:
|
||||
sys.stderr.write("Upload starting\r\n")
|
||||
|
||||
# remove existing file on device
|
||||
if args.append==False:
|
||||
if args.verbose:
|
||||
sys.stderr.write("Stage 1. Deleting old file from flash memory")
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w\")\r")
|
||||
transport.writeln("file.close()\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
else:
|
||||
if args.verbose:
|
||||
sys.stderr.write("[SKIPPED] Stage 1. Deleting old file from flash memory [SKIPPED]")
|
||||
|
||||
|
||||
# read source file line by line and write to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 2. Creating file in flash memory and write first line")
|
||||
if args.append:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"a+\")\r")
|
||||
else:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w+\")\r")
|
||||
line = f.readline()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 3. Start writing data to flash memory...")
|
||||
if args.bar:
|
||||
for i in tqdm(range(0, num_lines)):
|
||||
#zzz191124 transport.writer(line.strip())
|
||||
transport.writer(line)
|
||||
line = f.readline()
|
||||
else:
|
||||
while line != '':
|
||||
#zzz191124 transport.writer(line.strip())
|
||||
transport.writer(line)
|
||||
line = f.readline()
|
||||
|
||||
# close both files
|
||||
f.close()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 4. Flush data and closing file")
|
||||
transport.writeln("file.flush()\r")
|
||||
transport.writeln("file.close()\r")
|
||||
|
||||
# compile?
|
||||
if args.compile:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 5. Compiling")
|
||||
transport.writeln("node.compile(\"" + args.dest + "\")\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
|
||||
# restart or dofile
|
||||
if args.restart:
|
||||
transport.writeln("node.restart()\r")
|
||||
|
||||
if args.dofile: # never exec if restart=1
|
||||
transport.writeln("dofile(\"" + args.dest + "\")\r", 0)
|
||||
|
||||
if args.echo:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nEchoing MCU output, press Ctrl-C to exit")
|
||||
while True:
|
||||
sys.stdout.write(transport.read(1))
|
||||
|
||||
# close serial port
|
||||
transport.close()
|
||||
|
||||
# flush screen
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
if not args.bar:
|
||||
sys.stderr.write("\r\n--->>> All done <<<---\r\n")
|
||||
16
DeepSleep/Pet_tracker_2/repair.lua
Normal file
16
DeepSleep/Pet_tracker_2/repair.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Scripts de seconde chance pour réparer une boucle dans le restart
|
||||
|
||||
print("\n repair.lua zf181210.1456 \n")
|
||||
|
||||
--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f= "az_init_led.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
--[[
|
||||
jobtimer1=tmr.create()
|
||||
tmr.alarm(jobtimer1, 5*1000, tmr.ALARM_AUTO, function()
|
||||
print("repair...")
|
||||
end)
|
||||
]]
|
||||
12
DeepSleep/Pet_tracker_2/restart.lua
Normal file
12
DeepSleep/Pet_tracker_2/restart.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
-- Scripts pour faire un soft reset
|
||||
|
||||
print("\n restart.lua zf181209.1753 \n")
|
||||
|
||||
restarttimer1=tmr.create()
|
||||
tmr.alarm(restarttimer1, 2*1000, tmr.ALARM_SINGLE, function()
|
||||
node.restart()
|
||||
end)
|
||||
|
||||
print("hello zuzu")
|
||||
|
||||
|
||||
BIN
DeepSleep/Pet_tracker_2/schemas/water-level.fzz
Normal file
BIN
DeepSleep/Pet_tracker_2/schemas/water-level.fzz
Normal file
Binary file not shown.
24
DeepSleep/Pet_tracker_2/set_time.lua
Normal file
24
DeepSleep/Pet_tracker_2/set_time.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Scripts pour régler l'horloge quand on est connecté en WIFI
|
||||
|
||||
print("\n set_time.lua zf181212.0841 \n")
|
||||
|
||||
--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_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
|
||||
function set_time()
|
||||
sntp.sync(nil, nil, nil, 1)
|
||||
end
|
||||
|
||||
function ztime()
|
||||
tm = rtctime.epoch2cal(rtctime.get()+3600)
|
||||
print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
end
|
||||
|
||||
set_time()
|
||||
|
||||
48
DeepSleep/Pet_tracker_2/upload_s.sh
Normal file
48
DeepSleep/Pet_tracker_2/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 ;-)"
|
||||
45
DeepSleep/Pet_tracker_2/wifi_info.lua
Normal file
45
DeepSleep/Pet_tracker_2/wifi_info.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf200106.1803 \n")
|
||||
|
||||
function wifi_info()
|
||||
local zmodewifi=wifi.getmode()
|
||||
|
||||
--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
|
||||
|
||||
if zmodewifi == wifi.NULLMODE then
|
||||
print("WIFI OFF")
|
||||
elseif zmodewifi == wifi.STATION then
|
||||
print("WIFI mode CLI")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP\n")
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
print("Current AP config:")
|
||||
local ap_config=wifi.ap.getconfig(true)
|
||||
print("\tssid:", ap_config.ssid)
|
||||
print("\tpassword:", ap_config.pwd)
|
||||
print("\tbssid:", wifi.ap.getmac())
|
||||
elseif zmodewifi == wifi.STATIONAP then
|
||||
print("WIFI mode CLI+AP\n")
|
||||
print("CLIENT IP:\n",wifi.sta.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current CLIENT config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid.."\n")
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
print("Current AP config:")
|
||||
local ap_config=wifi.ap.getconfig(true)
|
||||
print("\tssid:", ap_config.ssid)
|
||||
print("\tpassword:", ap_config.pwd)
|
||||
print("\tbssid:", wifi.ap.getmac())
|
||||
end
|
||||
wifi_info=nil
|
||||
end
|
||||
wifi_info()
|
||||
|
||||
92
DeepSleep/Pet_tracker_2/wifi_init.lua
Normal file
92
DeepSleep/Pet_tracker_2/wifi_init.lua
Normal file
@@ -0,0 +1,92 @@
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf200621.1608 \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_tst5_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.STATION,true)
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd} wifi.sta.connect()
|
||||
|
||||
-- wifi.setmode(wifi.STATIONAP,true)
|
||||
-- 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")
|
||||
]]
|
||||
44
zflash-esp-m3.sh
Executable file
44
zflash-esp-m3.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
#Petit script pour flasher facilement les ESP-M3 avec un firmware
|
||||
|
||||
#ATTENTION: c'est pour ma structure, il faudra donc l'adapter
|
||||
|
||||
#zf200720.1838
|
||||
|
||||
|
||||
#test si l'argument est vide
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo -e "\nSyntax:
|
||||
|
||||
Pour le dernier firmware à la mode:
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-16-modules-2019-12-01-22-17-07-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-11-modules-2019-12-15-16-45-47-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-18-modules-2019-12-17-20-28-32-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-12-modules-2019-12-21-11-05-58-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-19-modules-2019-12-31-16-40-12-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-19-modules-2020-06-17-17-22-55-float.bin
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-19-modules-2020-06-17-18-07-17-float.bin
|
||||
|
||||
Pour l'ancien qui supporte encore le DS18B20:
|
||||
./zflash-esp-m3.sh ../../Firmware/nodemcu-master-20-modules-2019-06-01-12-50-39-float.bin
|
||||
|
||||
|
||||
|
||||
"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo ---------- start zflash.sh
|
||||
|
||||
cd ./Tools/esptool-master
|
||||
|
||||
python esptool.py flash_id
|
||||
sleep 2
|
||||
|
||||
python esptool.py erase_flash
|
||||
sleep 2
|
||||
|
||||
python esptool.py write_flash -fm dout 0x00000 $1
|
||||
sleep 2
|
||||
# screen /dev/cu.wchusbserial1410 115200
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ATTENTION: c'est pour ma structure, il faudra donc l'adapter
|
||||
|
||||
#zf191231.1912
|
||||
#zf200720.1838
|
||||
|
||||
|
||||
#test si l'argument est vide
|
||||
@@ -12,14 +12,14 @@ if [ -z "$1" ]
|
||||
echo -e "\nSyntax:
|
||||
|
||||
Pour le dernier firmware à la mode:
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-16-modules-2019-12-01-22-17-07-float.bin
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-11-modules-2019-12-15-16-45-47-float.bin
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-18-modules-2019-12-17-20-28-32-float.bin
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-12-modules-2019-12-21-11-05-58-float.bin
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-19-modules-2019-12-31-16-40-12-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-16-modules-2019-12-01-22-17-07-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-11-modules-2019-12-15-16-45-47-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-18-modules-2019-12-17-20-28-32-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-12-modules-2019-12-21-11-05-58-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-19-modules-2019-12-31-16-40-12-float.bin
|
||||
|
||||
Pour l'ancien qui supporte encore le DS18B20:
|
||||
./zflash-eps01.sh ../../Firmware/nodemcu-master-20-modules-2019-06-01-12-50-39-float.bin
|
||||
./zflash-esp01.sh ../../Firmware/nodemcu-master-20-modules-2019-06-01-12-50-39-float.bin
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user