← All projects

2024

Motion-Triggered LED over UDP

A client and server on a Raspberry Pi that talk over a custom UDP protocol: when a motion sensor trips on the client, the server blinks an LED.

A Raspberry Pi wired to a breadboard with a red LED and a motion sensor, with the program output on a screen behind it

A programming assignment for Computer Networks at Tennessee Tech, built with classmate Pierce Parker. We both worked on the client and the server.

The client watches a motion sensor and the server controls an LED, each wired to the Pi's GPIO pins. The two Python programs communicate over UDP sockets using a protocol we designed: every packet starts with a 12-byte header holding a sequence number, an acknowledgement number and ACK, SYN and FIN flags, followed by a text payload.

A session opens with a three-way handshake modelled on TCP. The client then sends how many times the LED should blink and for how long, and the server acknowledges. After that, each motion event sends a message that makes the server blink the LED, and stopping the client sends a FIN so the server can close cleanly.

Both programs log every packet they send and receive with a timestamp, and we recorded the exchange in a packet capture.

Source: lightserver.py · lightclient.py

Try it

The sensor and LED can't run in a browser, so this is a walkthrough of the protocol instead. The packets, sequence numbers and flags are the ones the real programs exchange.

  1. Press Connect to watch the three-way handshake and the blink settings being agreed.
  2. Press Trigger motion to stand in for the sensor. The client sends a message and the server blinks the LED three times.
  3. Click any packet in the log to see its 12-byte header and payload as raw bytes.
  4. Press Disconnect to send the FIN that ends the session.
Open in a new tab