Jump to content

rednet.broadcast() functionality for peripheral.wrap()

peripheral wireless

2 replies to this topic

#1 resdac

  • Members
  • 6 posts

Posted 06 August 2015 - 07:50 PM

i have my peripheral wrap set up with a wirless modem and i am stuck on the general broadcast function
my code for so far is this:
wifi = peripheral.wrap("left")
lan = peripheral.wrap("top")
while true do
	local event, value1, value2, value3, value4, value5 = os.pullEvent()
	if event == "modem_message" then
		if string.sub(value4,0,5) == "wifi#" or string.sub(value4,0,4) == "lan#" then
			rednetArr = split(value4,"#")
			if #rednetArr == 1 then
				lan.transmit( value3, 1110,"error ocured while sending1")
			elseif #rednetArr == 2 then
				if rednetArr[1] == "wifi" then
					lan.transmit( value3, 1110,"error ocured while sending2")
			elseif #rednetArr == 3 then
				if rednetArr[1] == "wifi" then
					wifi.transmit(tonumber(rednetArr[2]), 2220,rednetArr[3])
					lan.transmit(tonumber(rednetArr[2]), 1110,rednetArr[3])
			elseif #rednetArr == 4 then
				-- specific pc and protocol
with most of the other code gone to get it clear, the problem is on line 14 where wifi.broadcast() is called.
how can i get a way to reach the whole spectrum without using rednet.

#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 07 August 2015 - 03:36 AM

When you wrap a modem directly, with peripheral.wrap, you get the Modem API:

When you use rednet.open("side"), you use the Rednet API:

The modem API only has 1 function related to sending messages: transmit(channel,replyChannel,message)
Any computer listening on 'channel' gets a "modem_message" event.
Arguments are modemSide, channel, replyChannel, message, distance

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 August 2015 - 08:49 AM

When you call rednet.open(), basically all it's doing is:

modem.open( os.getComputerID() )
modem.open( 65535 )

When you call rednet.broadcast(), the end result boils down to:

rednet.send(65535, message)

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users