Advertisement
Sanwiches

redNetMonitor

Jan 15th, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. -- Finds devices connected to the computer, wraps them
  2. local function getDevices(deviceType) -- This function was taken from https://github.com/sandalle/minecraft_bigreactor_control and has been modified by https://github.com/Sanwi
  3. local deviceName = nil
  4. local deviceIndex = 1
  5. local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
  6. local peripheralList = peripheral.getNames() -- Get table of connected peripherals
  7. for peripheralIndex = 1, #peripheralList do -- Log every device found
  8. if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then -- Log devices found which match deviceType and which device index we give them
  9. deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  10. deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  11. deviceIndex = deviceIndex + 1
  12. end
  13. end -- for peripheralIndex = 1, #peripheralList do
  14. return deviceList, deviceNames
  15. end
  16.  
  17. local deviceList, deviceNames = getDevices("modem")
  18. local modem = deviceList[1]
  19.  
  20. rednet.open(deviceNames[1])
  21.  
  22. while true do
  23. local senderId, message, protocol = rednet.receive()
  24.  
  25. if type(message) == "string" then
  26. print(message)
  27. elseif type(message) == "table" then
  28. print(textutils.serialize(message))
  29. else
  30. print(message)
  31. end
  32. local event,key = os.pullEvent("key")
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement