micro:bit "radio write received packet to serial" is missing

Issue #173 resolved
Turgut Guneysu created an issue

In the MakeCode micro:bit IDE, the “radio write received packet to serial" block is the means to produce JSON output from the received data.

And also this feature is used in transmitting data collection values with various data value pairs.

Not supporting this block will create confusion for people working in both environments.

Now we know that MB does not have a SERIAL interface capability from the IDE. However, a block that converts the received packet to JSON but not write it to SERIAL would be very handy and a requirement for compatibility.

The usage of this block in MakeCode is as such:

Data received format

The format for received data when these send functions are used:

  • send number{v:ValueSent,t:MicrobitTimeAlive,s:SerialNumber}
  • send value{v:ValueSent,t:MicrobitTimeAlive,s:SerialNumber,n:"Name"}
  • send string{t:MicrobitTimeAlive,s:SerialNumber,n:"Text"}

The serial number value sent in the packet is set to 0 unless transmission of the serial number is enabled with radio set transmit serial number.

Actual Data received

Send Number: {"t":5117566,"s":-1142702066,"n":"1234567890"}

Send Value: {"t":5120453,"s":-1142702066,"n":"beg","v":44}

Send String: {"t":5120455,"s":-1142702066,"n":"The quick brown fox"}

Comments (5)

  1. John Maloney repo owner

    What do people use this block for? While it’s nice as a way to peek under the hood, I can only think of limited use cases for the timestamp and serial number fields. Do you know of any MakeCode example projects that use this feature? Do you have a particular application in mind?

  2. Turgut Guneysu reporter

    I personally don’t think much about the timestamp and serial# fields. The JSON payload is the important part ! But, of course, given the small 19byte message size, the timestamp and serial # fields can be helpful when collecting data over long periods of time, it being the most relevant use case that quickly comes to mind.

  3. John Maloney repo owner

    There isn’t actually any JSON payload in radio messages. A radio packet is 32-bytes of raw data. The MakeCode radio protocol uses the first 12 bytes as a header. The rest of a MakeCode packet depends on the type. For example, a string packet uses one byte for the string length leaving 19 bytes for the string body. A pair packet used one byte for the string length and four bytes for the number, leaving 15 bytes for the string part, etc.

    (See https://ukbaz.github.io/howto/ubit_radio.html  and https://support.microbit.org/support/solutions/articles/19000053168-receiving-radio-data-from-pxt-within-python for more details.)

    So, if you want to explore what’s inside radio packets, the “_radio receive packet” is probably what you want. However, as mentioned in issue 172, I just noticed a bug in that block in in the Radio library – it should return a boolean so you know if you’ve gotten a packet or not. I’ll fix that in the next release.

  4. John Maloney repo owner

    For those who want to explore the internal details of radio packets, you can use the low-level primitives to receive raw packets. The received data is copied into a 32-element list. Since this isa very unusual (and advanced) use case, that primitive is only available in the System/radioPrims library.

  5. Log in to comment