Advertisement
Guest User

weblocal

a guest
Oct 24th, 2015
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. -- v12345vtm youtube https://youtu.be/MzH8zR34x0Y
  2. --http://www.instructables.com/editInstructable/publish/EDRHQW8IG415EAG
  3.  
  4.  
  5.  
  6.  
  7. -----uart mode
  8. uart.setup(0,9600,8,0,1)
  9.  
  10.  
  11. -- Your Wifi connection data
  12. local SSID = "yourSSID"
  13. local SSID_PASSWORD = "yourSSIDpassword"
  14. local rtctijd = "15:50"
  15.  
  16. local var1 = "initvar1"
  17. local var2 = "initvar2"
  18. local var3 = "initvar3"
  19.  
  20.  
  21. local function connect (conn, data)
  22. webcode=" ";
  23. webcode = webcode .. "<html>"
  24. webcode = webcode .. "<body>"
  25. webcode = webcode .. "<br><hr>"
  26. webcode = webcode .. " <form method=\"get\"> "
  27. webcode = webcode .. "p1,ssid: <input type=\"text\" name=\"p1\" value=\"".. var1.."\"><br>"
  28. webcode = webcode .. "p2,passw: <input type=\"text\" name=\"p2\" value=\"".. var2.."\" ><br> "
  29. webcode = webcode .. "p3,time: <input type=\"text\" name=\"p3\" value=\"".. var3.."\" ><br> "
  30. webcode = webcode .. "<input type=\"submit\" value=\"SET\"> <INPUT TYPE=\"button\" onClick=\"history.go(0)\" VALUE=\"GET\"></form> "
  31. webcode = webcode .. "</body>"
  32. webcode = webcode .. "</html>"
  33.  
  34. conn:on ("receive",function (cn, req_data)
  35.  
  36. --print("wat is dat hier")
  37. print (req_data)
  38. -- print("staat er hier iet boven")
  39.  
  40.  
  41. if string.match(req_data, "p1") then
  42.  
  43.  
  44. positiep1 = string.find(req_data, "p1")
  45. positiep2 = string.find(req_data, "p2")
  46. positiep3 = string.find(req_data, "p3")
  47. positieEnd = string.find(req_data, "HTTP/")
  48.  
  49. valuep1 = (string.sub(req_data, positiep1+3, positiep2-2))
  50. valuep2 = (string.sub(req_data, positiep2+3 , positiep3-2))
  51. valuep3 = (string.sub(req_data, positiep3+3 , positieEnd-2))
  52. uart.write (0, valuep1 , "\r\n")
  53. uart.write (0, valuep2 , "\r\n")
  54. uart.write (0, valuep3 , "\r\n") -- = time-15-10-23-12-27-35-4
  55.  
  56. var1 = valuep1
  57. var2 = valuep2
  58. var3 = valuep3 --webfomtijd opslaan
  59.  
  60. else
  61. -- print ("geen data in form ingevuld gewest of de browser vroeg zijn favicon.ico daarnet ook nog")
  62. end
  63. cn:send (webcode)
  64. -- Close the connection for the request
  65. cn:close ( )
  66.  
  67. end)
  68. end
  69.  
  70.  
  71.  
  72.  
  73. function wait_for_wifi_conn ( )
  74. tmr.alarm (1, 1000, 1, function ( )
  75. if wifi.sta.getip ( ) == nil then
  76. print ("Waiting for Wifi connection")
  77. else
  78. tmr.stop (1)
  79. print ("ESP8266 mode is: " .. wifi.getmode ( ))
  80. print ("The module MAC address is: " .. wifi.ap.getmac ( ))
  81. print ("Config done, IP is " .. wifi.sta.getip ( ))
  82. ---gpio.write(led1, gpio.HIGH)
  83. end
  84. end)
  85. end
  86.  
  87.  
  88.  
  89.  
  90.  
  91. -- Configure the ESP as a station (client)
  92. wifi.setmode (wifi.STATION)
  93. wifi.sta.config (SSID, SSID_PASSWORD)
  94. wifi.sta.autoconnect (1)
  95.  
  96. -- Hang out until we get a wifi connection before the httpd server is started.
  97. wait_for_wifi_conn ( )
  98.  
  99. -- Create the httpd server
  100. svr = net.createServer (net.TCP, 30)
  101.  
  102. -- Server listening on port 80, call connect function if a request is received
  103. svr:listen (80, connect)
  104.  
  105.  
  106.  
  107.  
  108. print ("uart.setup(0,9600,8,0,1) finished")
  109. print ("waiting for serial data....")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement