11 posts
Location
Belgium
Posted 08 June 2012 - 06:03 PM
Hello crafters,
I'm trying to make one computer reply as soon as it has received a Rednet message. I hope to extend this system to make a small intranet on our SMP server.
My computer setup:
Spoiler
The computer on the left runs the program
receivertest.
The computer on the right runs the program
sendertest.
Console output of the receiving computer at the left:
Spoiler
Console output of the sending computer at the right:
Spoiler
As you can see, the right computer at the right successfully broadcasts a message to the left computer. This computer then sends a reply, but this doesn't seem to reach the right computer.
When I replace the bundled RedPower cables with wireless modems, it works perfectly. However, I'd rather not put a repeater computer every 17 meters just to make two computers communicate over long distances.
Any ideas?
1604 posts
Posted 08 June 2012 - 06:19 PM
The problem might be that using rednet over bundled cables is way too slow, so it times out. The soultion would be to increase the wait time, or use modems. I would recommend using modems, even if you have to set up some repeater system it would be faster. Just try to send a long message over bundle and see how long it takes to send it, that's because it sends each byte over the bundle. Modems send messages of any size instantly, so you could repeat the message through a lot of repeater computers and it would be faster than using cables.
992 posts
Posted 08 June 2012 - 06:34 PM
When I replace the bundled RedPower cables with wireless modems, it works perfectly. However, I'd rather not put a repeater computer every 17 meters just to make two computers communicate over long distances.
Any ideas?
the range of wifi in CC is 50 meters (blocks) so you would only need a repeater computer every 50 not 17. this range is also configurable so you could make it 100 or a 1000 if you wanted.
As for your code you can catch events with " os.pullEvent() " placed in a loop you can creat a computer program that will repete your signal example.
Spoiler
local side = "right"
rednet.open(side)
print("Waiting for message...")
while true do
event, id , message = os.pullEvent()
if event == "rednet_message" and message == "ping?" then
print("Recived message from "..id.." : "..message)
print("replying to "..id)
rednet.send(id,"Pong!") -- or rednet.broadcast(message)
end
if event == "char" and id == "q" then break end -- this line allows you to end the program by pressing "q"
end
this might be help full in testing
Spoiler
local function openRednet()
local listOfSides = { "top" , "bottom" , "front" , "left" , "right" , "back" }
local listofPossibles = {}
local counter1 = 0
while true do
counter1 = counter1 +1
if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
table.insert(listofPossibles,tostring(listOfSides[counter1]))
end
if counter1 == 6 and table.maxn(listofPossibles) == 0 then
print("no wifi present")
return nil
end
if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
rednet.open(listofPossibles[1])
return listofPossibles[1]
end
end
end
modemOn = openRednet()
if modemOn == nil then
print("No WIFI Modem")
print("Will shutdown in 3 seconds")
sleep(3)
os.shutdown()
else
print("Opened wifi on "..modemOn.." side")
end
write("ID: ")
id = tonumber(io.read())
write("Mesg: ")
mesg = io.read()
rednet.send(id,mesg)
print("Waiting for message...")
while true do
event, id , message = os.pullEvent()
if event == "rednet_message" then
print("Recived message from "..id.." : "..message)
end
if event == "char" and id == "q" then break end -- this line allows you to end the program by pressing "q"
end
8543 posts
Posted 08 June 2012 - 06:54 PM
The default range is actually 64 blocks.
11 posts
Location
Belgium
Posted 08 June 2012 - 06:58 PM
The problem might be that using rednet over bundled cables is way too slow, so it times out. The soultion would be to increase the wait time, or use modems. I would recommend using modems, even if you have to set up some repeater system it would be faster. Just try to send a long message over bundle and see how long it takes to send it, that's because it sends each byte over the bundle. Modems send messages of any size instantly, so you could repeat the message through a lot of repeater computers and it would be faster than using cables.
We did some tests and it seems like the first message takes about a second to send whereas our timeout is set to five seconds. The second message is about the same size, so it should take about the same time to send, right? Anyhow, we did try to increase the timeout to ten seconds, to no avail.
the range of wifi in CC is 50 meters (blocks) so you would only need a repeater computer every 50 not 17. this range is also configurable so you could make it 100 or a 1000 if you wanted.
According to the wiki, the range is 64 meters by default and decreases to 17 meters in a thunderstorm. If I'd want my system to work in all conditions, I'd need to place one every 17 blocks. Surely, I could ask the server admin to increase the range but that would be like cheating the question, right? :)/>/>
I'll probably go with the modem/repeater solution: they're faster and cheaper than bundled cables. Still, as an engineer I'm intrigued by this problem and I'd like to know if it is possible to do this with bundled cables. If anyone has a solution or an explanation for this, do share please!
992 posts
Posted 08 June 2012 - 07:15 PM
you are right storm do cause a range decrease and it is 64 blocks. This has never been a real problem form me so far.The bundled cable is not capable of fast speeds due to it relying on Redstone (sorta). it should be possible all be it more work to make a program that breaks a message down and sends it over a cable before assembling it at the ther end. you should look at the rednet api if you want to know how it works.
this is a set of programs i made when i first started using CC before modems. it is a extreamly basic 4 bit sender down a single redstone line (not bundle)
sender
Spoiler
while true do
side = "back"
print ("Enter number between 0 - 15")
invar = tonumber(io.read())
dat1 = 0
dat2 = 0
dat3 = 0
dat4 = 0
if invar >= 8 then
print (invar)
dat4 = 1
invar = invar -8
end
if invar >= 4 then
print (invar)
dat3 = 1
invar = invar -4
end
if invar >= 2 then
print (invar)
dat2 = 1
invar = invar -2
end
if invar == 1 then
print (invar)
dat1 = 1
end
print (dat1..dat2..dat3..dat4)
print ("sending data")
rs.setOutput (side, true)
sleep (0.1)
if dat1 == 1 then
rs.setOutput (side, true)
sleep (0.2)
else
rs.setOutput (side, false)
sleep (0.2)
end
if dat2 == 1 then
rs.setOutput (side, true)
sleep (0.2)
else
rs.setOutput (side, false)
sleep (0.2)
end
if dat3 == 1 then
rs.setOutput (side, true)
sleep (0.2)
else
rs.setOutput (side, false)
sleep (0.2)
end
if dat4 == 1 then
rs.setOutput (side, true)
sleep (0.2)
else
rs.setOutput (side, false)
sleep (0.2)
end
rs.setOutput (side, false)
print ("end of transmition")
end
reciver
Spoiler
side = "right"
while true do
event, pram = os.pullEvent()
if event == "char" and pram == "q" then break
end
total2 = 0
dat1 = 0
dat2 = 0
dat3 = 0
dat4 = 0
if event ~= "redstone" then
pased = true
print (pased)
else
print ("incoming transmition")
sleep (0.2)
if rs.getInput (side) == true then dat1 = 1
total2 = total2 +1
end
sleep (0.2)
if rs.getInput (side) == true then dat2 = 1
total2 = total2 +2
end
sleep (0.2)
if rs.getInput (side) == true then dat3 = 1
total2 = total2 +4
end
sleep (0.2)
if rs.getInput (side) == true then dat4 = 1
total2 = total2 +8
end
print (dat1..dat2..dat3..dat4.." "..total2)
sleep (0.2)
end
end
if that could be duplicated for each one of the 16 cables in a bundle you would have speeds of 40 bit's per second. that is extremely slow compared to wifi
11 posts
Location
Belgium
Posted 08 June 2012 - 07:35 PM
you are right storm do cause a range decrease and it is 64 blocks. This has never been a real problem form me so far.The bundled cable is not capable of fast speeds due to it relying on Redstone (sorta). it should be possible all be it more work to make a program that breaks a message down and sends it over a cable before assembling it at the ther end. you should look at the rednet api if you want to know how it works.
Agreed, redstone is slower than modems. Still, a simple test shows that the short message I'm sending takes about a second to send. Even though it's slower, it should still be able to receive the message before timing out.
this is a set of programs i made when i first started using CC before modems. it is a extreamly basic 4 bit sender down a single redstone line (not bundle)
if that could be duplicated for each one of the 16 cables in a bundle you would have speeds of 40 bit's per second. that is extremely slow compared to wifi
I checked the code of the Rednet API and it sort of does that. By default, it sends and receives at a clock rate of 15 Hz which means that it can send 15 packets of 16 bits per second, resulting in a net transfer rate of 240 bps. When using a modem, it simply passes the whole message in one go to the modem, hence the instant transfer.
Also, your code could be greatly simplified with bitwise operations. Just sayin'. :)/>/>So really, I'm not looking into finding a replacement for the Rednet API. I just want to know why the reply doesn't get through.
992 posts
Posted 08 June 2012 - 07:49 PM
that code was made a long time ago i know there is huge room for simplification. as for bit wise operations, lua 5.1 witch juaj is based on and cc uses does not support them.
http://www.lua.org/manual/5.1/http://www.lua.org/manual/5.2/ http://luaj.org/luaj/README.html
1604 posts
Posted 08 June 2012 - 09:20 PM
that code was made a long time ago i know there is huge room for simplification. as for bit wise operations, lua 5.1 witch juaj is based on and cc uses does not support them.
http://www.lua.org/manual/5.1/http://www.lua.org/manual/5.2/http://luaj.org/luaj/README.html
That's why there's a bit api in CraftOS :)/>/>