The Lost Connection Storyboard
Change the slider level and observe the 5x5 LED display.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- MakeCode (micro:bit) online editor
🔧 Build Your Reliable Radio Protocol
radio.setGroup(42)
let packetId = 0
let expectedId = 0
// Transmitter Logic (Button A)
input.onButtonPressed(Button.A, function () {
packetId += 1
let payload = "SOIL:45"
radio.sendString(packetId + "#" + payload)
basic.showNumber(packetId)
})
// Receiver Logic
radio.onReceivedString(function (receivedString) {
let parts = receivedString.split("#")
let id = parseInt(parts[0])
if (id == expectedId + 1) {
expectedId = id
basic.showIcon(IconNames.Yes) // Clean ordered packet
} else if (id > expectedId + 1) {
basic.showIcon(IconNames.No) // Packet loss detected!
radio.sendString("NACK#" + (expectedId + 1))
}
})
Sequence numbers allow the receiver to identify dropped packets and trigger automated recovery.
⚗️ Test your model
| Test Condition / Action | Expected Result |
|---|---|
| Packets 1, 2, 3 sent in order | Receiver verifies consecutive sequence; shows Yes checkmark |
| Packet 2 dropped (simulated) | Packet 3 arrives -> Receiver flags 'No' icon and broadcasts NACK#2 |
| Transmitter receives NACK#2 | Transmitter re-sends packet 2 from memory buffer |
Implement an automated Sender Timeout: if no ACK is received within 2 seconds of sending, retransmit automatically!
📖 Our Story & Concepts
When sending wireless radio or cellular signals across farmland or school compounds, radio waves reflect off walls, get absorbed by trees, and suffer from interference. Wireless packets get dropped constantly.
If you stream video or download a file over the Internet, how does your phone reconstruct the complete file without corruption? Protocols like TCP (Transmission Control Protocol) stamp every packet with a sequence number. By tracking numbers, receiver devices detect gaps and automatically request missing slices.
</> Full Annotated Code Walkthrough
// Complete Reliable Transport Protocol with Retransmission Buffer
radio.setGroup(42)
let txBuffer: string[] = []
let currentSeq = 0
let ackedSeq = 0
// Sender: Send with Sequence Tracking
input.onButtonPressed(Button.A, function () {
currentSeq += 1
let packet = currentSeq + ":TEMP:" + input.temperature()
txBuffer.push(packet)
radio.sendString(packet)
basic.showNumber(currentSeq)
})
// Receiver: Handle In-Order Delivery & NACKs
let expectedSeq = 1
radio.onReceivedString(function (pkt) {
if (pkt.includes("NACK:")) {
let missing = parseInt(pkt.split(":")[1])
// Resend missing packet from buffer
for (let item of txBuffer) {
if (parseInt(item.split(":")[0]) == missing) {
radio.sendString(item)
}
}
} else {
let seq = parseInt(pkt.split(":")[0])
if (seq == expectedSeq) {
expectedSeq += 1
basic.showIcon(IconNames.Happy)
} else if (seq > expectedSeq) {
basic.showIcon(IconNames.Sad)
radio.sendString("NACK:" + expectedSeq)
}
}
})
Sequence numbers allow the receiver to identify dropped packets and trigger automated recovery.
▷ Expected Results & Troubleshooting
| Test Condition / Action | Expected Result |
|---|---|
| Packets 1, 2, 3 sent in order | Receiver verifies consecutive sequence; shows Yes checkmark |
| Packet 2 dropped (simulated) | Packet 3 arrives -> Receiver flags 'No' icon and broadcasts NACK#2 |
| Transmitter receives NACK#2 | Transmitter re-sends packet 2 from memory buffer |
⚑ Extension Challenges & Blueprints
- Level 1: Display packet latency (time between transmission and ACK) in milliseconds.
- Level 2: Build a 5-packet queue buffer that sends packets in bursts.
- Level 3: Implement checksum error detection to verify that packet payload bytes were not corrupted in transit.