Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Sniffing Attacks and Defenses

Cybersecurity: Sniffing Attacks and Defenses

How the Sender, Receiver, and Sniffer Work

The transmitter script broadcasts a string containing a term every 2.5 seconds.  Those terms HAPPY, SAD, ANGRY can be used by receivers in statements that work the same way as display.show(Image.HAPPY), display.show(Image.SAD), and so on.

 

Transmitter Script

The statements below set up and turn on the micro:bit module’s built-in radio and also provide a helpful 1-second delay before sending data to the terminal.  To find out more, try out the Cybersecurity: Radio Basics activities.

# radio_send_images.py

from microbit import *
import radio

radio.on()
radio.config(channel=7)

sleep(1000)

 

A convenient approach to sending predefined image data through the radio is to simply send strings that contain words like “HAPPY”, “SAD”, “ANGRY” that can be used as arguments. The receiver script can build a statement like display.show(Image.HAPPY).  In addition to sending the data packet, the transmitter script prints the word on the terminal so you can monitor which mood/reaction image it’s sending through radio.send(packet).  

while True:

    packet = "HAPPY"
    print("Send:", packet)
    radio.send(packet)
    sleep(2500)

    ...

 

Receiver Script

After the same familiar initialization, the receiver script’s main loop checks for incoming messages with packet = radio.receive().  If nothing is received, packet = None, and the statements under if packet: get skipped.  When packet stores a string like “HAPPY”, “SAD”, or “ANGRY”, the statements indented below if packet: print the string to the terminal, and then display the corresponding image on the micro:bit module’s LEDs matrix.  

while True:
    
    packet = radio.receive()

    if packet:
        print("Receive:", packet)
        display.show(getattr(Image, packet))

 

The trick to using a string to access the image is to use getattr (object, name).  This “get attribute” function accepts an object and the string name of one of its properties.  It responds by returning that property.  When packet contains “HAPPY”, then getattr(Image, “HAPPY”) returns Image.HAPPY, and the micro:bit lights up its LEDs in response to display.show(Image.HAPPY).  

 


Printer-friendly version
Share Something Personal – Unencrypted?
Prev
Try This: Improve the Script
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress