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

Rednet not working?

Started by Shinryuu, 03 September 2012 - 09:58 PM
Shinryuu #1
Posted 03 September 2012 - 11:58 PM
I have a turtle perma-mining with this code:


while true do
  os.queueEvent("randomEvent")
  os.pullEvent()
  i = 1
  shell.run("excavate","20")
  shell.run("turn","right","2")
  shell.run("go","up","1")
  shell.run("go","forward","5")
  rednet.broadcast("Mining Turtle Excavating Session Complete")
  slot = 1
  while slot < 10 do
	turtle.select(slot)
	turtle.drop()
	slot = slot + 1
  end
  shell.run("turn","right","2")
  shell.run("go","forward","5")
  shell.run("go","down","1")
end

and my receiving computer running:


while true do
  senderID, message, distance = rednet.receive()
  mon = peripheral.wrap("left")
  mon.print(message)
  mon.print("ID &amp; distance: ")
  mon.write(senderID)
  mon.write(", ")
  mon.write(distance)
  while s < 5 do
	rs.setInput("bottom",true)
	sleep(0.3)
	rs.setInput("bottom",false)
	sleep(0.1)
	s = s + 1
  end
end

but nothing happens when I broadcast the message, be it automatically by the turtle's code or with a command, so the receiver just hangs permanently. What am I doing wrong? The turtle is wireless and the receiver console has a modem, and the distance is short. I tried with rednet.send too and also pullEvent.
Lyqyd #2
Posted 04 September 2012 - 12:57 AM
Have you made sure to call rednet.open("side"), changing side to the side of the modem, before attempting to send or receive messages via rednet?
BigSHinyToys #3
Posted 04 September 2012 - 01:02 AM
I have fixed your receiver. you will need to add a rednet.open("right") to the turtle script or ti will not be able to broadcast.

Spoiler

rednet.open("top") --  you have to turn on wifi for it to work.
mon = peripheral.wrap("left")
term.redirect(mon)
while true do
  senderID, message, distance = rednet.receive()
  print(message)
  print("ID &amp; distance: ")
  write(senderID)
  write(", ")
  print(distance)
  for i = 1,5 do
		rs.setOutput("bottom",true)
		sleep(0.3)
		rs.setOutput("bottom",false)
		sleep(0.1)
  end
end


you can use the wifi section of this to test that it is working
[CC_1.41] BENCH v1.3 multi porous testing utility