As the title says... Chat on...

User avatar
By Trilex
#11243 Hi,
please excuse my bad english.
I had a problem with reboots in my script. sometimes it reboot. Anyone have an idea?
The script reboot the most time after splitting and post the text on oled.
(wifi.sta.config infos deleted)

Code: Select allwifi.sta.config("SSID","password")

linelength  =24
wifi.sta.setip({ip="192.168.178.111",netmask="255.255.255.0",gateway= "192.168.178.1"})

oled.setup(4,3)
oled.clear()
oled.invert(0)
oled.line(1, 1, wifi.sta.getip() )

print(wifi.sta.getip())

srv=net.createServer(net.TCP) srv:listen(80,function(conn)
  conn:on("receive",function(conn,payload)
    inputs = {}
    payload = payload:gsub("%%3A+", ":")
    payload = payload:gsub("%%5B", "")
    payload = payload:gsub("%%5D", "")
    payload = payload:gsub("+", " ")
    if string.match(payload, "(text1)=(.+)") then
      for k, teilstring in string.gmatch(payload,"(text1)=(.+)") do
        inputs[k] = teilstring
      end
      payload = nil
      if inputs.text1 ~= nil then
           splitedtxt = split(inputs.text1, linelength)
           inputs.text1 = nil
           oled.clear()
           for i = 1 , #splitedtxt do
               oled.line(i, 1, splitedtxt[i])
               splitedtxt[i] = nil
               tmr.delay(1000)
           end
      end
    end
   

    conn:send('HTTP/1.1 200 OK\n\n')
    conn:send('<!DOCTYPE HTML>\n')
    conn:send('<html>\n')
    conn:send('<head><meta  content="text/html; charset=utf-8">\n')
    conn:send('<title>EasyPlay</title></title>\n')
    conn:send('<body><h1>EasyPlay</h1>\n')
    conn:send('<form action="" method="POST">\n')
    conn:send('<input type="text" name="text1" size="25" value="AAAAAAA"><br>\n')
    conn:send('<input type="submit" value=" send ">')
    conn:send('</form></body></html>\n')
    conn:on("sent",function(conn) conn:close() end)
    print("connection closed")
  end)
end)


function split(str, max_line_length)
   local lines = {}
   local line
   str:gsub('(%s*)(%S+)',
      function(spc, word)
         if not line or #line + #spc + #word > max_line_length then
            table.insert(lines, line)
            line = word
         else
            line = line..spc..word
         end
      end
   )
   table.insert(lines, line)
   return lines
end


I use "NodeMCU 0.9.5 build 20150127" with oled support from this thread. I want to understand the issue.

greetings & thanks
Alex

Edit: add link
User avatar
By Trilex
#11396 for hours of time-wasting later I know almost nothing.... :roll: :|

the trouble is in the split function. If I donT use the split function and create a Table manualy, the script work without reboots. EDIT: sometimes it reboot after all...
Change
Code: Select allsplitedtxt = noobsplit(inputs.text1, linelength)
into
Code: Select allsplitedtxt = {"sagaerg","aefqawefw","rwerkzkzkzk","sagaerg","aefqawefw","rwerkzkzkzk","sagaerg","aefqawefw","rwerkzkzkzk"}
anf everything is good.

In the last hours I try many different steps to split the payload, but everytime the script reboot erratic...

Good night everybody :?