Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Must have already opened a valid rednet
- -- connection BEFORE loading this API
- local config = {
- protocol = "wireless",
- host = "accessPoint",
- timout = 30
- }
- local id = rednet.lookup(config.protocol, config.hostName)
- function send(protocol, host, msg)
- local packet = {
- type = "HOSTED",
- host = host,
- payload = msg
- }
- rednet.send(id, packet, protocol)
- end
- function receive(protocol, timeout)
- if timeout == nil then timeout = config.timeout end
- local senderId, packet, prot = rednet.receive(protocol, timout)
- if (senderId ~= id) or
- (packet == nil) or
- (prot ~= protocol) then
- return nil
- else
- return packet.senderId,
- packet.payload,
- prot
- end
- end
- function reply(senderId, msg, protocol)
- local packet = {
- type = "WITH_ID",
- senderId = senderId,
- payload = msg
- }
- rednet.send(id, packet, protocol)
- end
- function broadcast(msg, protocol)
- local packet = {
- type = "BROADCAST",
- msg = msg,
- protocol = protocol
- }
- rednet.send(id, packet, protocol)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement