Here is the code I'm trying to adapt for flashmod , I don't really know where to start.
I'm unclear if I can put the 1st 8 lines in flash , and how to do it?
I have several vars I will be receiving updated values over the serial port [if I can get that sorted out] that will need to stay in ram ..
I thought I could put all the C:send in flash, but not sure if the vars would update when executed.
I'm at the not enough memory and can't node compile because not enough memory....
Converting this could be a good learning exercise for many of us without great programming skills.
All help will be greatly appreciated
wifi.setmode(wifi.STATION)
wifi.sta.config("12345-NETGEAR","mikeis12345")
tmr.alarm(0, 1000, 1, function(QQ)
print("Try Connecting:")
ip, nm, gw=wifi.sta.getip()
if ip ~= nil then
print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)
tmr.stop(0)
end
end)
rfctr=0
adc_id = 0
adc_value = 512
k1=0.11
p00='P'
apc0='11111'
ppm0='1770'
cdeg0='25.1'
kta0='0.01'
lo0='12'
hi0='20'
prb='01.0'
ph='7.0'
sbuf=""--('D=dump Z=calibrate= z [table 1-5] [slot0-9] ppmcal ppmcnt\r\n'
--..'============================== EEPROM DUMP ======================\r\n'
--..'000> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n020>\r\n040>\r\n060>\r\n080>\r\n100>\r\n120>\r\n140>\r\n160>\r\n180>\r\n')
--..'020>\r\n') -- 01840,45350 02000,48550 02450,66535 02800,65535 03260,54350\r\n'
--..'040>\r\n') -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n'
--..'060>\r\n' --- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n' -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n') -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n' -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n' -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n' -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')
--..'000>\r\n') -- 00001,00032 00342,65535 00700,66536 01000,34770 01400,65535\r\n')--]]
Eopn=0
B_Opn = "http://i.imgur.com/kzt3tO8.png"
B_Clo = "http://i.imgur.com/KS1dPa7.png"
bgc="Cyan"
s_img = B_Opn
-- simple uart input appears to work
uart.setup(0,9600,8,0,1)
--uart.on("data",40,function(data) print("Rcv uart: ",data) end,0)
--uart.on("data","\n\r",function(data) print("Rcv uart: ",data) end,0)
--uart.setup(0,9600,8,0,1)
srv = net.createServer(net.TCP, 30)
srv:listen(80,function(C)
C:on("receive", function(C, payload)
function esp_update()
--print("--PL--",payload)
m_do=string.sub(payload,postparse[2]+1,#payload)
x=string.find(m_do,"&m_do=")
if x ~= nil then
cmd=string.sub(m_do,x+6,#m_do)
m_do=string.sub(m_do,1,x-1)
else
cmd=string.sub(m_do,1,#m_do)
m_do=nil
end
cmd=string.gsub(cmd,"+","") -- remove lead/trail +
-- print("m_do-2 ",m_do," cmd "..cmd)
if cmd ~= nil then
print("---",cmd)
uart.write(0,cmd.."\n\r") -- send to PIC
-- print("-->uart-->pic=|"..cmd.."\n\r")
end
if m_do == "RD_ADC" then
adc_value = adc.read(adc_id)
if adc_value > 1023 then
adc_value = 1023
elseif adc_value < 0 then
adc_value = 0
end
end
if m_do == "BLINK" then
if Eopn==0 then
s_img =B_Clo
Eopn=1
bgc="Yellow"
else
s_img =B_Opn
Eopn=0
bgc="Cyan"
end
end
if m_do == "TEMP_DN" then
apc0 = apc0 + 100
cdeg0=round2((cdeg0-1),1)
end
if m_do == "TEMP_UP" then
apc0 = apc0 - 100
cdeg0=round2((cdeg0+1),1)
end
end
postparse={string.find(payload,"m_do=")}
if postparse[2]~=nil then esp_update()end
--C:send('HTTP/1.1 200 OK\n\n')
fdeg0 = round2((cdeg0*1.8) +32,1)
ppm1=round2(ppm0/(((cdeg0-25)*.021)+1),1)
ppm2=round2((ppm0*46.5)/(cdeg0+21.5),1 )
pha=25-cdeg0
if pha < 0 then
pha = round2((ph + (pha*.002)),2)
else
pha = round2((ph + (pha*.004)),2)
end
rfh='15'
C:send('<!DOCTYPE HTML>\n<html lang="en-US">\n<head><meta http-equiv="refresh" content="'..rfh..'" ></head>\n')
C:send('<script type = "text/javascript">\nvar timeInSecs;\nvar ticker;')
C:send('function startTimer(secs){ timeInSecs = parseInt(secs)-1; ticker = setInterval("tick()",1000); }')
C:send('function tick() { var secs = timeInSecs; if (secs>0) {timeInSecs--;} else {clearInterval(ticker); startTimer('..rfh..');}')
C:send('document.getElementById("countdown").innerHTML = secs;} startTimer('..rfh..'); </script>')
C:send('<body><div><table bgcolor="Lawngreen" border="1" cellpadding="5"><th><h1>ESP8266 Blinker Thing!</h1></th><td>'
..'<IMG SRC="'..s_img..'" LEFT="1" WIDTH="120" HEIGHT="60" BORDER="1"></td><th id="countdown">'..rfh..'</th></table><div><br>')
C:send('<textarea name="cmds" cols="70" rows="14">'..sbuf..'</textarea></div><br>')
C:send('<textarea name="cmds" cols="70" rows="6">'..sbuf..'</textarea></div><br>')
C:send('<div><table bgcolor="'..bgc..'" border="1" cellpadding="5">')
C:send('<tr><th>Sensor</th><th>TempC</th><th>TempF</th><th>PPMcntr</th><th>PPM__</th><th>Adj__1</th><th>Adj__2</th></tr>')
C:send('<tr><td>DS18B20'..p00..'</td><td>'..cdeg0..'</td><td>'..fdeg0..'</td><td>'..apc0..'</td><td>'..ppm0..'</td><td>'..ppm1..'</td>')
C:send('<td>'..ppm2..'</td></tr><tr><th>Probe-K</th><th>Pool-PH</th><th>PH-Adj</th><th>ADC Value</th></tr>')
C:send('<tr><td>'..prb..'</td><td>'..ph..'</td><td>'..pha..'</td><td bgcolor="Red">'..adc_value..'</td></tr></table></div><br>')
C:send('<form action="" method="POST">\n<input type="submit" name="m_do" value="BLINK" style="padding:5px;10px;">')
C:send('<input type="submit" name="m_do" value="RD_ADC" style="padding:5px;10px;">')
C:send('<input type="submit" name="m_do" value="TEMP_DN" style="padding:5px;10px;">')
C:send('<input type="submit" name="m_do" value="TEMP_UP" style="padding:5px;10px;"><br>')
C:send('"CMD:"<input type="text" name="m_do" value="" maxlength="100" style="padding:5px;10px;">')
C:send('<input type="submit" value="Submit"></form>\n<br></body></html>\n')
C:on("sent", function(C) C:close() end)
end)
rfctr=(rfctr+1)
rfc=math.floor((rfctr/2)+0.5) -- seems to double count so /2 and round
if (rfc % 2)==0 then
bgc="Cyan" --even
else
bgc="Yellow" --odd
end
end)
function round2(num, idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
function si(sIN)
buffer=sIN
if string.find(sIN,"=si('") then
sa=string.find(sIN,"=si('I")
sb=string.find(sIN,"')")
sbuf=sbuf..string.sub(sIN,sa+6,sb)
end
-- print("\n\rbuf--",buffer)
if string.find(sIN,"co") then
if string.find(sIN,"bo") then
cx=(string.find(sIN,"co"))+2
cdeg0 = string.sub(sIN,cx,cx+3)
if string.find(sIN,"ao") then
cx=(string.find(sIN,"bo"))+2
ppm0=string.sub(sIN,cx,cx+3)
if string.find(sIN,"xo") then
cx=(string.find(sIN,"ao"))+2
apc0 = string.sub(sIN,cx,cx+4)
end
end
end
end
end
function cbuf()
if #sbuf + #sIN > 200 then
sbuf = sIN
else
sbuf = sbuf..sIN
end
end
function all_trm(s)
return s:match( "^%s*(.-)%s*$" )
end
function all_trim(s)
return s:match"^%s*(.*)":match"(.-)%s*$"
end