Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. modem = peripheral.wrap("left");
  2. time = ""
  3. outputFile = "log";
  4. count = 0;
  5. monitor = {}
  6. state = false;
  7. modem.open(28812);
  8.  
  9. --Functions
  10.  
  11. function addMonitor(...)
  12. local monList = peripheral.getNames();
  13.  
  14. for i,m in ipairs(monList) do
  15. local curr = peripheral.wrap(m);
  16.  
  17. if peripheral.getType(m) == "monitor" and curr.isColour() == true then
  18. print("Found monitor on side: " .. m);
  19. state = true;
  20. monitor[0] = {
  21. peripheral = curr;
  22. }
  23. end;
  24. end;
  25. end;
  26.  
  27. function getTime(...)
  28. local web = http.get("http://api.timezonedb.com/v2/get-time-zone?key=NV11PJAS1020&format=json&by=zone&zone=America/Los_Angeles").readAll();
  29. time = string.sub(web,276,283);
  30. end;
  31.  
  32. --Pre
  33.  
  34. addMonitor();
  35.  
  36. logFile = fs.open(outputFile,"a");
  37. logFile.writeLine("----------------------------");
  38. logFile.close();
  39.  
  40. while true do
  41. local event,modemSide,senderChannel,replyChannel,message,senderDistance = os.pullEvent("modem_message");
  42. getTime();
  43. str = time .. " | " .. message;
  44. logFile = fs.open(outputFile,"a");
  45. --print(str);
  46. if state == true then
  47. monitor[0].peripheral.clear();
  48. monitor[0].peripheral.setCursorPos(1,1);
  49. monitor[0].peripheral.write(str);
  50. end;
  51. logFile.writeLine(str);
  52. logFile.close();
  53. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement