The Lost Connection Storyboard

JSS 3 MakeCode micro:bit Simulation first Packet Numbers and Reliable Radio
Simulation lab
Board: BBC micro:bit
Open MakeCode ↗
Simulator preview
☀️ 80

Change the slider level and observe the 5x5 LED display.

📁 Tools ▴
  • Web browser (Chrome, Edge, Firefox)
  • Internet connection
  • MakeCode (micro:bit) online editor

🔧 Build Your Reliable Radio Protocol

1 Set both BBC micro:bits to shared radio channel 42 using 'radio.setGroup(42)'.
2 Structure telemetry packets as formatted strings: 'packet_id#sensor_payload'.
3 Program the receiver to track 'expectedId': if an arriving packet number is greater than expected, flag lost packet!
4 Transmit an automatic Negative Acknowledgment (NACK) requesting retransmission of the missing sequence!
🧩 Block plan / Starter code ▴
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 / ActionExpected Result
Packets 1, 2, 3 sent in orderReceiver verifies consecutive sequence; shows Yes checkmark
Packet 2 dropped (simulated)Packet 3 arrives -> Receiver flags 'No' icon and broadcasts NACK#2
Transmitter receives NACK#2Transmitter re-sends packet 2 from memory buffer
⚑ Try a challenge

Implement an automated Sender Timeout: if no ACK is received within 2 seconds of sending, retransmit automatically!

❓ Quick check
Why does our wireless protocol attach an incrementing sequence number (1, 2, 3...) to every radio message?

📖 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 / ActionExpected Result
Packets 1, 2, 3 sent in orderReceiver verifies consecutive sequence; shows Yes checkmark
Packet 2 dropped (simulated)Packet 3 arrives -> Receiver flags 'No' icon and broadcasts NACK#2
Transmitter receives NACK#2Transmitter re-sends packet 2 from memory buffer

⚑ Extension Challenges & Blueprints

⚑ Extension Challenges
  • 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.

❓ Check Your Understanding

Question 1: Why does our wireless protocol attach an incrementing sequence number (1, 2, 3...) to every radio message?

Question 2: The receiver receives packet 1, packet 2, and then packet 4. What should the protocol do?

Question 3: Which built-in radio feature of the BBC micro:bit is used to simulate dual-device wireless communications?

Question 4: What is this protocol concept called in the architecture of the global Internet?

Feedback appears after you check your answer.