[KongchangAI]
· 3 min read· 1,526 words

Giving a Toilet an IP Address with a Raspberry Pi: An Absurd Yet Hardcore IT Experiment

Giving a Toilet an IP Address with a Raspberry Pi: An Absurd Yet Hardcore IT Experiment

A blogger assigned an IP to his toilet using a Raspberry Pi and float switch to monitor flushes and investigate network disconnections, drawing parallels to AI Agent security monitoring.

To investigate the correlation between office NAS disconnections and toilet flushes, an IT blogger assigned IP address 10.77.14.178 to his toilet using a Raspberry Pi 3 Model B+ and a float switch. The float switch converts water level changes into GPIO high/low levels via a magnet and reed, with built-in pull-up resistors suppressing noise. The script polls GPIO every 0.1 seconds, records flush events to state.json, and triggers Slack notifications. The installation was full of surprises but ultimately succeeded. The project is used to analogize log correlation and forensic approaches for AI Agent prompt injection attacks, emphasizing that all signals need to be on the same timeline when anomalies occur.

When a Toilet Gets an IP Address

An IT blogger actually assigned an IP address to his toilet—10.77.14.178. This isn't a joke; it's a real project he completed using a Raspberry Pi 3 Model B+ and a liquid-level float switch. The idea started as a joke he made while teaching subnetting: "I'm going to give my toilet an IP address." Years later, that joke became a hardcore experiment in a video.

But behind the absurdity lies a legitimate IT need: the NAS and network in his office would occasionally disconnect for no apparent reason, and each disconnection seemed to coincide with someone flushing the toilet. Rather than asking colleagues one by one, "Did you just flush?", he decided to let the toilet report for itself—precise to the millisecond, making it easy to compare against network logs on a timeline.

Close-up of the float switch

Technical Approach: Sensing Flushes with a Float Switch

The hardest part of monitoring a toilet isn't the hardware—it's figuring out "how do you know it flushed?" Camera? Impractical. Handle sensor? Too complex. The final solution was surprisingly simple: put a float switch inside the tank.

How a Float Switch Works

This small component contains two metal reeds that are almost in contact and a magnet. As the float moves up and down with the water level, the magnet causes the reeds to attract or separate, outputting an on/off signal. Connect it to the Raspberry Pi's GPIO pin, and you can turn "water level dropping" into "a flush event."

Diagram of float switch internal structure

The float switch is a typical application of a reed switch. A reed switch seals two ferromagnetic reeds inside a glass tube filled with inert gas. When an external magnetic field (such as a magnet fixed to the float) approaches, the reeds become magnetized and attract; when the field moves away, the reeds separate due to their own elasticity. This structure has no mechanical wear contacts exposed to air, making it suitable for humid environments. In liquid-level detection, the float typically rides on a guide tube, with a magnet inside moving with the liquid surface and a reed switch fixed inside the tube, achieving non-contact triggering. Its output is a pure switching signal (on/off), requiring no analog-to-digital conversion—which is why it's suitable for direct connection to Raspberry Pi GPIO.

Wiring and Pull-up Resistor

The wiring is equally minimal: one wire to Pin 9 (ground), the other to Pin 11 (GPIO 17). The blogger temporarily twisted jumper wires on and reminded viewers to complete wiring before powering up to avoid short circuits. Here's a key detail—Raspberry Pi GPIO has built-in weak pull-up resistors that pull the pin voltage to 3.3V. When the float switch is open, it reads as high (1); when the float sinks and the reed grounds, it reads as low (0). Without this pull-up resistor, the pin would pick up stray electrical noise, causing the system to "see" flush events that never happened—as the blogger put it, like someone who ate too much Taco Bell.

A pull-up resistor is a fundamental concept in digital circuits. If a GPIO pin is left floating, its voltage is indeterminate and susceptible to electromagnetic interference, randomly flipping between 0 and 1. A pull-up resistor connects the pin to 3.3V through a relatively large resistance (the Raspberry Pi's internal one is about 50kΩ), stabilizing the default state at high level; when an external switch closes to ground, the pin is pulled low to 0. Raspberry Pi GPIO can enable internal pull-up/pull-down in software, but the internal resistors are weak, and long wires or noisy environments can still cause false triggers. If instability occurs, add an external 4.7kΩ–10kΩ pull-up resistor to improve noise immunity. Also, GPIO input voltage must not exceed 3.3V; connecting a 5V signal directly may damage the pin.

Software Logic: Polling Every 0.1 Seconds

The system runs a minimal 64-bit OS on the Raspberry Pi with no graphical interface. The script checks GPIO status every 0.1 seconds, records flush events and writes them to a state.json file, while also tracking low-water-level duration—if the water level drops too fast and recovers too quickly, it's not counted as a valid flush, filtering out false triggers.

The blogger also had AI generate a visual animation demo: when the water level is full, the float is up; after flushing, the float sinks, a timer starts counting, then the tank refills and the state resets. This logic was validated outside the tank first, and only installed in the real toilet after confirming reliability.

Polling and interrupts are two common ways to detect GPIO events. Polling actively reads pin status at fixed intervals—simple to implement but CPU-intensive and may miss short pulses; interrupts trigger callbacks when pin level changes, offering better real-time response and lower CPU usage. This project chose 0.1-second polling because water level changes from flushing last several seconds, far exceeding the polling interval, so no events are missed, and the logic is easier to debug. state.json persists current state (such as whether a flush is in progress and the last flush time), so context can be restored even if the script restarts. In actual deployment, debounce logic could be added to prevent repeated counting from float jitter near critical water levels.

Installation: A Real-World Process Full of Surprises

The actual installation was not elegant. The blogger first tried Lego bricks as a bracket, then used zip ties to secure the Raspberry Pi near the tank. During the process, wires got wet and he had to dismantle and start over. He admitted he's not good at handiwork, and the final product looked quite "makeshift."

Redoing after wires got wet during installation

After installation and power-up, a real flush test succeeded: the system captured the event and triggered a Slack notification to the team channel. The blogger deliberately blurred the image, only showing the notification appearing in the general channel. At this point, the toilet monitoring loop was complete—from physical action to digital signal to team message.

From Toilet to AI Security: Transferring Monitoring Concepts

This project was used to analogize a more serious topic: AI Agent security. A Wiz demo inserted in the video showed a prompt injection attack—a malicious prompt made an AI Agent execute attacker code, steal cloud credentials, open a reverse shell, and copy databases. Wiz's AI detection and response system aggregated CloudTrail, DNS logs, model logs, and server sensor data into a single attack path graph, then an AI Agent determined it as malicious and completed forensic analysis.

The commonality between the two: when anomalies occur, you need all relevant signals on the same timeline. The correlation between toilet flushes and NAS disconnections, and between hacker activity and log anomalies, are essentially the same IT methodology—observe, correlate, locate.

Prompt injection is one of the main security threats facing AI Agents. Attackers disguise malicious instructions as ordinary content (such as web page text, emails, documents), tricking the Agent into executing them as legitimate commands, thereby abusing tool calls, leaking data, or executing code. Unlike SQL injection, prompt injection has no strict syntactic boundaries, making defense harder. The attack chain in the Wiz demo exploited the Agent's trust in tool calls, making the Agent actively execute attacker code. CloudTrail is AWS's API audit logging service that records all cloud operations; DNS logs can expose malicious domain resolutions; a reverse shell is a common technique attackers use to gain remote control. Aggregating these heterogeneous logs into a unified timeline is key to detection and forensics.

Is This Project Worth Doing?

From a practical standpoint, giving a toilet an IP address has almost no everyday value. But from a learning perspective, it strings together GPIO input, pull-up resistors, polling and state files, and notification integration into a complete chain, costing only a Raspberry Pi, a float switch, and a few zip ties. In his closing prayer, the blogger said he hopes such "silly projects" can open viewers' imaginations to technological possibilities—perhaps a career direction, or perhaps just a small thing that ignites passion.

For readers who want to replicate this, the core checklist is: Raspberry Pi (with GPIO), float switch, jumper wires, zip ties, and the safety awareness to complete wiring before powering up.

One-line Summary

A blogger assigned an IP address to his toilet using a Raspberry Pi and float switch to monitor flushes and investigate network disconnections, drawing parallels to AI Agent security monitoring.

Paragraph Summary

To investigate the correlation between office NAS disconnections and toilet flushes, an IT blogger assigned IP address 10.77.14.178 to his toilet using a Raspberry Pi 3 Model B+ and a float switch. The float switch uses a magnet and reed on/off to convert water level changes into GPIO high/low levels, with built-in pull-up resistors suppressing noise. The script polls GPIO every 0.1 seconds, records flush events to state.json, and triggers Slack notifications. The installation was full of surprises, but the loop was ultimately completed. The project is used to analogize log correlation and forensic approaches for AI Agent prompt injection attacks, emphasizing that when anomalies occur, all signals need to be on the same timeline.

#Raspberry Pi#float switch#GPIO#pull-up resistor#AI Agent security#prompt injection#network monitoring
Share:

Related articles