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

[Lua][Bug] Rednet jammed?

Started by kelevra.1337, 14 January 2013 - 05:13 AM
kelevra.1337 #1
Posted 14 January 2013 - 06:13 AM
Hey guys, kelevra here again,

i've got a bug in my skripts and i dont know what to do and i how to track it down any further.
The basic gist is, that a master pc sends out a calculated message via rednet and a standard skript should receive and process it.

The problem is now (and thats whats really wierd about this) that the 7th or so turtle doesnt receive anything at all. But the master pc can print out the message it should send and the skript is the same for every turtle.

I know its confusing but thats why i made a short little video to show the problem:

[media]http://www.youtube.com/watch?v=NsyRCSoeMuo[/media]


This is the part of the master skript thats responsible for sending the data:



function launchT()
rednet.open("right")
for i = 1, gridsize do
  for i = 1, 12 do
   a = turtle.getItemCount(i+4)
   b = b + a
   --print(B)/>/>/>
  end
  if (turtle.getItemCount(slot)) == 0 then
   slot = slot + 1
  end
  turtle.select(slot)
  for i = 1, 12 do
   c = turtle.getItemCount(i+4)
   d = d + c
   --print(B)/>/>/>
  end
  if d < gridsize then
   print("require more slaves!")
   break
  end
  turtle.place()
  peripheral.call("front","turnOn")
  id, message = rednet.receive()

  print("message incoming")

  rednet.send(id,tostring(targetPos[idpos]["tx"]))
  rednet.send(id,tostring(targetPos[idpos]["ty"]))
  rednet.send(id,tostring(targetPos[idpos]["tz"]))
  rednet.send(id,tostring(dirdata["dir"]))
  rednet.send(id,tostring(dirdata["tdir"]))


  print("data sent to: "..idpos)
  print("")
  idpos = idpos + 1
  sleep(1.5)
end
rednet.close("right")
end


and this is the part of the slave skript responsible for receiving the data:


function receiveData()
print("receiving data from master "..mID)
rednet.send(mID, "im ready for launch")

id, tx = rednet.receive()
id, ty = rednet.receive()
id, tz = rednet.receive()
id, dir = rednet.receive()
id, tdir = rednet.receive()


gdata["tx"] = tonumber(tx)
gdata["ty"] = tonumber(ty)
gdata["tz"] = tonumber(tz)
gdata["tdir"] = tonumber(tdir)
dirdata["dir"] = tonumber(dir)
print(gdata["tx"])
print(gdata["ty"])
print(gdata["tz"])
print(gdata["tdir"])
mapi.saveData(gdata,"gstate")
print("saved gridposition")
mapi.saveData(dirdata,"dir")
return gdata
end

If you have any idea why this bug happens every time and in multiple test world please let me know, i would really like to finally finish this project and maybe publish it if its good enough
Thanks and Greetings from germany :)/>
imef #2
Posted 14 January 2013 - 06:47 AM
My guess is that the turtles which don't receive the data are too far from the master PC. Modems only send messages to computers which are within a certain radius. The higher the computer, the greater the radius. The minimum range is 64 blocks and the max is 384.

What I recommend you should do is to make a rednet relay. I don't have any code for that but basically the relay receives a message and transmits it to another.
kelevra.1337 #3
Posted 14 January 2013 - 07:06 AM
they receive the data all at the same position, at the same distance from the master pc, its all just really weird….
imef #4
Posted 14 January 2013 - 09:47 AM
The video is set to private. If you set it to public I'll be able to see the setup and maybe see where the problem is.
kelevra.1337 #5
Posted 14 January 2013 - 10:01 AM
oh sorry, i thought you could access private video via the link….. but its fixed now
ChunLing #6
Posted 14 January 2013 - 01:04 PM
Did you check out that error, moto 50, arithmetic on number and nil?
kelevra.1337 #7
Posted 14 January 2013 - 01:26 PM
Yeah the skript uses the data the turtle should receive, so its an just an error caused by the problem, not the problem itself
ChunLing #8
Posted 15 January 2013 - 06:38 AM
If the turtle wasn't receiving anything, it would just hang. It's probably receiving a spurious rednet from somewhere. Since you aren't doing any kind of filtering to ensure that all the rednet messages come from the master controller, that would mess things up pretty good.

Put a rednet logger (something that just receives and prints all rednet traffic) nearby to see if there are any broadcasts coming in (if you have any of the turtles using gps, the PING they send could be the culprit). Also, have the turtles print out each recieved message before it gets changed into a number.
kelevra.1337 #9
Posted 15 January 2013 - 07:13 AM
wow that was really the problem, they get jammed because of the a "ping" message. i did some research and it seems like the gps api brodcasts a ping every time it gets the location. I'll make a little filter like you said, huge thanks to you!
kelevra.1337 #10
Posted 15 January 2013 - 07:29 AM
ok, got it working now:


  while true do
   rednet.send(id,tostring(targetPos[idpos]["tx"]))
   rednet.send(id,tostring(targetPos[idpos]["ty"]))
   rednet.send(id,tostring(targetPos[idpos]["tz"]))
   rednet.send(id,tostring(dirdata["dir"]))
   rednet.send(id,tostring(dirdata["tdir"]))
   id, message = rednet.receive()
   if message == "yo" then
    break
   end
  end



while true do
  id1, tx = rednet.receive()
  id2, ty = rednet.receive()
  id3, tz = rednet.receive()
  id4, dir = rednet.receive()
  id5, tdir = rednet.receive()
  if id1 and id2 and id3 and id4 and id5 == mID then
   rednet.send(mID, "yo")
   break
  else
   rednet.send(mID, "no")
  end
end


I know its not the prettiest solution but it works, may change it later.
And again, huge Thanks for the suggestion!
ChunLing #11
Posted 15 January 2013 - 05:55 PM
Yeah, that's not pretty. It let's a single spurious message mess up all the rest of your messages, requiring a resync/resend. If you wrote a small function for a filtered receive, you could use that instead:
function filter(rmID)
	while true do
		local id,msg = rednet.receive()
		if rmID == id then return msg end
	end
end
Then get the messages by saying tx = filter(mID) and so on.

It's also a good (if time consuming) idea to create an alternate gps.locate function that doesn't broadcast the PING but just sends it to a list of GPS servers. Eventually, if they ever do get rid of (or downgrade) broadcast the way some were suggesting, that might be built in.

Hah, missed an end.
Edited on 15 January 2013 - 04:56 PM
Cloudy #12
Posted 16 January 2013 - 01:12 AM
That wouldn't work. You'd have to account for every gps transmitter in the world manually.
kelevra.1337 #13
Posted 16 January 2013 - 05:29 AM
Thanks again, ill use that. I really like that it doesnt need any sync what so ever that makes things much easier in the future.
ChunLing #14
Posted 16 January 2013 - 05:53 AM
Huh? In this case we only care about messages from the one transmitter, we're just throwing away everything else. Why would we have to account for the transmitters we're explicitly trying to ignore?

Eh, I was wondering what Cloudy was talking about. I open a bunch of tabs at once and then close them one by one, so it doesn't even take a ninja to ninja me.
Edited on 16 January 2013 - 04:55 AM