You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
766 B

local url = "wss://echo.websocket.org"
local json = textutils.serializeJSON({
client = "computer_moon",
target = "n8n_to_webapp",
request = "update_info_moon",
content = {
moon_status = "full"
}
})
local ws, err = http.websocket(url)
if not ws then
print("Erreur de connexion :", err)
return
end
print("Connecté !")
-- envoi du JSON au serveur
ws.send(json)
print("Payload envoyé !")
while true do
local event, urlOrMsg, msg = os.pullEvent()
if event == "websocket_message" then
print("Serveur:", msg)
elseif event == "key" then
-- touche appuyée -> renvoi ping
ws.send("ping")
elseif event == "websocket_closed" then
print("WebSocket fermée.")
break
end
end