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

Communications & Range Test Kit

Started by lebalusch, 25 May 2015 - 08:56 PM
lebalusch #1
Posted 25 May 2015 - 10:56 PM
Hi Guys and Girls,

Here is a little two part project I done this bank holiday weekend that might help some new starters to scripting. Its designed to work on a computer and/or advanced computer, so its text based but still gets the job done.

So as stated there are two parts You can call them what you want i have just called them ears and mouth for ease of use:

Communications Test Listener http://pastebin.com/Ju9Lgy7R In Game: pastebin get Ju9Lgy7R ears
Alpha 1.0
Spoiler
[

– Code for updater to go here.
–[[info]]
–[[
– Program: communication Tester Listener http://pastebin.com/Ju9Lgy7R
– Version: v1.0 Alpha
– Size: 3.0 KB
– Author: Leba Lusch
– Created: 25/05/15
– Dependencies: yes
Communications Tester Broadcaster http://pastebin.com/hAHtp36n
link :
– Use:
Tests communications capacity of your wireless / wired network. Can be used to Test the range suitability.
This script does the listening. It will tell you the distance to the computer running the Broadcaster script as well as other useful info.

I have tried to make as many needed comments in the script to help people that want to learn.

– Credits:

All those that have Created and contributed to making Lua & Computercraft what it is today.


–Links:

http://www.lua.org/
http://www.computercraft.info/
http://www.computercraft.info/forum2
http://www.minecraft.net
]]
–[[Licence]]
–[[
THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

YOU MAY NOT USE ANY PART OF THIS SOFTWARE UNLESS YOU CREDIT THE AUTHOR FOUND ABOVE IN YOUR HEADER.
YOU MAY NOT USE ANY PART OF THIS SOFTWARE IN A COMERCIAL PRODUCT FOR PROFIT,
OR SOFTWARE THAT DOES NOT ALLOW THE USER FULL ACCESS TO THE CODE.

]]

local programName = "Communication Tester Listener v1.0 Alpha"
local modem = peripheral.wrap("top")

local function newPage()– clears page and sets cursor to top left of page (works)
term.clear()
term.setCursorPos(1,1)
write(programName)
write("\n") –new line
end

function ASK()

print("Program Started…\n")
print("\n Please make sure your modem is on the top of your pc\nor this can be changed in the script")
print("Also set the broadcaster up first on the other PC")
print("\nWhat Channel should I listen to 1 to 65535:\n")
local RX =tonumber(read())
whatChan = RX
modem.open(RX)

end

–code
modem.closeAll()
newPage()
ASK()

while true do –The loop
newPage()
print ("\nNow listening channel "..whatChan)
local event, modemSide, senderChannel,
replyChannel, message, senderDistance = os.pullEvent("modem_message")

print("\n\nI just received a message from Channel: "..senderChannel)
print("I should apparently reply on Channel: "..replyChannel)
print("The modem receiving this is located on the "..modemSide.." side")
print("The message was: "..message)
print("The sender is: "..senderDistance.." blocks away from me.")
sleep(10)
print("To exit you can ctrl + T out")
sleep(1)
print("\nResetting Listener—")
sleep(5)
end
Communications Test Broadcaster http://pastebin.com/hAHtp36n In Game: pastebin get hAHtp36n mouth
Alpha 1.1
Spoiler[
– Code for updater to go here.
–[[info]]
–[[
– Program: communication Tester Broadcaster
– Version: v1.1 Alpha
– Author: Leba Lusch
– Created: 25/05/15
– Dependencies: yes
Communications Tester Listener
link :
– Use:
Tests communications capacity of your wireless / wired network. Can be used to Test the range suitability.
This script does the broadcasting. It will give you a few options to set up or just use the present ones.
All this can be set in running program it will give you a summery of useful information.
Set this one up first


I have tried to make as many needed comments in the script to help people that want to learn.

– Credits:

All those that have Created and contributed to making Lua & Computercraft what it is today.


–Links:

http://www.lua.org/
http://www.computercraft.info/
http://www.computercraft.info/forum2
http://www.minecraft.net
]]
–[[Licence]]
–[[
THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

YOU MAY NOT USE ANY PART OF THIS SOFTWARE UNLESS YOU CREDIT THE AUTHOR FOUND ABOVE IN YOUR HEADER.
YOU MAY NOT USE ANY PART OF THIS SOFTWARE IN A COMERCIAL PRODUCT FOR PROFIT,
OR SOFTWARE THAT DOES NOT ALLOW THE USER FULL ACCESS TO THE CODE.

]]

local programName = "Communication Tester v1.1 Alpha"

– programmed in pre-sets. change to what you want them to be for pre-set option.

local emitCH = "3"
local retCH = "6"
local message = "\nHello world" – \n is for new line.
local modem = peripheral.wrap("top") –what side of the PC your modem is on.
local myDelay = "10" – delay between messages

–functions

local function newPage()– clears page and sets cursor to top left of page (works)
term.clear()
term.setCursorPos(1,1)
write(programName)
write("\n") –new line
end


local function YEPnope()
local response = read()
– you will need to ask a yes or no question before passing to response

local Y1,Y2,Y3,Y4,Y5 ="Y", "y", "yes","Yes", "YES"
local N1,N2,N3,N4,N5="N", "n", "no", "No", "NO"

– for the no's
if response ==N1 then
myChoice() –activate this function
end

if response ==N2 then
myChoice() –activate this function
end

if response ==N3 then
myChoice() –activate this function
end

if response ==N4 then
myChoice() –activate this function
end

if response ==N5 then
myChoice() –activate this function
end

–for the yes's. Pre-sets are top of program and already loaded in.
if response ==Y1 then
end

if response ==Y2 then
end

if response ==Y3 then
end

if response ==Y4 then
end

if response ==Y5 then
end
end




function myChoice()

sleep(1)
newPage()
write("\n-Do Not Use The Same channel \nfor your InPort and OutPort-")
write("\n\nPlease state the OutPort channel. 1 to 65535 :\n ")
emitCH = read()

write("\nPlease state the InPort channel. 1 to 65535 :\n ")
retCH = read()
sleep(1)

– compare selections for ports,reject if the same

if emitCH == retCH then
write("\nYou Have selected the Same ports this is not allowed")
sleep(5)
emitCH= 1
retCH=2
myChoice()
end

write("\n\nPlease state the message to send on repeat :\n ")
message= read()

newPage()

write("\n-Warning low delay values can cause problems-")
write("\nPlease state the Delay between messages : ")
myDelay= read()

findModem()
end

function findModem() – this is broke needs fixing.

write("\n\n-Sides available are:\nfront, back, left, right, top or bottom.")
write("\nPlease state the side the wireless modem \nis connected to: ")
local modemSide= read()

if modemSide == "front" then
modem = peripheral.wrap(modemSide)


elseif modemSide == "back" then
modem = peripheral.wrap(modemSide)


elseif modemSide == "left" then
modem = peripheral.wrap(modemSide)


elseif modemSide == "right" then
modem = peripheral.wrap(modemSide)


elseif modemSide == "top" then
modem = peripheral.wrap(modemSide)


elseif modemSide == "bottom" then
modem = peripheral.wrap(modemSide)

else
write("\nThat was not an option please type it as stated")
findModem()
end
end



function summery()–works (all text is being displayed as text not numbers)
newPage()
sleep(2)
write("\nSummery of Set up: \n\n")

write("\nOpening Channel: ")write(emitCH)
write("\nOpening Channel: ")write(retCH)

TX = tonumber(emitCH)
RX = tonumber(retCH)
modem.open(TX,RX)

write(" \nTransmitting on Channel: ")write(emitCH)
write(" \nReciving on Channel: ")write(retCH)
write(" \nDelay time for loop of message set to: ")write(myDelay)
write("\n \n message being sent: \n")write(message)

end


local function startSend()

while true do – loops message
modem.transmit (tonumber(emitCH),tonumber(retCH), message)
sleep(tonumber(myDelay))–Recommend about 10 sec so as not to spam to fast. Can cause problem if set to quick.

end
end

–code
–modem.closeAll()
newPage()

write("Program Started…\n")

write("\n\nWould you like to use the program \npresents Y/ N :")


YEPnope()
summery()
startSend()

Using These two scripts you can find out if your cabled network is working between point a and b. the same with the wireless modem. It will even tell you the cable length for a hard wired network. The wireless modem set up will tell you as the crow flys block distance. I guess you could use the Communications test Listener as a basic snooping device although play nice.


Updates:
Broadcaster program fix issued. alpha 1.1:
This addresses Known bug 1. and part fixes it so that it will now activate what ever side your modem is on that you have specified.

Known Bugs:
  • Please use only the top for the modems, while there are options to select the side you are using its not working right due to the pre-sets. if you want to use a different side feel free to edit the pre-sets before running. Method suggested for a fix in Ask a pro user by member Lyqyd
  • The broadcaster does not check that the side you have stated the modem is on is true. Fix in the pipe line for this using method suggested bellow by flaghacker

Thank you for stopping by this page and constructive help gratefully appreciated. Feed back below or direct message. Have fun :D/>
Edited on 31 May 2015 - 03:52 PM
flaghacker #2
Posted 26 May 2015 - 11:47 AM
Cant this stuuf be shortened to:

Computer1:

>lua
>rednet.open("back")
>os.pullEvent("rednet_message")

Computer2:

>lua
>rednet.open("back")
>rednet.broadcast("Hello world!")

Could still be usefull to some…

Edit: code is only usefull without typo's
Edited on 26 May 2015 - 09:48 AM
lebalusch #3
Posted 26 May 2015 - 09:05 PM
SpoilerCant this stuuf be shortened to:

Computer1:

>lua
>rednet.open("back")
>os.pullEvent("rednet_message")

Computer2:

>lua
>rednet.open("back")
>rednet.broadcast("Hello world!")

Could still be usefull to some…

Edit: code is only usefull without typo's

You could shorten it to a very basic program yes but where is the fun in that?! i was using it as a learning tool for myself and also hopefully others to see how areas of it work.. I have tried to add a little depth to it and a bit more features. Being a bit of an experienced user would you care to have a go at fixing the break mentioned above in the script please?
Edited on 26 May 2015 - 07:06 PM
flaghacker #4
Posted 26 May 2015 - 09:29 PM
If you're talking about the problem that the modem has to be on the top side, you can easily fix that using peripheral.find.

Replace your

modem = peripheral.wrap ("top")
with

modem = peripheral.find ("modem")
. If that's not your problem, please clarify ;)/>

And I was not trying to be rude, I encourage you to keep learning and keep writing programs!
lebalusch #5
Posted 26 May 2015 - 11:04 PM
Thank you @flaghacker it wasn't taken as you being rude sorry if that's how it came across i will put your advice into action and give it a go.