diff --git a/status_broadcast.lua b/status_broadcast.lua index e69197d..9e070ad 100644 --- a/status_broadcast.lua +++ b/status_broadcast.lua @@ -1,13 +1,43 @@ local id = os.getComputerID() -local status = "idle" -- or "busy", "charging", etc. +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 = os.getComputerLabel() or ("Turtle_" .. id), + label = label, status = status, time = os.clock() } - rednet.broadcast(textutils.serialize(msg), "turtle_status") + + 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 \ No newline at end of file +end