This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PyroGodz's profile picture

Creating a rednet server that logs what other computers do?

Started by PyroGodz, 30 September 2012 - 02:19 PM
PyroGodz #1
Posted 30 September 2012 - 04:19 PM
Hey guys, I'm pretty new to CC. What I'm trying to do is create a RedNet server that will allow me to send messages from all the computers doing tasks, to the main hub, which logs all of the data, and at what time this happened.

The things I'm not sure how to do.. are basically, sending the info to the main hub, recording the time. Currently everything being done is logged locally, but without time. As I do not know how to setup time.

If anyone could point me in the right direction of setting up global computer time and sending logs from task computers to the main hub, that would be great! Thanks!
Anonomit #2
Posted 30 September 2012 - 04:34 PM
If all the computers send a message to the main computer, the main computer could create a table for each message, containing the time, then the message

id, msg, dist = rednet.receive()
table = { textutils.formatTime(os.time(), true), msg )  --change the true to false if you don't want to save in 24-hour time
string = textutils.serialize(table)
file = io.open( "file.txt", "w" )
file:write( string )
file:close()

os.time() returns the current minecraft time, but in an unappealing format. textutils.formatTime() fixes that.


Late this could be done to retrieve the log

file = io.open( "file.txt", "r" )
string = file:read()
file:close()
table = textutils.unserialize(string)
print( table[1].." - "..table[2] )
jag #3
Posted 30 September 2012 - 04:55 PM
SpoilerIf all the computers send a message to the main computer, the main computer could create a table for each message, containing the time, then the message

id, msg, dist = rednet.receive()
table = { textutils.formatTime(os.time(), true), msg )  --change the true to false if you dont want to save in 24-hour time
string = textutils.serialize(table)
file = io.open( "file.txt", "w" )
file:write( string )
file:close()

os.time() returns the current minecraft time, but in an unappealing format. textutils.formatTime() fixes that.


Late this could be done to retrieve the log

file = io.open( "file.txt", "r" )
string = file:read()
file:close()
table = textutils.unserialize(string)
print( table[1].." - "..table[2] )
Straight forward, dosen't get easier then that.
PyroGodz #4
Posted 30 September 2012 - 06:05 PM
Ok, well I haven't gotten to where I will try sending the logs to the hub yet, as I haven't been able to get the script for my docking bay working.

I am trying to write in the terminal "ostime: Minecart has entered bay four."


EDIT: Ok.. I have nearly got it working. The only issue now, is that the time won't update between when a minecart comes to bay four, and when a minecart leaves bay four. I know I can just update the time before it leaves, but I was wondering if there's a way to have it continually update.

New code:


line = 0

delay = 5

term.clear()

while true do

local t = os.time()

time = textutils.formatTime(t,false)

if redstone.getInput("bottom") then

line = line+1
	term.setCursorPos(1,line)

write (time)
write (": Minecart arrived at bay four.)

sleep(delay)

redstone.setOutput("back", true)

line = line+1

term.setCursorPos(1,line)


write (time)
write (": Minecart left bay four.)

sleep(2)

redstone.setOutput("back", false)

end

sleep(0.1)

end
cant_delete_account #5
Posted 30 September 2012 - 07:24 PM
Ok, well I haven't gotten to where I will try sending the logs to the hub yet, as I haven't been able to get the script for my docking bay working.

I am trying to write in the terminal "ostime: Minecart has entered bay four."


EDIT: Ok.. I have nearly got it working. The only issue now, is that the time won't update between when a minecart comes to bay four, and when a minecart leaves bay four. I know I can just update the time before it leaves, but I was wondering if there's a way to have it continually update.
Try this:
Spoiler

local delay = 5
term.clear()
term.setCursorPos(1,1)
while true do
if redstone.getInput("bottom") then
print(textutils.formatTime(os.time(),false)..": Minecart arrived at bay four.)
sleep(delay)
redstone.setOutput("back", true)
print(textutils.formatTime(os.time(),false)..": Minecart left bay four.)
sleep(2)
redstone.setOutput("back", false)
end
sleep(0.1)
end
(I simplified the code, too)
PyroGodz #6
Posted 30 September 2012 - 07:45 PM
Ok, well I haven't gotten to where I will try sending the logs to the hub yet, as I haven't been able to get the script for my docking bay working.

I am trying to write in the terminal "ostime: Minecart has entered bay four."


EDIT: Ok.. I have nearly got it working. The only issue now, is that the time won't update between when a minecart comes to bay four, and when a minecart leaves bay four. I know I can just update the time before it leaves, but I was wondering if there's a way to have it continually update.
Try this:
Spoiler

local delay = 5
term.clear()
term.setCursorPos(1,1)
while true do
if redstone.getInput("bottom") then
print(textutils.formatTime(os.time(),false)..": Minecart arrived at bay four.)
sleep(delay)
redstone.setOutput("back", true)
print(textutils.formatTime(os.time(),false)..": Minecart left bay four.)
sleep(2)
redstone.setOutput("back", false)
end
sleep(0.1)
end
(I simplified the code, too)

That won't print different lines of code.. it will simply replace the first line over and over again. My code prints on a new line everytime a minecart comes in or goes out.
I've also figured it out, thanks though :)/>/>

The last issue i'm having with the station is arrival/depature bells.
I'm wondering if there is a way to have a computer literally play a sound, instead of needing a noteblock. Because the way I have things compacted, there is nowhere suitable for me to put noteblocks. Thanks! :(/>/>
MysticT #7
Posted 30 September 2012 - 07:54 PM
That won't print different lines of code.. it will simply replace the first line over and over again. My code prints on a new line everytime a minecart comes in or goes out.
You know that print goes to the next line after writing the text, right?

The last issue i'm having with the station is arrival/depature bells.
I'm wondering if there is a way to have a computer literally play a sound, instead of needing a noteblock. Because the way I have things compacted, there is nowhere suitable for me to put noteblocks. Thanks! :)/>/>
Computers can't play sounds, you'll have to use a noteblock or some peripheral.