{"id":34520833,"url":"https://github.com/justinh-rahb/esp-stop","last_synced_at":"2026-05-28T03:31:27.523Z","repository":{"id":291173420,"uuid":"976690521","full_name":"justinh-rahb/esp-stop","owner":"justinh-rahb","description":"E-Stop for 3D Printers using OctoPrint or Klipper. Also supports TP-Link Kasa smart switches. Built with ESP8266 Arduino (PlatformIO).","archived":false,"fork":false,"pushed_at":"2026-02-16T06:55:56.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-16T14:38:28.986Z","etag":null,"topics":["arduino","e-stop","esp8266","iot","klipper","moonraker","octoprint","platformio","tplink-kasa"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justinh-rahb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-02T15:09:40.000Z","updated_at":"2026-02-16T06:55:56.000Z","dependencies_parsed_at":"2025-05-02T21:39:26.962Z","dependency_job_id":"d789779e-0672-4671-9940-ba09dfd3a29b","html_url":"https://github.com/justinh-rahb/esp-stop","commit_stats":null,"previous_names":["justinh-rahb/esp-stop"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/justinh-rahb/esp-stop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinh-rahb%2Fesp-stop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinh-rahb%2Fesp-stop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinh-rahb%2Fesp-stop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinh-rahb%2Fesp-stop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinh-rahb","download_url":"https://codeload.github.com/justinh-rahb/esp-stop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinh-rahb%2Fesp-stop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33593400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","e-stop","esp8266","iot","klipper","moonraker","octoprint","platformio","tplink-kasa"],"created_at":"2025-12-24T04:55:47.525Z","updated_at":"2026-05-28T03:31:27.517Z","avatar_url":"https://github.com/justinh-rahb.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🔴 ESP-Stop Button for 3D Printers\n\nThis project implements a simple emergency stop (E-Stop) button using an ESP8266 and a physical button.\n\nWhen pressed, it sends a command to a server, smart device, or 3D printer, depending on the selected mode. Supported integrations include:\n\n- **OctoPrint** (3D printer)\n- **Moonraker / Klipper** (3D printer)\n- **Bambu Lab** (3D printer via MQTT)\n- **TP-Link Kasa** (local LAN smart plugs/switches)\n\n\u003e [!NOTE]\n\u003e Your printer must be running a compatible server (OctoPrint or Moonraker) that accepts G-code commands via HTTP POST. For Bambu Lab printers, the button uses MQTT over TLS. For Kasa devices, the button communicates directly via the LAN.\n\n\u003e [!CAUTION]\n\u003e \u003e This is a **software** E-Stop button. It does not cut physical power or ensure printer safety.\n\u003e \u003e\n\u003e \u003e **Use at your own risk.** This project provides **no hardware safety mechanisms**.\n\u003e \u003e\n\u003e \u003e We are **not responsible** for any damage or injury.\n\n## 📚 Table of Contents\n- [✨ Features](#-features)\n- [🧰 Hardware](#-hardware)\n- [🖥️ PlatformIO Usage](#️-platformio-usage)\n  - [Example:](#example)\n- [📦 Pin Configuration](#-pin-configuration)\n- [⚙️ Configuration Fields](#️-configuration-fields)\n- [📡 API Logic](#-api-logic)\n- [📚 Requirements](#-requirements)\n- [📜 License](#-license)\n\n## ✨ Features\n\n- **Dynamic Web Interface** - Smart configuration UI that adapts based on printer type\n  - Field labels and hints update automatically when selecting printer type\n  - Context-aware placeholders and help text for each integration\n  - Clean, modern design with responsive layout\n- **WiFiManager** captive portal for first-time setup\n- **Smart Button Controls**:\n  - Short press: Send emergency stop command\n  - Hold 1.5s: Open configuration portal\n  - Hold 3s: Factory reset\n- **Improved TP-Link Kasa Support**:\n  - Single outlet devices (HS100, HS103, KP115, etc.)\n  - Multi-outlet power strips (HS300, KP303, etc.)\n  - Special handling for KP200 dual-outlet quirks\n- **Immediate Klipper E-Stop**:\n  - Uses `/printer/emergency_stop` endpoint for instant shutdown\n  - Falls back to `/printer/gcode/script` if endpoint unavailable (custom Klipper builds)\n  - No waiting for command queue like standard M112\n- **Bambu Lab MQTT Support**:\n  - Direct MQTT/TLS connection to printer (port 8883)\n  - Sends emergency stop command to halt prints immediately\n  - Secure connection with access code authentication\n- **Persistent Configuration** in EEPROM\n- Configurable:\n  - Base URL (or local IP for Kasa/Bambu)\n  - API Key / Access Code (if needed)\n  - G-code / Command / Serial Number\n  - Server type: `octo`, `moon`, `kasa`, or `bambu`\n- Debounced button input with visual LED feedback\n- LED status indicators for all operations\n\n## 🧰 Hardware\n\n- ESP8266 board (e.g., NodeMCU or Wemos D1 Mini)\n- Momentary pushbutton\n- Optional: LED with 330Ω resistor\n\n## 🖥️ PlatformIO Usage\n\n```bash\nmake build           # Compile the firmware\nmake upload          # Upload to ESP8266 (use PORT=/dev/ttyUSB0 if needed)\nmake monitor         # Open serial monitor\nmake clean           # Clean build\n````\n\n### Example:\n\n```bash\nmake upload PORT=/dev/ttyUSB0\nmake monitor\n```\n\n## 📦 Pin Configuration\n\n| Function | Pin | Notes                 |\n| -------- | --- | --------------------- |\n| Button   | D1  | Pulled-up input       |\n| LED      | D2  | Active LOW by default |\n\n## ⚙️ Configuration\n\n### Web Interface\n\nAfter connecting to WiFi, access the configuration page at `http://\u003cdevice-ip\u003e/`\n\nThe web interface provides:\n- Current configuration status\n- WiFi signal strength\n- **Dynamic configuration editor** - field labels and hints automatically update based on selected printer type\n- Factory reset option\n\n#### Dynamic Configuration UI\n\nThe configuration form intelligently adapts to the selected printer type:\n\n- **OctoPrint**: Shows \"Base URL\", \"API Key\", and \"G-code Command\" with OctoPrint-specific guidance\n- **Moonraker/Klipper**: Shows \"Moonraker URL\" with port hint, explains emergency_stop endpoint\n- **Kasa**: Shows \"Device IP\", clarifies API key not needed, explains outlet switch commands\n- **Bambu Lab**: Shows \"Printer IP\", \"Access Code\", and \"Printer Serial Number\" with specific instructions\n\nThis makes configuration straightforward - just select your printer type and the form guides you through the required fields!\n\n### WiFiManager Portal\n\nWhen first powered on (or after reset), a captive portal will appear:\n\n📶 **SSID**: `EstopConfigAP`\n\n### Configuration Fields\n\n| Field       | Example                      | Notes                                            |\n| ----------- | ---------------------------- | ------------------------------------------------ |\n| Base URL    | `http://192.168.0.150:7125`  | For Octo/Moon: full server URL\u003cbr\u003eFor Kasa/Bambu: just IP address |\n| API Key     | `abc123...`                  | OctoPrint / Moonraker: API key\u003cbr\u003eBambu: Access Code (from printer settings)\u003cbr\u003eNot used for Kasa |\n| G-code      | `M112` or `on0` / `off1`     | Octo/Moon: G-code command\u003cbr\u003eKasa: switch command\u003cbr\u003eBambu: Printer Serial Number |\n| Server Type | `octo`, `moon`, `kasa`, or `bambu` | Determines how the command is sent               |\n\n### Accessing Configuration\n\nYou can reconfigure the device in three ways:\n1. **Web Interface**: Navigate to `http://\u003cdevice-ip\u003e/config`\n2. **Button Hold**: Hold button for 1.5 seconds to open config portal\n3. **Factory Reset**: Hold button for 3 seconds to clear all settings\n\n\u003e \\[!WARNING]\n\u003e\n\u003e \u003e API keys are stored in EEPROM and sent in plaintext. Do **not expose** this device to the public internet.\n\u003e \u003e\n\u003e \u003e Use a restricted-scope API key, and secure your network appropriately.\n\n## 📡 API Logic\n\n| Server Type | Target                       | Protocol | Payload Format                                                    | Header / Method                      |\n| ----------- | ---------------------------- | -------- | ----------------------------------------------------------------- | ------------------------------------ |\n| `octo`      | `/api/printer/command`       | HTTP     | `{ \"command\": \"M112\" }`                                           | `X-Api-Key: \u003ckey\u003e` (POST)            |\n| `moon`      | `/printer/emergency_stop`    | HTTP     | Empty (for M112)\u003cbr\u003e`{ \"script\": \"\u003ccmd\u003e\" }` (for other commands) | `Authorization: Bearer \u003ckey\u003e` (POST) |\n|             | `/printer/gcode/script`      |          | Fallback if emergency_stop returns 404                            |                                      |\n| `bambu`     | `device/\u003cserial\u003e/request`    | MQTT/TLS | `{\"print\":{\"command\":\"stop\",\"param\":\"\"}}`                         | Username: `bblp`, Password: Access Code (Port 8883) |\n| `kasa`      | Local device IP, port 9999   | TCP      | Auto-detects single vs multi-outlet format                        | Encrypted XOR payload via raw TCP    |\n\n### Kasa Command Formats\n\nThe firmware automatically detects device type and uses the appropriate format:\n\n**Single Outlet Devices** (HS100, HS103, KP115):\n```json\n{\"system\":{\"set_relay_state\":{\"state\":1}}}\n```\n\n**Multi-Outlet Devices** (HS300, KP303):\n```json\n{\"context\":{\"child_ids\":[\"\u003coutlet_id\u003e\"]},\"system\":{\"set_relay_state\":{\"state\":1}}}\n```\n\n**Command Syntax**:\n- `on` / `off` - Control outlet 0\n- `on0` / `off0` - Control outlet 0 explicitly\n- `on1` / `off1` - Control outlet 1\n- `0` / `1` / `2` - Turn on outlet N\n\n### Bambu Lab Configuration\n\nFor Bambu Lab printers, the device connects via MQTT over TLS (port 8883):\n\n**Required Settings**:\n- **Base URL**: Printer's IP address only (e.g., `192.168.1.100`)\n- **API Key**: Access Code from printer settings (Settings → Network → Access Code)\n- **G-code Field**: Printer Serial Number (found in Bambu Studio or printer network settings)\n\n**Emergency Stop Command**:\n```json\n{\"print\":{\"command\":\"stop\",\"param\":\"\"}}\n```\n\nPublished to MQTT topic: `device/\u003cserial\u003e/request`\n\n**MQTT Connection**:\n- Broker: The printer itself\n- Port: 8883 (MQTT over TLS)\n- Username: `bblp`\n- Password: Access Code\n- TLS: Required (certificate verification disabled for self-signed cert)\n\n## 📚 Requirements\n\n* [PlatformIO](https://platformio.org/)\n* ESP8266 board platform\n* Auto-installed libraries (via `lib_deps` in `platformio.ini`):\n\n  * `WiFiManager`\n  * `ESP8266HTTPClient`\n  * `PubSubClient` (for Bambu MQTT support)\n  * `EEPROM`\n\n## 📜 License\n\nMIT Licensed – see [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinh-rahb%2Fesp-stop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinh-rahb%2Fesp-stop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinh-rahb%2Fesp-stop/lists"}