client/server: to test

This commit is contained in:
e2200662 2025-04-23 14:38:27 +02:00
commit 55603f969e
2 changed files with 41 additions and 0 deletions

32
wifi_client.lua Normal file
View 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
View 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)