41 lines
917 B
Lua
41 lines
917 B
Lua
local M = {}
|
|
|
|
local modemOpened = false
|
|
for _, side in ipairs({"top", "bottom", "left", "right", "front", "back"}) do
|
|
if peripheral.getType(side) == "modem" then
|
|
rednet.open(side)
|
|
modemOpened = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if not modemOpened then
|
|
print("No modem found!")
|
|
|
|
end
|
|
|
|
local id = os.getComputerID()
|
|
local label = os.getComputerLabel() or ("Turtle_" .. id)
|
|
|
|
function M.reportStatus(getStatusFn)
|
|
while true do
|
|
local status = getStatusFn()
|
|
local msg = {
|
|
id = id,
|
|
label = label,
|
|
status = status,
|
|
time = os.time()
|
|
}
|
|
rednet.broadcast(textutils.serialize(msg), "turtle_status")
|
|
|
|
-- Optional: print for debug
|
|
term.setCursorPos(1, 5)
|
|
term.clearLine()
|
|
print("Broadcasted: " .. status .. " @ " .. textutils.formatTime(os.time(), true))
|
|
|
|
sleep(2)
|
|
end
|
|
end
|
|
|
|
return M
|