SHARE
TWEET

mqtt2.lua

a guest Dec 8th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local srv = "http://91.226.122.210:15781"
  2.  
  3. local signal = 0
  4.  
  5. local ch = {1, 4, 128, 256, 1024}
  6. local pld = 0
  7.  
  8.  
  9. local mon = peripheral.wrap("front")
  10. mon.setTextScale(0.5)
  11. term.redirect(mon)
  12. term.setCursorPos(1,1)
  13. term.clear()
  14.  
  15. local mag = peripheral.wrap("top")
  16.  
  17. print("Access card required")
  18. local msevt, token = os.pullEvent("mag_swipe")
  19.  
  20. term.clear()
  21.  
  22. local interval = 5
  23.  
  24.  
  25. local MAXATTEMPTS = 5
  26. local attempt = 0
  27.  
  28.  
  29.  
  30. while not http.checkURL(srv) do
  31.     print("Server unavailable. Retrying...")
  32.     attempt = attempt + 1
  33.     if attempt > MAXATTEMPTS then
  34.         print("Connection failed")
  35.         os.exit()
  36.     end
  37.     sleep(10)
  38. end
  39.  
  40. -- print("Server alive")
  41. while true do
  42.     rsevt = os.pullEvent("redstone")
  43.     --signal = redstone.getBundledInput("left")
  44.     --print(signal)
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.     for i=0, 4 do
  48.         if redstone.testBundledInput("left", ch[i+1]) then
  49.             print("CH" .. i .." ON")
  50.             pld = 1
  51.         else
  52.             print("CH" .. i .." OFF")
  53.             pld = 0
  54.         end    
  55.         http.get(srv .. "/pub/wrkshp/room/ch" .. i .. "?token=" .. token .. "&payload=" .. pld)
  56.     end    
  57.     sleep(1)
  58. --    term.clear()
  59. --    term.setCursorPos(1,1)
  60.  
  61. 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
 
Top