32 lines
796 B
Lua
32 lines
796 B
Lua
function start_wifi()
|
|
print("Starting WiFi...")
|
|
wifi.setmode(wifi.STATIONAP)
|
|
wifi.sta.config("SachamamaGoingHome", "GoFoundIt") -- Set SSID and password
|
|
wifi.sta.connect()
|
|
end
|
|
|
|
local dataReceive={}
|
|
|
|
start_wifi()
|
|
|
|
tmr.alarm(0, 1000, 1, function()
|
|
if wifi.sta.status() == wifi.STA_GOTIP then
|
|
print("WiFi connected!")
|
|
print("IP Address: " .. wifi.sta.getip())
|
|
tmr.stop(0)
|
|
|
|
elseif wifi.sta.status() == wifi.STA_CONNECTING then
|
|
print("Connecting to WiFi...")
|
|
else
|
|
print("WiFi connection failed.")
|
|
end
|
|
end)
|
|
|
|
-- Function to send data to the server
|
|
function sendData(data)
|
|
local conn = net.createConnection(net.TCP, 0)
|
|
conn:on("receive", function(conn, payload) print(payload) end)
|
|
conn:connect(80, "")
|
|
end
|
|
|
|
|