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

How to send a command over rednet to another computer and tell the 2nd computer to run the program and control it from the 1st computer

Started by pig101z, 12 May 2013 - 11:26 AM
pig101z #1
Posted 12 May 2013 - 01:26 PM
this is for a wireless ICBM mod launch program made to launch missiles and control all launchers from a computer but I need to be able to tell the program to to do other things basically control another computer from another thanks
Calimore #2
Posted 12 May 2013 - 01:43 PM
I am a newbie to ComputerCraft (see my post count :P/>), but I guess there's no out-of-the-box solution for this. You will need to write a client and a server side of the software you need.

The server side would have some sort of GUI/Menu and send commands to the clients. The client itself would then have to listen for those messages, interpret them and call some of the client side functions (like in your case launch a missile or something) and maybe even give feedback to the master computer.

I guess most of the work you have ahead of you is developing some sort of simple protocol for the communication between your master and the slave computers.

I hope this answer wasn't to theoretical and it for sure wasn't a CC Pro reply… Anyway mabe this points you in the right direction…
pig101z #3
Posted 12 May 2013 - 02:02 PM
I already have a program I just need to tell it to run it because i know i need to do rednet.broadcast and then I need to broadcast the program run command to another computer actually to about 12 computers at one time and with as little typing as possible so i can quickly launch in a emergancy
Spongy141 #4
Posted 12 May 2013 - 02:18 PM
For receiving comp

C = '20'  --replace with the computer id that is sending the command
while true do --So it will loop
  id, cmd = rednet.receive()
  if id == C then  --So you it wont do anything unless the id matches
	 if cmd == 'Launch 1' then -- Customize the commands here... this is just an example
		rs.setOutput('back', true) --Change the side to what ever side you want... if you don't know, this will set a redstone current, which you need when launching a missile (In ICBM)
		sleep(0.1)
		rs.setOutput('back', false)
	 end
  end
end
pig101z #5
Posted 12 May 2013 - 05:18 PM
this is my program that I need to do it this program works just fine but I need to send it over rednet to have another computer run it with
local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
local silos = {}
local argv = {...}
local selected = 1
local color = {"silver"}
for i,v in pairs(colors) do
if i ~= "combine" and i ~= "subtract" and i ~= "test" and i ~= "lightGray" then
  table.insert(color, i)
end
end
print("Detecting silos...")
for i,side in ipairs(rs.getSides()) do
if argv[1] == "--debug" then
  print("Checking: "..side)
end
if peripheral.getType(side) == "cable" then
  if argv[1] == "--debug" then
   print("Found a peripheral cable.")
  end
  for i2, color in ipairs(color) do
   if argv[1] == "--debug" then
	print("Checking: "..side..":"..color)
   end
   if peripheral.getType(side..":"..color) == "ICBMLauncher" then
	print("Silo found on side:"..side..":"..color)
	table.insert(silos, {side..":"..color, peripheral.wrap(side..":"..color)})
   end
  end
elseif peripheral.getType(side) == "ICBMLauncher" then
  print("Silo found on side:"..side)
  table.insert(silos, {side, peripheral.wrap(side)})
end
end
if #silos == 0 then
print("No silos detected.")
print("Please place a launcher control panel next to the computer.")
	os.sleep(2)
return
elseif #silos == 1 then
print("Found 1 silo.")
else
print("Found "..#silos.." silos.")
end
os.sleep(0.75)
local function getPW()
if fs.exists("launchCode") then
  term.clear()
  term.setCursorPos(5, 8)
  write("Please enter a launch code.")
  local handle = fs.open("launchCode", "r")
  local code = handle.readAll()
  handle.close()
  local userPW = read()
  term.clear()
  term.setCursorPos(1,1)
  return (code == userPW)
else
  return true
end
end
local function printColored(...)
for i=1, arg["n"] do
  if type(arg[i]) == "string" then
   write(arg[i])
  elseif type(arg[i]) == "number" then
   if term.isColor() then
	term.setTextColor(arg[i])
   end
  end
  
end
print("")
term.setTextColor(colors.white)
end
local function doCountdown(length)
for i=length, 1, -1 do
  term.clear()
  term.setCursorPos(12,9)
  write("Launching in: "..i.." seconds...")
  term.setCursorPos(3,10)
  write("Press any key (except escape) to abort launch.")
  local timer = os.startTimer(1)
  while true do
   local event, id = os.pullEvent()
   if event == "key" then
	if id ~= 1 then
	 term.setCursorPos(17,11)
	 write("Aborting launch!")
	 os.sleep(0.5)
	 return false
	end
   elseif event == "timer" then
	if id == timer then
	 break
	end
   end
  end
end
return true
end
while true do
term.clear()
term.setCursorPos(1,1)
printColored(colors.white, "Silo ", colors.lime, tostring(selected), colors.white, " selected.")
print("")
print("Details: ")
print("")
printColored("Frequency: ", colors.lime, tostring(silos[selected][2].getFrequency()))
local targetX, targetY, targetZ = silos[selected][2].getTarget()
print("Targeted: ")
printColored("X: ", colors.lime, tostring(targetX))
printColored("Y: ", colors.lime, tostring(targetY))
printColored("Z: ", colors.lime, tostring(targetZ))
print("")
print("Options: ")
printColored("1. ", colors.lime, "Select Silo")
printColored("2. ", colors.orange, "Set Silo Target")
printColored("3. ", colors.orange, "Set Silo Frequency")
printColored("4. ", colors.red, "Launch")
printColored("5. ", colors.red, "Launch All")
printColored("6. ", colors.orange, "Set All Silo Frequencies")
printColored("7. ", colors.orange, "Set All Silo Targets")
local event, key = os.pullEvent("key")
if key == 2 then
  term.clear()
  term.setCursorPos(1,1)
  print("Detected silos:")
  for i,v in ipairs(silos) do
   print(i..". Silo on: "..v[1].." side")
  end
  local x, y = term.getCursorPos()
  while true do
   term.setCursorPos(x,y)
   term.clearLine()
   write("Selection> ")
   local data = tonumber(read())
   if data then
	if silos[data] then
	 selected = data
	 break
	end
   end
  end
elseif key == 3 then
  local x, y, z = 0
  while true do
   term.setCursorPos(1,7)
   term.clearLine()
   write("X: ")
   local selX = read()
   if tonumber(selX) then
	x = tonumber(selX)
	break
   end
  end
  while true do
   term.setCursorPos(1,8)
   term.clearLine()
   write("Y: ")
   local selY = read()
   if tonumber(selY) then
	y = tonumber(selY)
	break
   end
  end
  while true do
   term.setCursorPos(1,9)
   term.clearLine()
   write("Z: ")
   local selZ = read()
   if tonumber(selZ) then
	z = tonumber(selZ)
	break
   end
  end
  silos[selected][2].setTarget(x,y,z)
elseif key == 4 then
  while true do
   term.setCursorPos(1,5)
   term.clearLine()
   write("Frequency: ")
   local selFreq = read()
   if tonumber(selFreq) then
	silos[selected][2].setFrequency(tonumber(selFreq))
	break
   end
  end
elseif key == 5 then
  if getPW() then
   if doCountdown(10) then
	silos[selected][2].launch()
   end
  else
   term.clear()
   term.setCursorPos(12,9)
   print("Incorrect code!")
   os.sleep(2)
  end
elseif key == 6 then
  if getPW() then
   if doCountdown(10) then
	for i,v in ipairs(silos) do
	 v[2].launch()
	 os.sleep(3)
	end
   end
  else
   term.clear()
   term.setCursorPos(12,9)
   print("Incorrect code!")
   os.sleep(2)
  end
elseif key == 7 then
  while true do
   term.setCursorPos(1,5)
   term.clearLine()
   write("Frequency: ")
   local selFreq = read()
   if tonumber(selFreq) then
	for i,v in ipairs(silos) do
	 v[2].setFrequency(tonumber(selFreq))
	end
	break
   end
  end
elseif key == 8 then
  local x, y, z = 0
  while true do
   term.setCursorPos(1,7)
   term.clearLine()
   write("X: ")
   local selX = read()
   if tonumber(selX) then
	x = tonumber(selX)
	break
   end
  end
  while true do
   term.setCursorPos(1,8)
   term.clearLine()
   write("Y: ")
   local selY = read()
   if tonumber(selY) then
	y = tonumber(selY)
	break
   end
  end
  while true do
   term.setCursorPos(1,9)
   term.clearLine()
   write("Z: ")
   local selZ = read()
   if tonumber(selZ) then
	z = tonumber(selZ)
	break
   end
  end
  for i,v in ipairs(silos) do
   v[2].setTarget(x,y,z)
  end
end
end
os.pullEvent = oldPull
pig101z #6
Posted 12 May 2013 - 06:23 PM
please help
sploders101 #7
Posted 12 May 2013 - 08:29 PM
os.pullEvent() works like this: event, arg1, arg2, arg3, and so on. you forgot the parinthesis and you need more variables before it

(At least 2)
Edited on 12 May 2013 - 06:29 PM
pig101z #8
Posted 12 May 2013 - 09:11 PM
I said it works just fine I need to send it to another computer over rednet and tell it to run it and I have no previous coding experience
Spongy141 #9
Posted 13 May 2013 - 12:50 AM
Please use [*code] [*/code] when you post code…. and if its over 75 lines, do [*spoiler] [*/spoiler] without the * of course.
And you realize how easy rednet is right? Here's an example to send a user input over rednet, then having the receiving comp do something with it.

rednet.open('top') --This opens the top modem...
term.write('Code: ')
local cmd = read()
rednet.broadcast(cmd)  --this will broadcast the message in all directions... any computer with rednet.receive() will get the command
--This will be the receiving comp... you CAN NOT use just one comp.
rednet.open('top') --Again... this opens the modem
cSender = '20' --Id of the sender, so it will ONLY use the command if the id matches..
id, cmd = rednet.receive()
if id == cSender then
  --Do stuff here.
end
Rednet is simple… so it shouldn't be hard to make the program yourself.
BigSHinyToys #10
Posted 13 May 2013 - 01:41 AM
You cant push a program to a computer remotely that is impossible without having a program running on that system to receive it first . I think what you want is to name your program "startup" then it will be run when miencraft loads and you will be able to access it over rednet. the computer must be in a loaded chunk for that to work so add a chunk loader or be near it.
jeroentjuh99 #11
Posted 13 May 2013 - 04:28 AM
Receiving computer/turtle

rednet.open("right")
while true do
  senderID, message, distance = rednet.receive()
  print(message)
  shell.run(message)
end

Sending computer/turtle

rednet.open("right")
rednet.send(1, "The program name on your receiving computer/turtle")
pig101z #12
Posted 13 May 2013 - 03:42 PM
ok I need to control computer 2 from computer 1 and tell it to run a specific program then I know I need to do rednet.broadcast to send a message to all my computers and tell them to run a program and then tell them to run command 5 by sending the number 5 can I just send shell.run(missile_silo_control) "the name of my program is missile silo control" and the computer will run the program
pig101z #13
Posted 13 May 2013 - 06:13 PM
I need help please
Spongy141 #14
Posted 14 May 2013 - 12:30 AM
I need help please
Look, were trying to help you, if you do not try what we tell you, you will never get it to work, stop saying 'I need help please' we get it, and every-time we help you, it seems you do not even bother to look at it… that's your fault, not ours. And if you bother to read this, here's how to do what you wanted…

--Sender
rednet.open('top') --Replace the side 'top' with the modem side...
rednet.broadcast(id,'missile_silo_control')

--ALL THE OTHER COMPS
rednet.open('top') --Same as 'Sender'
Control = '20'  --REPLACE 20 WITH THE ID OF YOUR CONTROL COMP... THIS WILL INSURE PROTECTION
id, msg = rednet.receive()
if id == Control then
  shell.run(msg)
end
Spongy141 #15
Posted 14 May 2013 - 10:00 AM
-snip-
You'll find I like to be helpful, so even though you said that, I'll help you
– this marks the start of a code comment, it will only use one line. And can be at the end of a line of code.
I'm using rednet API in the program I made for you, you NEED two computers for this.
Take the code from line 2 - 3 and put it in your 'Control' Computer… were you will control the silos, exactly how you wanted…. I could add a GUI for you, but you didn't ask, so I didn't
Then take lines 6 - 11 and put it in your 'Silo' Computers, MAKE sure you have a rednet wireless modem the recipe is the enderpearl it used to be a redstone torch… not anymore though, UNLESS you are using computercraft below v.1.51, then the redstone torch WILL work.
If you want a nice GUI then just PM me, and I would be more than happy to make one.
Cranium #16
Posted 14 May 2013 - 10:38 AM
Try not to be rude to the people trying to help you. Everything that everyone is posting here is in one way or another trying to help you. I suggest you pay attention to them.
As to where you put this code, you need to put it in a program file. You can use the inbuilt edit program to do this, or you can edit your game files, in \world\computers\<computer ID>.
I've gone ahead and put your code in
 tags, but I recommend using them yourself in the future. It really helps us identify the issues easier.
As a personal note, I also recommend proper punctuation. It really turns people off when you post an entire paragraph without a single comma or period. Run-on sentences are not fun to read.
Don't be a dick on these forums, and you will have a much more pleasant time. Happy hacking!
pig101z #17
Posted 14 May 2013 - 05:22 PM
ok I will try what Spongy141 said and see if it works and cranium I don't care what you say so screw off , and spongy141 I did not mean to get mad but I have been having problems and I figured that people would not be ignorant on this forums so I was using video games as my little escape so thanks for all the help (this excludes you cranium) and I will see if this works
Spongy141 #18
Posted 14 May 2013 - 11:41 PM
ok I will try what Spongy141 said and see if it works and cranium I don't care what you say so screw off , and spongy141 I did not mean to get mad but I have been having problems and I figured that people would not be ignorant on this forums so I was using video games as my little escape so thanks for all the help (this excludes you cranium) and I will see if this works
… Its not the wises idea to be rude to a moderator… I kinda know Cranium, hes a nice guy, and was only trying to help you as well. Also, anything we say, try to read it with a positive attitude, on 'Ask a Pro' we try to not be rude to people asking the questions, so please do not take anything we say as rude (unless you can clearly see its rude, such as someone calling you a rude name and such).
But on to topic, make sure to post exactly what happens, if you need further help, such as how to get the program to install on to your computers, just say, or if you are on a server, then I can always help you even better (I think you can get the point on what I mean).
pig101z #19
Posted 15 May 2013 - 04:06 PM
ok so if you read my other post called how to send a message over rednet in there is a guy called woody and his program is what I need you to look at. and I need someone to read my posts and tell me if what I am asking is possible

and how to do it
Spongy141 #20
Posted 15 May 2013 - 06:04 PM
ok so if you read my other post called how to send a message over rednet in there is a guy called woody and his program is what I need you to look at. and I need someone to read my posts and tell me if what I am asking is possible

and how to do it
Just PM me your question, it would be the easiest way for me to help, since it would take longer for me to search through your posts.