pxt-calliope/docs/reference/radio/received-packet.md
Peli de Halleux 2b504d863d
Radiodocsupdate (#1430)
* a few updates

* more updates

* reorder radio blocks

* more shuffling of new radio apis

* fixing hot or ocold

* more doc fixes

* more updates

* fixing docs issues

* more doc fixes

* restore docs errors

* missing packate

* renamed argument of callback

* mssing radio

* more odcs fixes

* lock turtle

* ignore docs for now
2018-10-15 15:32:09 -07:00

1.0 KiB

Received Packet Property

Get one of the properties from the last received radio packet.

radio.receivedPacket(RadioPacketProperty.SignalStrength)

Parameters

  • type: the property type to get from the packet. These are:
  • signal strength: the strength of the radio signal when the packet was received.
  • serial number: the serial number of the board sending the packet.
  • time: the time when the packet was sent.

Returns

  • a number that is the property selected in the type parameter.

Example

This program uses the signal strength from received packets to graph the approximate distance between two @boardname@s.

basic.forever(() => {
    radio.sendNumber(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    led.plotBarGraph(
        Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42),
        128 - 42
    )
})

See also

set transmit serial number

radio