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

Machine monitoring program

Started by Grapengeter, 01 December 2014 - 08:33 PM
Grapengeter #1
Posted 01 December 2014 - 09:33 PM
Hello,
I am trying to set up a machine monitoring system on my private server so I can see which machines are running, how they get activated and much more.
At the moment I have three programs running in this network (look at the picture):
The main computer (left), the satellite (top, a normal computer) and a computer at my tree farm (ignore the nuclear reactor to the left of the tree farm for now).

These are my codes:
tree farm: http://pastebin.com/26eMyWnD
main computer: http://pastebin.com/50a17fDi
satellite: http://pastebin.com/6KhzskVM

What the programs should do is:
Control the tree farm (and other machines when it works) from any computer in the network by sending "Tree.true/false" via modem to the satellite which will send it to the tree farm. The tree farm should be turned on/off and send information about it back to the satellite and from the satellite to the monitoring computer which lists the information.
The tree farm also sends information about how it was (de-)activated (Redstone or Network/Computer).

My problem is that when I activate my tree farm with modem.transmit(101, 100, "Tree.true") (or deactivate it with "Tree.false") it turns on/off but doesn't send information back to the main computer.
When activating/deactivating the tree farm with redstone (attached to the front of the computer at the tree farm), everything works fine.
If you take a look at the picture you can see which computer uses which port. Red line is the command route, Green line is the information route.

What I noticed is that the problem should be in this code:

function control()
  rs.setOutput("right", Info["rs"])
  Message = textutils.serialize(Info)
  modem.transmit(PortOut, PortIn, Message)
  Time = textutils.formatTime(os.time(), true)
  Day = os.day()
  print(Day.." - "..Time.." - "..Message)
end
It prints the Message but it is not sent to/not received by the satellite.


If you have any questions regarding this, I will answer them :)/>

I have no idea where I made the mistake, maybe I'm just blind but I tried different changes for hours already.
Bomb Bloke #2
Posted 02 December 2014 - 01:30 AM
My initial guess, without looking at the other scripts, is the "sleep(0)" you've got in the satellite code. This'll cause issues in that the satellite will "miss" messages sent to it.

The sleep function works by queuing a timer event to fire at some point in the future (minimum of 0.05 seconds), then pulling every event from the event queue and discarding them until it finds the timer event it wants. If any modem messages are in the queue, odds are they'll be wiped out.

Anyway, delete that line and give it another go.
Grapengeter #3
Posted 02 December 2014 - 10:50 AM
Thank you so much, it worked!
You can not believe how happy I am right now and how retarded I feel :D/>