forked from CreatorBot/3D-Printing-ESP8266
-
Notifications
You must be signed in to change notification settings - Fork 15
/
init.lua
65 lines (59 loc) · 1.69 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--'
-- CreatorBot ESP8266 Serial WIFI Connect
-- Author: Chetan Patil.
-- LICENCE: http://opensource.org/licenses/MIT
-- Last modified 2015-01-03. V0.0
-- CreatorBot.com
--'
Tstart = tmr.now()
ConnStatus = nil
function Start_Data()
sv=net.createServer(net.TCP, 60)
global_c = nil
sv:listen(9999, function(c)
if global_c~=nil then
global_c:close()
end
global_c=c
c:on("receive",function(sck,pl) uart.write(0,pl) end)
end)
uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
end
function ConnStatus(n)
status = wifi.sta.status()
local x = n+1
if (x < 50) and ( status < 5 ) then
if(status==0) then
wifi.sta.connect()
print("\n IDLE")
end
tmr.alarm(0,100,0,function() ConnStatus(x) end)
elseif(status== 2) then
print("\n WRONG PASSWORD")
tmr.alarm(0,1000,0,function() dofile('WIFI_Reset.lua')end)
elseif(status==3) then
print("\n AP NOT FOUND")
tmr.alarm(0,1000,0,function() dofile('WIFI_Reset.lua')end)
elseif(status==4) then
print("\nConnection failed")
tmr.alarm(0,1000,0,function() dofile('init.lua')end)
elseif(status==5) then
print('\nConnected as '..wifi.sta.getip())
local myIP= nil
myIP =wifi.sta.getip()
uart.setup(0,115200,8,0,1,0)
for i = 1, 4, 1 do
uart.write(0," M117 ")
uart.write(0, myIP)
uart.write(0,"\n")
end
tmr.alarm(0,1000,0,function() Start_Data() end)
end
end
wifi.setmode(wifi.STATION)
print("\n CONNECTING TO WIFI")
tmr.alarm(0,100,0,function() ConnStatus(0) end)