-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.lua
More file actions
31 lines (28 loc) · 871 Bytes
/
socket.lua
File metadata and controls
31 lines (28 loc) · 871 Bytes
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
local ws, err = http.websocket("ws://vetterlain.dk:8080/websocket/" .. arg[1])
if not ws then
return printError(err)
end
local function send()
while true do
ws.send(textutils.serializeJSON({
time = textutils.formatTime(os.time()),
day = os.day(),
-- position = locate(), only if gps is setup
label = os.computerLabel()
-- power = math.floor((power / maxPower) * 100), perform a check to see if we are connected to some kinda power
}))
sleep(.3)
end
end
local function receive()
while true do
local command = ws.receive();
local success, result = pcall(loadstring('return ' .. command))
if not success then
ws.send(result)
else
ws.send(result)
end
end
end
parallel.waitForAll(send, receive)