client/server: to test
This commit is contained in:
commit
55603f969e
2 changed files with 41 additions and 0 deletions
32
wifi_client.lua
Normal file
32
wifi_client.lua
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
|
9
wifi_server.lua
Normal file
9
wifi_server.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
-- Initialize the Wi-Fi server
|
||||||
|
wifi.setmode(wifi.STATIONAP)
|
||||||
|
wifi.sta.config("SachamamaGoingHome", "GoFoundIt")
|
||||||
|
wifi.sta.connect()
|
||||||
|
wifi.sta.http.start()
|
||||||
|
|
||||||
|
wifi.sta.http.on("receive", function(conn, payload)
|
||||||
|
print(payload)
|
||||||
|
end)
|
Loading…
Add table
Add a link
Reference in a new issue