Radio Modems & Wireless Communication
Overview
Radio modems (cee_radio) allow computers to communicate wirelessly over the air using channels, frequencies, and antennas. Modems are split into roles (tx for transmitting, rx for receiving) depending on their physical wiring. A computer never hears its own transmissions unless loopback is enabled in the configuration.
Hardware & Wiring Rules
- Roles: A modem is
txwhen a TX antenna is wired to its signal-out; otherwise, it defaults torx. - Physical Layout: Two modems fit in a single block, each occupying a separate half (upright or laid flat). Wrenching or breaking them affects only the targeted modem.
- Data Flow Wiring: Wire modems according to the data path:
- Transmitter: Computer ->
in, TX Antennas ->out. - Receiver: RX Antennas ->
in, Computer ->out. - Power: Modems, TX antennas, and RX antennas all require proper power and correct polarity. Level
0is completely silent. Range is determined entirely by the sending transmitter's power level, height, and obstacles.
API Reference Table
| Method Signature | Arguments & Types | Description |
|---|---|---|
r.setChannel(channel) |
channel (number 0–6000) |
Sets the radio channel frequency. |
r.setLevel(level) |
level (number) |
Sets the transmission power level (range/strength). |
r.transmit(msg) |
msg (table/string) |
Transmits a payload over the air; returns the number of accepted arrivals. |
r.getRole() |
None | Returns 'tx' or 'rx' based on physical antenna wiring. |
r.canTransmit() |
None | Returns true while the modem and its TX antenna are powered and ready. |
r.hasTransmitter() |
None | Alias for canTransmit(). |
r.getLastError() |
None | Returns nil on success, or an error string (e.g., 'unpowered', 'rate_limited', 'no_receiver') on failure. |
r.isOn() |
None | Returns true if the modem's physical power switch is turned on. |
r.publish(key, value) |
key, value |
Continuously publishes state data over the air (newest-value-wins queue system). |
r.readState(id, key) |
id, key |
Reads the latest published state value from a specific sender. |
Wireless Events
cee_radio_message- Triggered when a wireless message arrives.
- Event returns:
_, channel, senderId, message, distance, signalMargin. cee_radio_state- Triggered when a published state updates over the air.
- Event returns:
_, channel, senderId, key, value, distance, signalMargin.
Code Examples
Sending a Wireless Message
local r = peripheral.find("cee_radio")
if r then
r.setChannel(1234)
r.setLevel(16)
local sentCount = r.transmit({ hello = "world" })
print("Message sent to " .. sentCount .. " receivers.")
end