nodeMCU reboot during string concatenation?
Posted: Wed Apr 15, 2015 1:24 pm
When calling M.update({15}) I get three numbers from node.heap(), then nothing, which tells me the crash is happening in print('Field '..i..': '..v). Any thoughts?
Code: Select all
local api_host = 'api.thingspeak.com'
local api_path = '/update'
local get_template = 'GET '..api_path..'?api_key='..api_key
local function update_factory(getstring)
return function (s)
if debug then print('Connected!') end
if debug then print('Sending: '..getstring) end
s:send(getstring..'\r\n\r\n')
end
end
local function sendUpdate(getstring)
s = net.createConnection(net.TCP, 1)
if debug then print("socket created...") end
s:on("connection", update_factory(getstring) )
s:on("receive", function (s, r) if debug then print("Return from API: "..r) end s:close() s = nil end)
if debug then print("callbacks registered...") end
s:connect(443,api_host)
if debug then print ("connect requested...") end
end
function M.update(data)
local getstring = get_template
print(node.heap())
for i,v in ipairs(data) do
print(node.heap())
if i < 9 then
print(node.heap())
print('Field '..i..':'..v)
getstring = getstring.."&field"..i.."="..v
end
end
print(node.heap())
if debug then print('Preparing connection') end
sendUpdate(getstring)
end
return M