Fait un nouveau firmware minimaliste pour essayer de gagner de la RAM, mais finalement je n'ai gagné que 100 bytes de RAM :-(

This commit is contained in:
Christian Zufferey
2019-12-21 12:42:35 +01:00
parent 234d69ca49
commit 11ec004436
9 changed files with 223 additions and 16 deletions

View File

@@ -1,13 +1,13 @@
-- Petit script pour faire office de crontab pour les
--mesures
print("\n 0_cron.lua zf191217.2222 \n")
print("\n 0_cron.lua zf191220.2245 \n")
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
flash_led_xfois()
xfois =2
--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 ()
-- blink_LED ()
send_data()
end)

View File

@@ -59,8 +59,8 @@ https://github.com/zuzu59/NodeMCU_Lua/blob/master/Firmware/nodemcu-master-18-mod
Avec ces modules:
```
adc,ads1115,bit,enduser_setup,file,gpio,http,i2c,net,node,ow,rtctime,si7021,sntp,spi,tmr,uart,wifi
```
file gpio http i2c net node rtctime sntp tmr uart wifi
```
## Utilisation
@@ -126,7 +126,7 @@ telnet -rN 192.168.0.xxx
zf191219.1924
zf191221.0825
pense bête:

View File

@@ -1,5 +1,35 @@
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf191218.0820
# zf191221.1133
zf191220.1447
BUG1:
1) quand on démarre rapidement après un power off en cliquant sur le btn on vide mal la mémoire
car on a pas passé par seconde_chance dans init.lua !
choses pas vidées:
gpio.trig(zswitch)
hvbouton=nil
zswitch=nil
reset_reason=nil
il reste encore ces variables en trop en mémoire !
hvbouton function: 0x3fff0d28
initalarme userdata: 0x3fff14a8
initalarme2 userdata: 0x3fff1530
reset_reason 6
zswitch 3
BUG2
dans 0_cron.lua on n'a pas besoin de la ligne:
flash_led_xfois()
# si luatool ne marche pas sur le MAC, il faut lire ceci:
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0
@@ -16,9 +46,9 @@ export zIP="192.168.0.113"
#th0
192.168.0.118
#th1
#th1 19512
192.168.0.143
#th2
#th2 19432
192.168.0.132
#th3
192.168.0.145
@@ -32,6 +62,7 @@ export zIP="192.168.0.113"
#export zIP="192.168.0.137"
export zport="23"
cd '/Users/zuzu/Google Drive/FamilleZ Share/FamilleZ/Papa/LUA/NodeMCU ESP8266/NodeMCU_Lua/Mesures/humidity/bolo
@@ -171,12 +202,16 @@ ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.1.11
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
verbose=false
verbose=true
dofile("dir2.lua")
dir()
filec("head.lua")

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot2.lua zf191217.2224 \n")
print("\n boot2.lua zf191220.2319 \n")
function boot2()
second_chance=nil initz=nil boot=nil
@@ -31,15 +31,26 @@ function boot2()
f= "0_send_data.lua" if file.exists(f) then dofile(f) end
f= "0_cron.lua" if file.exists(f) then dofile(f) end
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
f=nil
verbose = true
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
print("BOOOOUM, y'a plus de boot2 !")
print("BOOOOUM, y'a plus de boot2 !")
wifi_info=nil boot2=nil
print(node.heap())
collectgarbage()
print(node.heap())
end)
--tmr.create():alarm(7*1000, tmr.ALARM_SINGLE, function()
-- print("MUOOOOB !")
-- collectgarbage()
-- print(node.heap())
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
-- f=nil
--end)
end
end)
end

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# Petit script pour télécharger facilement tout le binz via le port série
#zf191216.2139
#zf191221.1126
# 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 !
@@ -27,6 +27,7 @@ read -p "Est-ce bien vide ?"
./luatool.py --port $luatool_tty --bar -f wifi_init.lua
./luatool.py --port $luatool_tty --bar -f wifi_info.lua
./luatool.py --port $luatool_tty --bar -f web_srv2.lua
./luatool.py --port $luatool_tty --bar -f 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

View File

@@ -0,0 +1,159 @@
-- Petit WEB IDE tout simple autonome
-- ATTENTION: tourne sur le port 88 !
print("\n _web_ide2.lua zf181221.1137 \n")
--[[
XChip's NodeMCU IDE
Create, Edit and run NodeMCU files using your webbrowser.
Examples:
http://<mcu_ip>/ will list all the files in the MCU
http://<mcu_ip>/newfile.lua displays the file on your browser
http://<mcu_ip>/newfile.lua?edit allows to creates or edits the specified script in your browser
http://<mcu_ip>/newfile.lua?run it will run the specified script and will show the returned value
]]--
srv=net.createServer(net.TCP)
srv:listen(88,function(conn)
local rnrn=0
local Status = 0
local DataToGet = 0
local method=""
local url=""
local vars=""
conn:on("receive",function(conn,payload)
if Status==0 then
_, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP")
print(method, url, vars)
end
if method=="POST" then
if Status==0 then
--print("status", Status)
_,_,DataToGet, payload = string.find(payload, "Content%-Length: (%d+)(.+)")
if DataToGet~=nil then
DataToGet = tonumber(DataToGet)
--print(DataToGet)
rnrn=1
Status = 1
else
print("bad length")
end
end
-- find /r/n/r/n
if Status==1 then
--print("status", Status)
local payloadlen = string.len(payload)
local mark = "\r\n\r\n"
local i
for i=1, payloadlen do
if string.byte(mark, rnrn) == string.byte(payload, i) then
rnrn=rnrn+1
if rnrn==5 then
payload = string.sub(payload, i+1,payloadlen)
file.open(url, "w")
file.close()
Status=2
break
end
else
rnrn=1
end
end
if Status==1 then
return
end
end
if Status==2 then
--print("status", Status)
if payload~=nil then
DataToGet=DataToGet-string.len(payload)
--print("DataToGet:", DataToGet, "payload len:", string.len(payload))
file.open(url, "a+")
file.write(payload)
file.close()
else
conn:send("HTTP/1.1 200 OK\r\n\r\nERROR")
Status=0
end
if DataToGet==0 then
conn:send("HTTP/1.1 200 OK\r\n\r\nOK")
Status=0
end
end
return
end
DataToGet = -1
if url == "favicon.ico" then
conn:send("HTTP/1.1 404 file not found")
return
end
conn:send("HTTP/1.1 200 OK\r\n\r\n")
-- it wants a file in particular
if url~="" and vars=="" then
DataToGet = 0
return
end
conn:send("<html><body><h1>NodeMCU IDE</h1>")
if vars=="edit" then
conn:send("<script>function tag(c){document.getElementsByTagName('w')[0].innerHTML=c};\n")
conn:send("var x=new XMLHttpRequest()\nx.onreadystatechange=function(){if(x.readyState==4) document.getElementsByName('t')[0].value = x.responseText; };\nx.open('GET',location.pathname,true)\nx.send()</script>")
conn:send("<h2><a href='/'>Back to file list</a>\n")
conn:send("<br><br><button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob(")
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
conn:send("<a href='"..k.."?edit'>"..k.."</a>, size:"..v.."<br>")
end
end
conn:send("</body></html>")
end)
conn:on("sent",function(conn)
if DataToGet>=0 and method=="GET" then
if file.open(url, "r") then
file.seek("set", DataToGet)
local line=file.read(512)
file.close()
if line then
conn:send(line)
DataToGet = DataToGet + 512
if (string.len(line)==512) then
return
end
end
end
end
conn:close()
end)
end)
print("listening, free:", node.heap())

View File

@@ -3,7 +3,7 @@
#ATTENTION: c'est pour ma structure, il faudra donc l'adapter
#zf191217.2104
#zf191221.1223
#test si l'argument est vide
@@ -15,6 +15,7 @@ Pour le dernier firmware à la mode:
./zflash.sh ../../Firmware/nodemcu-master-16-modules-2019-12-01-22-17-07-float.bin
./zflash.sh ../../Firmware/nodemcu-master-11-modules-2019-12-15-16-45-47-float.bin
./zflash.sh ../../Firmware/nodemcu-master-18-modules-2019-12-17-20-28-32-float.bin
./zflash.sh ../../Firmware/nodemcu-master-12-modules-2019-12-21-11-05-58-float.bin
Pour l'ancien qui supporte encore le DS18B20:
./zflash.sh ../../Firmware/nodemcu-master-20-modules-2019-06-01-12-50-39-float.bin