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

User avatar
By Divinity82
#30462 I am trying to set a delay based on what is returned from a request but the values of "rtime" and "wtime" never change.
What am I doing wrong? The code will run once and print the default values of the variables but then won't work again when you click the button.

Code: Select allpin=4
rtime=1000
wtime=1000

gpio.write(pin, gpio.LOW)
gpio.mode(pin,gpio.OUTPUT)

srv=net.createServer(net.TCP) srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)

if (string.find(payload,"runtime=") and string.find(payload,"waittime=") and string.find(payload,"relay_on")) then
  gpio.write(pin, gpio.HIGH)
  tmr.delay(rtime)
  gpio.write(pin, gpio.LOW)
  tmr.delay(wtime)
elseif (string.find(payload,"runtime=1") and string.find(payload,"waittime=1") and string.find(payload,"relay_on")) then
  rtime=1000000
  wtime=1000000
  gpio.write(pin, gpio.HIGH)
  tmr.delay(rtime)
  gpio.write(pin, gpio.LOW)
  tmr.delay(wtime)
  print(rtime)
  print(wtime)
end

if string.find(payload,"favicon.ico") == nil then
  conn:send('<html><form method="POST" name="wstcc" ><p>Run Time: <input name="runtime" value="" />     Wait Time: <input name="waittime" value="" /></p><p><input type="submit" name="lo" value="relay_on" /></p></form></body>')
end

end)

conn:on("sent",function(conn) conn:close() collectgarbage() end)

end)