BitRadio
Support for sending and receiving packets using the Bit Radio protocol, typically used between micro:bit devices.
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
Commands
sendString
Sends a string payload as a radio message, maximum 18 characters.
bitRadio.sendString(message: string): Promise<void>
sendNumber
Sends a double precision number payload as a radio message
bitRadio.sendNumber(value: number): Promise<void>
sendValue
Sends a double precision number and a name payload as a radio message
bitRadio.sendValue(value: number, name: string): Promise<void>
sendBuffer
Sends a payload of bytes as a radio message
bitRadio.sendBuffer(data: Buffer): Promise<void>
Registers
enabled
Turns on/off the radio antenna.
type:
Register<boolean>
(packing formatu8
)read and write
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
const value = await bitRadio.enabled.read()
await bitRadio.enabled.write(value)
- track incoming values
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
bitRadio.enabled.subscribe(async (value) => {
...
})
write
and read
will block until a server is bound to the client.
group
Group used to filter packets
type:
Register<number>
(packing formatu8
)read and write
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
const value = await bitRadio.group.read()
await bitRadio.group.write(value)
- track incoming values
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
bitRadio.group.subscribe(async (value) => {
...
})
write
and read
will block until a server is bound to the client.
transmissionPower
Antenna power to increase or decrease range.
type:
Register<number>
(packing formatu8
)read and write
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
const value = await bitRadio.transmissionPower.read()
await bitRadio.transmissionPower.write(value)
- track incoming values
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
bitRadio.transmissionPower.subscribe(async (value) => {
...
})
write
and read
will block until a server is bound to the client.
frequencyBand
Change the transmission and reception band of the radio to the given channel.
type:
Register<number>
(packing formatu8
)read and write
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
const value = await bitRadio.frequencyBand.read()
await bitRadio.frequencyBand.write(value)
- track incoming values
import { BitRadio } from "@devicescript/core"
const bitRadio = new BitRadio()
// ...
bitRadio.frequencyBand.subscribe(async (value) => {
...
})
write
and read
will block until a server is bound to the client.