Radio Modem and Wi-Fi Router
The wireless endpoints of a computer: their range, and the network name that joins routers into one backbone.
A Radio Modem (packet radio, 1971) lets a computer send net messages through the air to the computers around it. A Wi-Fi Router (1999) reaches twice as far, and all the routers that share a network name, an SSID, form one backbone across the world, like the Internet: a message that reaches one router comes out of all the others. As a peripheral, the radio tells its range, and the router lets a program read and set its SSID.
local router = peripheral.find("wifi_router")
router.set_ssid("brassworks")
print(router.range() .. " blocks")radio.range() | The range of this radio: 128 blocks for a Radio Modem, 256 for a Wi-Fi Router, times the server's range multiplier. |
radio.get_ssid() | The network name of a Wi-Fi Router. |
radio.set_ssid(name) | Gives the router a network name: it joins every other router of that name into one backbone. |
Setting up
Which computers. Wireless needs a Personal Computer, a Microcontroller or a Modern Computer. Older computers can still wrap a radio and call these methods, but net sends nothing through it.
Placing it. Put the radio against any face of the computer, or anywhere on the Data Cable network of the computer: one radio on the roof serves every computer of the building. A computer with several radios uses them all.
How far. Two radios hear each other when they are closer than the shorter of their two ranges:
| block | range | peripheral type |
|---|---|---|
| Radio Modem | 128 blocks | radio_modem |
| Wi-Fi Router | 256 blocks | wifi_router |
A modem and a router talk up to 128 blocks, two routers up to 256. The server can scale every range (wirelessRangeMultiplier in computingages-server.toml, from 0.1 to 16). On a Create Aeronautics vehicle, distances use the real position of the vehicle.
The backbone. Routers that share an SSID are all linked, wherever they are in the same dimension. A computer is on that backbone when one of its own routers has the SSID, or when any of its radios, even a plain modem, is in range of a router of it. It then reaches every computer near any other router of the same SSID. A relay router must be attached to a computer that has wireless and sits in a loaded chunk (the computer does not need to run a program): a router standing alone in a field relays nothing. A router with no SSID is simply a radio with a longer range.
Messages that went through a router arrive with via set to "wifi", the others with "radio" (or "cable"). net.networks lists the backbones a computer can use. The whole story is in Networks.
Range
The range of this radio: 128 blocks for a Radio Modem, 256 for a Wi-Fi Router, times the server's range multiplier.
- number
- how far this radio reaches, in blocks
local radio = peripheral.wrap("top")
print(radio.range(), "blocks")Remember that a link uses the shorter range of its two ends: a router talking to a modem reaches only as far as the modem. When the block is not a radio any more, the call stops the program with radio removed.
Network name
The network name of a Wi-Fi Router.
- string|nil
- the SSID of a Wi-Fi Router,
""when it has none;nilfor a Radio Modem
A new router has no name: get_ssid() returns the empty string "". A Radio Modem has no SSID at all and returns nil, which makes this call a way to tell the two apart:
local radio = peripheral.wrap("top")
local ssid = radio.get_ssid()
if ssid == nil then
print("a radio modem")
elseif ssid == "" then
print("a router without a network name")
else
print("a router of " .. ssid)
endSee also radio.set_ssid() net.networks()
radio.set_ssid(name)
Gives the router a network name: it joins every other router of that name into one backbone.
namestring- the network name, 32 characters at most
local router = peripheral.find("wifi_router")
router.set_ssid("brassworks")- The name is kept in the router itself: it stays when the program ends, when the world reloads, and when the router is moved to another computer.
- A name longer than 32 characters is cut to its first 32.
- The empty string
""takes the router off every backbone: it becomes a long-range radio again. - The change reaches the network within a second.
- On a Radio Modem the program stops with
only Wi-Fi routers have an SSID.
Anyone who knows the name can join the backbone with their own router: pick a name that is hard to guess for a private network.
See also radio.get_ssid() net.networks()
Examples
A router that names itself
A startup file for each computer that carries a router: it sets the SSID once, and checks that it worked. Copy it to the base, the mine and the airship dock, and the three become one network.
local NETWORK = "brassworks"
local router = peripheral.find("wifi_router")
if router == nil then
error("no Wi-Fi Router on this computer")
end
if router.get_ssid() ~= NETWORK then
router.set_ssid(NETWORK)
print("router joined " .. NETWORK)
endEvery radio of a computer
Lists the radios a computer can use, against it or on its cable, with their range and their network name:
for _, name in ipairs(peripheral.list()) do
local kind = peripheral.type(name)
if kind == "radio_modem" or kind == "wifi_router" then
local radio = peripheral.wrap(name)
local ssid = radio.get_ssid()
if ssid == nil then
ssid = "-"
elseif ssid == "" then
ssid = "(no name)"
end
print(name .. " " .. radio.range() .. " blocks " .. ssid)
end
endOn a computer with a router on top and a modem on the roof, it prints something like:
top 256 blocks brassworks radio_modem@14,80,-3 128 blocks -