44 lines
963 B
Lua
44 lines
963 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.time()
|
|
}
|
|
|
|
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
|