The lua code for the webpage i am using: (sorry for the dutch words in it)
uart.setup(0,9600,8,0,1,0)
hoogte_vijver = 1
srv=net.createServer(net.TCP) srv:listen(80,function(conn2)
conn2:on("receive",function(conn2,payload)
print(payload)
if string.find(payload,"comm=") ~= nil then --we ontvangen een commando
if string.find(payload,"vijver") ~= nil then
print('H\n') --commando H doorsturen, in arduino vraagt dit de hoogte op van de vijver
teller = 0
while hoogte_vijver < 2 do
print ("wachten op data")
if teller > 100 then break end
teller = teller + 1
end
if hoogte_vijver == 1 then conn2:send("fout geen hoogte bekend") else conn2:send(hoogte_vijver) end
hoogte_vijver = 1
end
end
end)
conn2:on("sent",function(conn2) conn2:close() end)
end)
When the command H is send to the arduino it measures the distance and sends the result back by changing the lua variable ( ex println(hoogte_vijver=60) in arduino)
However it seems that i cannot change the variable while i am in the while loop, so it does not work.
Can anyone tell me how to solve this?