Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ws, err
- local m = peripheral.find "modem"
- local function connect()
- while true do
- if ws then ws.close() end
- ws, err = http.websocket "wss://r.osmarks.net/cc-metrics"
- if ws then print "Connected" break
- else printError(err) sleep(1) end
- end
- end
- local function send(x)
- if not ws then connect() end
- local ok, err = pcall(ws.send, textutils.serialiseJSON(x))
- if not ok then
- printError(err)
- connect()
- end
- end
- while true do
- m.open(3054)
- local _, _, c, rc, m, d = os.pullEvent "modem_message"
- if type(m) == "table" and #m == 4 then
- print(m[1], m[3], m[4])
- send(m)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement