microsoft / microsoft/pxt-microbit

Can't get signal strength in onReceivedMessage

Open
#6,869 5 comments 0 reactions 1 assignee View on GitHub

@microbit-carlos is already working on this.

Since Jun 5, 2026.

apis P2 radio
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Describe the bug

radio.receivedPacket(RadioPacketProperty.SignalStrength) does not work if called in a radio.onReceivedMessage() handler. This is true in the simulator and on micro:bit V2.

It does work in a radio.onReceivedNumber() handler. And once this has been trigger, calling radio.receivedPacket(RadioPacketProperty.SignalStrength) will show that same value in radio.onReceivedMessage().

To Reproduce
Steps to reproduce the behavior:

  1. Use the code
enum RadioMessage {
    message1 = 49434
}
input.onButtonPressed(Button.A, function () {
    radio.sendNumber(0)
})
input.onButtonPressed(Button.B, function () {
    radio.sendMessage(RadioMessage.message1)
})
radio.onReceivedMessage(RadioMessage.message1, function () {
    basic.showString("B")
    basic.showNumber(radio.receivedPacket(RadioPacketProperty.SignalStrength))
})
radio.onReceivedNumber(function (receivedNumber) {
    basic.showString("A")
    basic.showNumber(radio.receivedPacket(RadioPacketProperty.SignalStrength))
})
radio.setGroup(1)
  1. Press button B
  2. This always show zero.
  3. Press button A
  4. This will show a signal strength
  5. Pressing B now will show the signal strength from the previous onReceivedNumber

Expected behavior

Any of the radio.onReceived... methods should report the signal strength of the current packet.

micro:bit version (please complete the following information):

V2.21 hardware and the sim at https://makecode.microbit.org/#editor

Desktop (please complete the following information):

  • OS: Fedora 43
  • Browser: 1.19.13b (Firefox 150.0.3)
  • Version [e.g. 22]

Additional context

I think this is because radio.sendMessage() and radio.onReceivedMessage(), take a different path compared to the other radio methods. On receipt of the radio packet they go through event.packetReceived() instead of datagram.packetReceived(). This triggers a MicroBitEvent for the message id. radio.receivedPacket works with the last packet received to MicroBitRadioDatagram.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.