SHARE
TWEET

mqtt1.lua

a guest Dec 8th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local srv = "http://91.226.122.210:15781"
  2. local mon = peripheral.wrap("top")
  3. term.redirect(mon)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. local mag = peripheral.wrap("left")
  7.  
  8. term.setTextColour(colors.black)
  9. term.setBackgroundColor(colors.red)
  10. print("Access card required")
  11. local msevt, token = os.pullEvent("mag_swipe")
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. term.setTextColor(colors.white)
  15. term.setBackgroundColor(colors.black)
  16. term.clear()
  17.  
  18. local interval = 60
  19.  
  20. local MAXATTEMPTS = 12
  21. local attempt = 0
  22.  
  23. local topics = {"wrkshp/room/t0", "wrkshp/room/t1"}
  24.  
  25. while not http.checkURL(srv) do
  26.     print("Server unavailable. Retrying...")
  27.     attempt = attempt + 1
  28.     if attempt > MAXATTEMPTS then
  29.         print("Connection failed")
  30.         os.exit()
  31.     end
  32.     sleep(10)
  33. end
  34.  
  35. -- print("Server alive")
  36. while true do
  37.  
  38. for i=1, #topics do
  39.     topic = topics[i]
  40.     req, err = http.get(srv .. "/sub/" .. topic .. "?token=" .. token)
  41.     if not req then error(err) end
  42.     result = tostring(req.readAll())
  43.     print(topic .. ": " .. result)
  44.     req.close()
  45. end
  46.  
  47. sleep(interval)
  48. term.clear()
  49. term.setCursorPos(1,1)
  50.  
  51. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top