Advertisement
osmarks

Untitled

Jun 7th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. local ws, err
  2. local m = peripheral.find "modem"
  3.  
  4. local function connect()
  5. while true do
  6. if ws then ws.close() end
  7. ws, err = http.websocket "wss://r.osmarks.net/cc-metrics"
  8. if ws then print "Connected" break
  9. else printError(err) sleep(1) end
  10. end
  11. end
  12.  
  13. local function send(x)
  14. if not ws then connect() end
  15. local ok, err = pcall(ws.send, textutils.serialiseJSON(x))
  16. if not ok then
  17. printError(err)
  18. connect()
  19. end
  20. end
  21.  
  22. while true do
  23. m.open(3054)
  24. local _, _, c, rc, m, d = os.pullEvent "modem_message"
  25. if type(m) == "table" and #m == 4 then
  26. print(m[1], m[3], m[4])
  27. send(m)
  28. end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement