37 lines
843 B
Lua
37 lines
843 B
Lua
local M = {}
|
|
local logger = require("logger")
|
|
|
|
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
|
|
logger.log("No modem found. Cannot report status.")
|
|
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")
|
|
logger.log("Broadcasted status: " .. status)
|
|
|
|
sleep(2)
|
|
end
|
|
end
|
|
|
|
return M
|