Jump to content




Rednet sending a command. What am i missing?


4 replies to this topic

#1 thedriver87

  • Members
  • 28 posts
  • LocationSouthern Oregon

Posted 02 February 2013 - 04:59 PM

So i have the following code for the purpose of sending a redstone signal either solid state or pulsing out the bottom of a computer when it gets the message "[WAREHOUSE] Toggle RS" or "[WAREHOUSE] Pulse RS ON/OFF" from another computer.

local function findPeripheral( pType, errMsg )
  for _, v in pairs( rs.getSides() ) do
    if peripheral.isPresent( v ) and peripheral.getType( v ) == pType then
	  return v
    end
  end
  print( "Cannot find a "..errMsg or pType.." attached to this computer " )
  error()
end
local modemSide = findPeripheral( "modem" )
rednet.open( modemSide )
local pulseDuration = nil
local pulseTime = os.startTimer( duration or 0.5 )
local pulseActive = false
while true do
  local event = { os.pullEventRaw( ) }
  if event[1] == "rednet_message" then
    print( "Message received" )
    local msg = textutils.unserialize( event[3] )
    if msg["target"] == "[WAREHOUSE]" then
	  local action = msg["action"]
	  if action == "Toggle RS" then
	    rs.setOutput( "bottom", not rs.getInput( "bottom" ) )
	  elseif action == "Pulse RS ON" then
	    pulseDuration = tonumber( msg["duration"] )
	    pulseActive = true
	    pulseTime = os.startTimer( duration or 0.5 )
	  elseif action == "Pulse RS OFF" then
	    pulseActive = false
	    rs.setOutput( "bottom", false )
	  end
    end
  elseif event[1] == "timer" and event[2] == pulseTime and pulseActive then
    rs.setOutput( "bottom", not rs.getInput( "bottom" ) )
    pulseTime = os.startTimer( pulseDuration or 0.5 )
  end
end
rednet.close( modemSide )

however when i run another computer set the rednet and boradcast the following in the lua prompt: rednet.broadcast( "[WAREHOUSE] Toggle RS") and hit enter the computer returns true and the drone computer returns message received, but no redstone pulse or redstone solid state.. i'm pretty sure the rs.setOutput is written properly and im almost certain the message is being read properly.... what am i missing?

#2 raineth

  • Members
  • 15 posts
  • LocationPennsylvania, USA

Posted 02 February 2013 - 05:22 PM

 thedriver87, on 02 February 2013 - 04:59 PM, said:

however when i run another computer set the rednet and boradcast the following in the lua prompt: rednet.broadcast( "[WAREHOUSE] Toggle RS") and hit enter the computer returns true and the drone computer returns message received, but no redstone pulse or redstone solid state.. i'm pretty sure the rs.setOutput is written properly and im almost certain the message is being read properly.... what am i missing?
Why are you sending plain text and expecting it to deserialize into a table? Is this your code, or someone else's that you're trying to send messages to?

#3 Conn332

  • Members
  • 11 posts

Posted 03 February 2013 - 04:24 AM

instead of have os.pullEvent() equaling just event have it equal event, ID, message and just test if message is equal to [Warehouse] pulse or ON/OFF

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 February 2013 - 10:11 AM

Because when I wrote this code the message format was intended like so...

rednet.broadcast(textutils.serialize({target="[WAREHOUSE]", action="some action"}))


 Conn332, on 03 February 2013 - 04:24 AM, said:

instead of have os.pullEvent() equaling just event have it equal event, ID, message and just test if message is equal to [Warehouse] pulse or ON/OFF
Wouldn't work... If you didn't notice the os.pullEvent() has {} around it meaning its returned data in a table. So
local event, ID, message = {os.pullEvent()}
Message AND ID would always be nil.

#5 thedriver87

  • Members
  • 28 posts
  • LocationSouthern Oregon

Posted 03 February 2013 - 12:05 PM

and there is the answer.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users