etelan

stationv1.2

Jan 27th, 2022 (edited)
266
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. component = require("component")
  2. detector = component.ir_augment_detector
  3. control = component.ir_augment_control
  4. event = require("event")
  5. os = require("os")
  6. internet = component.internet
  7.  
  8. stationName = "grassland"
  9.  
  10. url = "http://localhost:8011"
  11. local readhash = "abe6db4c9f5484fae8d79f2e868a673c"
  12.  
  13. while true do
  14.   event.pull("ir_train_overhead")
  15.   control.setThrottle(0)
  16.   control.setBrake(1)
  17.   tag = detector.getTag()
  18.  
  19.   if tag == nil or tag == "" then
  20.     print("Unregistered train!")
  21.     local registerAnswer
  22.     repeat
  23.       io.write("Register Train (y/n)? ")
  24.       io.flush()
  25.       registerAnswer=io.read()
  26.     until registerAnswer=="y" or registerAnswer=="n"
  27.    
  28.     if answer == y then
  29.  
  30.       local newTag
  31.       io.write("Write your train tag!")
  32.       io.flush()
  33.       newTag = io.read()
  34.       detector.setTag(newTag)
  35.  
  36.       local addHash = "abe6db4c9f5484fae8d79f2e868a673c"
  37.       local handle = internet.request(url .. "/addTrain?tag=" .. newTag .. "&passHash=" .. addHash .. "&station=" .. stationName)
  38.       print(handle.finishConnect())
  39.     end
  40.   else
  41.       local updatehash = "abe6db4c9f5484fae8d79f2e868a673c"
  42.       local handle = internet.request(url .. "/updateTrainByName?tag=" .. tag .. "&passHash=" .. updateHash .. "&station=" .. stationName)
  43.       print(handle.finishConnect())
  44.     print(tag)
  45.   end
  46.  
  47.   os.sleep(1)
  48. end
RAW Paste Data Copied