turtle/status_broadcast.lua
2025-06-27 13:46:36 +01:00

44 lines
968 B
Lua

local id = os.getComputerID()
local label = os.getComputerLabel() or ("Turtle_" .. id)
local status = "idle" -- Can be changed based on the turtle's job
-- Try to open modem
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. Aborting.")
return
end
-- Display header
term.clear()
term.setCursorPos(1, 1)
print("Status Broadcaster")
print("------------------")
while true do
local msg = {
id = id,
label = label,
status = status,
time = os.clock()
}
local serialized = textutils.serialize(msg)
rednet.broadcast(serialized, "turtle_status")
-- Print to screen
term.setCursorPos(1, 5)
term.clearLine()
print("Sent at: " .. os.date("%H:%M:%S"))
sleep(5)
end