Update write-received-packet-to-serial.md (#2217)

A support ticket pointed out issues that they'd encountered when trying to follow this document:

- `sendValue` only supports an 8 character string. This is documented in the `sendValue` docs but a longer string had been used here
- Only `radio.onReceivedNumber` is used so the sample output is not consistent with the users experience. I've changed it so that all packets are handled
This commit is contained in:
Sam Kent 2019-06-18 19:23:37 +01:00 committed by Peli de Halleux
parent b1334c75ca
commit cc06e91c25

View File

@ -30,22 +30,26 @@ the second @boardname@), this program sends temperature data to the
serial port.
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(input.temperature());
radio.sendValue("temperature", input.temperature());
radio.sendString("It's warm now");
});
input.onButtonPressed(Button.A, function () {
radio.sendNumber(input.temperature())
radio.sendValue("temp", input.temperature())
radio.sendString("It's warm now")
})
radio.onReceivedNumber(function (receivedNumber) {
radio.writeReceivedPacketToSerial();
});
radio.writeReceivedPacketToSerial()
})
radio.onReceivedValue(function (name, value) {
radio.writeReceivedPacketToSerial()
})
radio.onReceivedString(function (receivedString) {
radio.writeReceivedPacketToSerial()
})
```
Sample output to serial when ``A`` button pressed:
```json
{"t":323,"s":0,"v":27}
{"t":325,"s":0,"n":"temperature","v":27}
{"t":325,"s":0,"n":"temp","v":27}
{"t":326,"s":0,"n":"It's warm now"}
```