This is a strange behavior on code related to uart receive event.
I have to add data=data at the begining of function on uart receive event
Maybe some buffer issues dont know..
.
.
.
uart.setup(0,9600,8,0,1,0)
uart.on("data", "\r",
function(data)
data=data
a=string.find(data, "==")
if a then
print("valid content: ",data)
print("valuebefore: ",value)
value=string.sub(data,a+2,string.len(data))
num=tonumber(value)
print("new value: ",value)
conn:send("POST espwireless?temperature=10&solar=800&pump=" .. num .. " HTTP/1.1\r\nHost: server.io\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
label=string.sub(data,1,a-1)
print("posted: ",value)
end
if data=="quit\r" then
uart.setup(0,9600,8,0,1,1)
uart.on("data")
end
return value
end, 0)
.
.
.
*******************original post*********************************************
Hi, Im trying to POST some data to webserver that comes from uart but some is wrong when i add a variable to request
Uart is reading sucessfull strings like value==12345
Here is code:
conn=net.createConnection(net.TCP, false)
newmili = 0
value="sas"
value2="20"
result=0
i=0
conn:on("receive", function(conn, pl) a=string.find(pl, "created") e=string.sub(pl,a+27,a+32) mil=string.sub(e,4,6) mili=tonumber(mil) result=mili-newmili newmili=mili if result<0 then result=result+1000; end print(result) i=i+2 print(i) end)
uart.setup(0,9600,8,0,1,0)
uart.on("data", "\r",
function(data)
a=string.find(data, "==")
if a then
print("valid content: ",data)
value=string.sub(data,a+2,string.len(data))
print("value: ",value)
conn:send("POST /espwireless?temperature=10&solar=800&pump=300 HTTP/1.1\r\nHost: server.io\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
label=string.sub(data,1,a-1)
print("posted: ",value)
end
if data=="quit\r" then
uart.setup(0,9600,8,0,1,1)
uart.on("data")
end
end, 0)
conn:connect(80,"server")
This way I can POST sucessfull, but next i add variable
With next code stops sending data dont know why
I just replaced conn:send("POST /espwireless?temperature=10&solar=800&pump=" .. value .. " HTTP/1.1\r\nHost: server.io\r
to send variable value
conn=net.createConnection(net.TCP, false)
newmili = 0
value="sas"
value2="20"
result=0
i=0
conn:on("receive", function(conn, pl) a=string.find(pl, "created") e=string.sub(pl,a+27,a+32) mil=string.sub(e,4,6) mili=tonumber(mil) result=mili-newmili newmili=mili if result<0 then result=result+1000; end print(result) i=i+2 print(i) end)
uart.setup(0,9600,8,0,1,0)
uart.on("data", "\r",
function(data)
a=string.find(data, "==")
if a then
print("valid content: ",data)
value=string.sub(data,a+2,string.len(data))
print("value: ",value)
conn:send("POST /espwireless?temperature=10&solar=800&pump=" .. value .. " HTTP/1.1\r\nHost: server.io\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
label=string.sub(data,1,a-1)
print("posted: ",value)
end
if data=="quit\r" then
uart.setup(0,9600,8,0,1,1)
uart.on("data")
end
end, 0)
conn:connect(80,"server")
But another strange behavior
if I add to code value2=i +1
and send value2 varible it works fine and send an incrementing variable
value2=i +1
conn:send("POST /espwireless?temperature=10&solar=800&pump=" .. value2 .. " HTTP/1.1\r\nHost: server.io\r
Any help is welcome,
Regards ,Vito