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

[API]Remote Control

Started by PoLoMoTo, 05 September 2012 - 11:12 PM
PoLoMoTo #1
Posted 06 September 2012 - 01:12 AM
The API will allow you to remotely control a turtle or computer. It's a pretty simple code and I didn't check if anyone has made something similar but I know this helped me so I decided to see if it would help anyone else :D/>/>

Functions:
rc.openTurtle(controller)
–This will open a turtle to receiving commands, it is highly recommended to specify the controlling computer's id.
rc.openComputer(controller)
–Basically the same as rc.openTurtle() except you are not limited to turtle functions.
rc.turtle(id,command)
–This will send a command to a turtle for it to carry out (Will only do turtle functions e.g. rc.turtle(24,forward))
rc.computer(id,command)
–Will send anything to a computer/turtle and that computer/turtle will run it

I have been made aware of ways to hack the turtle with rc.turtle which is why specifying a controller computer is highly recommended.

Note: A rednet modem needs to be open

Feedback is welcome :P/>/>

Download
http://www.mediafire...zfjlji2h8toozst

Simply put the rc file in the API folder.
KaoS #2
Posted 06 September 2012 - 07:28 AM
nice idea, I made something similar myself, you should try make another command that you can specify a file with and it sends it across to be executed as a program. very useful
PoLoMoTo #3
Posted 06 September 2012 - 03:13 PM
Thanks, I don't think there's a real way to send a program over rednet but I'm sure I can rig something up. I also need to figure out how to get the turtles output to be sent back to the computer for detect and getFuelLevel etc
Cranium #4
Posted 06 September 2012 - 03:47 PM
Sure you can. Just read the program files, and for each line, send via rednet, and have it write each line as it receives.
PoLoMoTo #5
Posted 06 September 2012 - 03:59 PM
Sure you can. Just read the program files, and for each line, send via rednet, and have it write each line as it receives.

Yes but you have to make sure the receiver is ready to process the entire thing, shouldn't be too hard though, it'll just be another small function
KaoS #6
Posted 07 September 2012 - 11:59 AM
just do this

function sendFile(id, name)
local cAll=''
if fs.exists(name) then
  local file=io.open(name)
  while true do
   local cLine=file:readLine()
   if not cLine then
    break
   end
   cAll=cAll..' '..cLine
  end
  rednet.send(id, cAll)
end
end

and then loadstring it on the other side or write it to a file

and why do you have to rig that up? you can just tell it to send the input back when you send it commands (that's how I do it in my swarm - http://www.computercraft.info/forums2/index.php?/topic/3884-a-project-i-did-yesterday-after-work-opinions/)

use

command='rednet.send('..os.computerID()..','..command..')'

if the variable command is what you send the other computers to execute