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

Wireless Redstone Control

Started by Dunrana, 11 August 2015 - 03:18 PM
Dunrana #1
Posted 11 August 2015 - 05:18 PM
I'm trying to make a small program that will allow any computer with a wireless modem to send a redstone signal to a block, thus controlling its current state. I would like to be able to use modem equipped pocket computers, as well as regular computers to do this.For reference, it’s to control a laser lift from the newly updated warp drive mod.

The Non-running code I have so far is…


local modem = peripheral.wrap("left")
modem.open (5)

signal = "down"

if signal == "up" then
redstone.setOutput("right",true)
end

if signal == "down" then
redstone.setOutput("right",false)
end
Lyqyd #2
Posted 11 August 2015 - 07:17 PM
Moved to Ask a Pro.
CherryPie #3
Posted 11 August 2015 - 07:27 PM
rednet.open(SIDE)

rednet.send(ID, MESSAGE)

Is the code you might look into

Like this:


rednet.open("right")
if SOMETHING then
	 rednet.send(1, "Redstone Action")
end

and


msg = rednet.receive(ID)
if msg == "Redstone Action" then

[ACTION CODE GOES HERE]

end

I am a bit rust at rednet but pretty sure it's right
Edited on 11 August 2015 - 05:33 PM
HPWebcamAble #4
Posted 12 August 2015 - 12:57 AM
So, I assume you know that a Rednet signal can't directly control redstone. You need to have another computer somewhere to receive the signal.


On the pocket computer:

local compID = 1 --# The ID of the computer

rednet.open("side") --# Can't remember what side its on, but for a pocket computer, its always the same

rednet.send( compID , "REDSTONE" )

On the computer:

local pocketID = 2 --# ID of the pocket computer
rednet.open("side")

while true do --# Run this code forever
  local senderID , message = rednet.recieve() --# Waits for a message

  if senderID == pocketID then --# Makes sure the sender was the pocket computer (This is easy to fake though)
    if message == "REDSTONE" then

      --# Do the thing you need to

    end
  end
end
Dragon53535 #5
Posted 12 August 2015 - 03:25 AM
–snip–

msg = rednet.receive(ID)
if msg == "Redstone Action" then

[ACTION CODE GOES HERE]

end

I am a bit rust at rednet but pretty sure it's right
The beginning is quite correct, or well mostly, and enough for most to use. but the code that I've listed here is wrong, rednet.receive takes two arguments and your spelling is incorrect, ceive not cieve.

rednet.receive([timeout],[protocol])
That is the syntax for it, the first argument and second are both OPTIONAL, but timeout is the first, and protocol is the second.
Timeout works like this: I specify that I want a 3 timeout, it will start to listen, and if no message has come in by the end of 3 seconds, then it continues on with the code with senderID and message set to nil.
Protocol works like this: I set a rednet protocol on my send, (rednet,send has 3 arguments, id, message, and protocol) and then i set the same rednet protocol on my receive (It's just a string, can be WHATEVER you want), the receive will wait until it gets a rednet message with that protocol, any other message will be discarded.


--#Receiving computer. ID 0
local id, message = rednet.receive("my,message") --# Something I failed to mention, if you set a protocol as the first argument, it will still work
print(message)
--#Sending computer one
rednet.send(0,"Hello")
--#Sending computer two
rednet.send(0,"Hello There","my,message")
--#The receiving computer will print out:
"Hello There"

HOWEVER, all that being said, you don't HAVE to use rednet, you can use the modem API and that's what it seems like you're trying to do.

Sending computer:

local modem = peripheral.wrap("back") --# A pocket computer will have the wireless modem IN THE BACK
modem.open(61) --#Any number 1-65535
--#Technically the sending computer does NOT have to open the channel to send, but if you want confirmation, it's good to have it open.
modem.transmit(213,61,"hello")
modem.transmit's arguments are:
channel to send to
channel they can send back to you with
message

Receiving computer:

local modem = peripheral.wrap("back")
modem.open(213)
local event = {os.pullEvent("modem_message")}
print(event[5])
Modem API
There are no protocols in the modem api, only 65535 different channels to use.
Edited on 12 August 2015 - 01:34 AM