Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local srv = "http://91.226.122.210:15781"
- local mon = peripheral.wrap("top")
- term.redirect(mon)
- term.clear()
- term.setCursorPos(1,1)
- local mag = peripheral.wrap("left")
- term.setTextColour(colors.black)
- term.setBackgroundColor(colors.red)
- print("Access card required")
- local msevt, token = os.pullEvent("mag_swipe")
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- local interval = 60
- local MAXATTEMPTS = 12
- local attempt = 0
- local topics = {"wrkshp/room/t0", "wrkshp/room/t1"}
- while not http.checkURL(srv) do
- print("Server unavailable. Retrying...")
- attempt = attempt + 1
- if attempt > MAXATTEMPTS then
- print("Connection failed")
- os.exit()
- end
- sleep(10)
- end
- -- print("Server alive")
- while true do
- for i=1, #topics do
- topic = topics[i]
- req, err = http.get(srv .. "/sub/" .. topic .. "?token=" .. token)
- if not req then error(err) end
- result = tostring(req.readAll())
- print(topic .. ": " .. result)
- req.close()
- end
- sleep(interval)
- term.clear()
- term.setCursorPos(1,1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement