Advertisement
melzneni

RFDisplayWirelessMonitor

Jun 9th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. args={...}
  2. if #args==0 then
  3. error("required arguments: monitorName")
  4. end
  5. mName=args[1]
  6.  
  7. monitor=peripheral.wrap("right")
  8.  
  9. rednet.open("left")
  10.  
  11. function connect()
  12. print("connecting to server...")
  13. while true do
  14. rednet.broadcast("connectToServer:"..mName,"monitoring")
  15. msg={rednet.receive("monitoring",1)}
  16. if msg[1]~=nil then
  17. id=msg[1] -- id,msg,distance,protocol
  18. if msg[2]=="successfullyConnected" then
  19. print("successfully connected to server")
  20. return id
  21. else
  22. error("unknown message: "..msg[2])
  23. end
  24. end
  25. end
  26. end
  27.  
  28. function len(txt)
  29. return #txt
  30. end
  31.  
  32. function ping()
  33. i=0
  34. while i<3 do
  35. rednet.send(host,"ping","monitoring")
  36. msg={rednet.receive("monitoring",1)}
  37. if msg[1]~=nil then
  38. return true
  39. end
  40. i=i+1
  41. end
  42. return false
  43. end
  44.  
  45. host=connect()
  46.  
  47. while true do
  48. if ping()==false then
  49. print("ping failed")
  50. host=connect()
  51. end
  52.  
  53. msg={rednet.receive("monitoring",1)}
  54. if msg[1]~=nil then
  55. print(msg[2])
  56. if msg[2]:sub(1,len("displayMsg:"))=="displayMsg:" then
  57. txt=msg[2]:sub(len("displayMsg:")+1)
  58. monitor.clear()
  59. monitor.setCursorPos(1,1)
  60. monitor.write(txt)
  61. else
  62. print("unknown message: "..msg[2])
  63. end
  64.  
  65. end
  66.  
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement