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

How to send commands wirelessly, and some monitor help?

Started by Elektro7, 20 September 2013 - 07:38 PM
Elektro7 #1
Posted 20 September 2013 - 09:38 PM
Title: How to send commands wirelessly, and some monitor help?

I'm new to computercraft, only able to do what's probably the most basic of stuff on my own such as running a program on a monitor, sending a message over rednet, and password locking a computer, so please go slowly for my sake.

I'm wondering how to do a few things:

1. How to have a program write to both a computer screen, and a monitor
For example, I can do "monitor left adventure", and run the Adventure program on my monitor, but each time I type in a command, I have to close out the computer UI and then go look at the monitor because nothing will show up on the computer. I'd like it to write to both, so I can just keep going on the computer, but also be able to look at the monitor to see everything, not just one or the other.

2. How to send commands over rednet
I have a simple startup program that automatically opens rednet, and then I can do "rednet.receive()" to hold it open for a message, and "rednet.broadcast("Message")" on another computer to send some text over to the other, but that's it. How would I make it so I can run programs on one computer from another, and not just send/receive text?

3. How to do confirmation messages depending on the current state of something.
Ultimately what I'm trying to do is use my one main computer to control a lot of my base's functions by sending commands to other computers and having them do things. running a program like "Engines" send a message to another computer to toggle my engines on/off if they're overheating or something, or telling another computer to start running adventure, so it's running and waiting for me, and I can look at the monitor and see my progress at a glance before going into the computer to actually play it.
But for example, with the engines, I'd like it to say something like "Engines are now off" or "Engines are now on" so I'm not just blindly toggling, and I'm not sure how I can do that.

All of this seems like it would be relatively simple to do, but then again I know next to nothing.
Lyqyd #2
Posted 20 September 2013 - 10:37 PM
1. You'd have to write a terminal redirect that writes to both the monitor and the terminal. This is a pretty common thing, so there are a variety of them on the forums.

2. This depends on how you want to do it. If you just want to send a command for the other computer to run, it's pretty simple. You just take the rednet message and pass it to shell.run() and the computer will run the program. If you want to see the other screen, you'd want something like nsh, which is a lot of work to program and rather complex if you're just starting out.

3. If you want to actually detect what the engines are doing, you'd need a peripheral mod like OpenCCSensors, MiscPeripheral, or OpenPeripheral. If you just want your computers to respond with what the current state of their redstone output is, that's a great deal simpler.
Elektro7 #3
Posted 21 September 2013 - 12:02 AM
Thanks, I'll check those out.

And I think I may have an idea on how to detect the redstone, I just checked and they can detect their own output as in input if the redstone goes directly into them or an adjacent block. Not sure how I can code that though.

And how can I pass a program to shell.run()?
Elektro7 #4
Posted 21 September 2013 - 01:01 AM
I got programs to run remotely with this:

local id, message = rednet.receive()
If message = "on" then
shell.run("adventure")
end

Just a test to run Adventure by sending it, "on", and it works ^^
Still need help with detecting a redstone current though.
Lyqyd #5
Posted 21 September 2013 - 01:24 AM
For the redstone stuff, just take a look at the redstone API page on the wiki. You can use the setOutput and getInput methods in that API to output redstone and look at the inputs.

You can expand that by sending the message as whatever program you want to run. So to run adventure, you'd send "adventure" as the message, and the other end would have:


local id, message = rednet.receive()
shell.run(message)

Of course, that runs whatever it receives.