1 | wifi.setmode(wifi.SOFTAP) -- set mode as access point
|
2 | wifi.ap.config({ssid= "ESP_XXX", pwd="123456789"}) -- configure own SSID as ‘ESP_TEST’ and password as
|
3 | outpin=4 -- Select right IO index !! Here is settings for GPIO2 (Lua build 20141219)
|
4 |
|
5 | uart.setup(0, 9600, 8, 0, 1, 1 ) -- Change the baudrate to 115200 neu 9600
|
6 |
|
7 | --neu zum speichern--
|
8 | file.open("valueR.txt","r")
|
9 | --file.writeline(200)
|
10 | xxxR = tonumber(file.readline())
|
11 | file.close()
|
12 |
|
13 | srv=net.createServer(net.TCP)
|
14 | srv:listen(80,function(conn)
|
15 | conn:on("receive",function(conn,payload)
|
16 | --next row is for debugging output only
|
17 | --print("-----")
|
18 | --print(payload)
|
19 | --print("-----")
|
20 |
|
21 |
|
22 | function ctrlpower()
|
23 | pwm.close(outpin)
|
24 | gpio.mode(outpin,gpio.OUTPUT)
|
25 | dotaz=string.sub(payload,kdesi[2]+1,#payload)
|
26 | if dotaz=="ON" then gpio.write(outpin,gpio.HIGH)return end
|
27 | if dotaz=="OFF" then gpio.write(outpin,gpio.LOW)return end
|
28 | if dotaz=="FLC" then pwm.setup(outpin,2,512)pwm.start(outpin)return end
|
29 |
|
30 | --pwm.setup(outpin,1000,dotaz*10)
|
31 | --pwm.start(outpin)
|
32 | end
|
33 | --parse position POST value from header
|
34 | kdesi={string.find(payload,"pwm_a=")}
|
35 | --If POST value exist, set LED power
|
36 | if kdesi[2]~=nil then ctrlpower()
|
37 | --uart.write(0, payload) --R
|
38 |
|
39 |
|
40 | --file.open("valueR.txt","r")
|
41 | --file.writeline(payload)
|
42 |
|
43 | end
|
44 |
|
45 |
|
46 | --neu
|
47 | file.open("valueR.txt","r")
|
48 | xxxR = tonumber(file.readline())
|
49 | file.close()
|
50 | --neu
|
51 |
|
52 |
|
53 | testwert = 200
|
54 |
|
55 | conn:send('HTTP/1.1 200 OK\n\n')
|
56 | conn:send('<!DOCTYPE HTML>\n')
|
57 | conn:send('<html>\n')
|
58 | conn:send('<head><meta content="text/html; charset=utf-8">\n')
|
59 | conn:send('<title>ESP8266</title></head>\n')
|
60 | conn:send('<body><h1>Sample GPIO output control</h1>\n')
|
61 | conn:send('<h3>For Lua NodeMcu 0.9.2 build 20141219 only !!!</h3>\n')
|
62 | conn:send('<h3>Tested with IE 11. and Chrome 39.</h3>\n')
|
63 | conn:send('<IMG SRC="http://esp8266.fancon.cz/common/led.gif" WIDTH="150" HEIGHT="101" BORDER="1"><br><br>\n')
|
64 | conn:send('<form action="" method="POST">\n')
|
65 | conn:send('<input type="range" name="pwm_a" min="0" value="'.. xxxR ..'" max="255">\n')
|
66 | --conn:send('<input type="range" name="pwm_b" min="0" max="255">\n')
|
67 | --conn:send('<input type="range" name="pwm_c" min="0" max="255">\n')
|
68 | conn:send('<input type="submit" name=""\n')
|
69 | --neu
|
70 | --conn:send('</form>\n')
|
71 | --neu
|
72 | conn:send('</body></html>\n')
|
73 | conn:on("sent",function(conn) conn:close() end)
|
74 |
|
75 | --print("AAA")
|
76 | print(dotaz) --DAS HIER SIEHT GUT AUS
|
77 | --print(kdesi[1])
|
78 | --print("AAA")
|
79 |
|
80 | --neu2
|
81 | --file.open("valueR.txt","r")
|
82 | --file.writeline(100)
|
83 | --file.close()
|
84 | --neu2
|
85 |
|
86 | end)
|
87 | end)
|