{"id":21014983,"url":"https://github.com/ogd09/cplug","last_synced_at":"2026-05-07T18:12:27.899Z","repository":{"id":263329164,"uuid":"889626896","full_name":"OGD09/cplug","owner":"OGD09","description":"This project transforms an ESP32 microcontroller into a smart plug, controllable via a relay. It features a web interface for network-based API control and an I2C LCD for real-time feedback like connection status and control URLs.","archived":false,"fork":false,"pushed_at":"2024-11-19T02:16:17.000Z","size":9917,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T12:06:11.615Z","etag":null,"topics":["arduino","arduino-library","esp32","home-automation","iot","iot-device","relay-switch","smart-home","smart-plug","web-api"],"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/OGD09.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-11-16T20:04:07.000Z","updated_at":"2024-11-20T06:17:22.000Z","dependencies_parsed_at":"2024-11-17T22:25:09.352Z","dependency_job_id":"6fa26bbb-870d-4776-9ab7-cd7985c9dfd0","html_url":"https://github.com/OGD09/cplug","commit_stats":null,"previous_names":["ogd09/cplug"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fcplug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fcplug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fcplug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fcplug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OGD09","download_url":"https://codeload.github.com/OGD09/cplug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243441914,"owners_count":20291558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","arduino-library","esp32","home-automation","iot","iot-device","relay-switch","smart-home","smart-plug","web-api"],"created_at":"2024-11-19T10:08:01.963Z","updated_at":"2026-05-07T18:12:27.855Z","avatar_url":"https://github.com/OGD09.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CPLUG\n\nThis project is a smart plug powered by an ESP32 microcontroller, which controls a relay to switch connected devices on or off. The relay can be controlled through a simple and intuitive web interface, using API calls over the network. The device also displays relevant information on an I2C LCD screen and includes a physical button for direct control of the relay, ensuring usability even without network access.\n\n### Assembled Device\n![diagram](img/cplug_diagram_clear.png)\n\u003cdiv style=\"display: flex; justify-content: space-around;\"\u003e\n  \u003cimg src=\"img/cplug.jpg\" alt=\"Assembled Device\" height=\"200\"\u003e\n  \u003cimg src=\"img/cguts.jpg\" alt=\"Device's guts\" height=\"200\"\u003e\n\u003c/div\u003e\n\n\n## Features\n\n1. **Wi-Fi Modes**:\n   - Connects to an existing Wi-Fi network using stored credentials.\n   - Creates an Access Point (AP) if no network credentials are available.\n\n2. **Dynamic LCD Display**:\n   - Displays the AP SSID and password when in AP mode without clients.\n   - Shows the URL for relay control when a client connects to the AP or when connected to Wi-Fi.\n\n3. **Physical Button Control**:\n   - Allows direct control of the relay.\n   - Button press takes priority over API or web-based control.\n\n4. **Web Interface**:\n   - Responsive relay control using modern AJAX (XHR).\n   - Displays the current relay state without page refreshes.\n\n5. **Non-Volatile Storage**:\n   - Saves Wi-Fi credentials using the ESP32's Preferences library.\n\n6. **Custom 3D-Printed Case**:\n   - A 3D-printable STL file for the case is included in the `assets` folder.\n\n## Requirements\n\n### Software\n- Arduino IDE or Arduino CLI\n- ESP32 Board Support Package\n- Required Libraries:\n  - `WiFi.h`\n  - `WebServer.h`\n  - `Preferences.h`\n  - `esp_wifi.h`\n  - `LiquidCrystal_I2C.h`\n\n### Hardware\n- **ESP32 Microcontroller**\n- **I2C LCD Display**: 16x2 with an I2C interface.\n- **Relay Module**\n- **Self-Lock Push Button**\n- **Voltage Converter**: Converts 110V-240V AC to 5V DC for the ESP32.\n- **NEMA 5-15R Socket**: A standard US receptacle for the relay-controlled device.\n- **IEC 320 C14 Socket (AS-05, AC 250 V, 10 A)**: Common power inlet for devices.\n\n**Note**: See the [Hardware](#hardware) section below for links to the components used.\n\n## Installation\n\n1. Clone this repository or copy the source code to your local machine.\n2. Open the project in Arduino IDE or place it in a suitable directory for the Arduino CLI.\n3. Install the required libraries:\n   - Use the Arduino Library Manager or Arduino CLI.\n   - Ensure the ESP32 board package is installed.\n4. Connect your ESP32 and upload the code.\n\n## Usage\n\n1. **Initial Configuration**:\n   - When powered on for the first time, the ESP32 will start in AP mode. The LCD will display the SSID and password for the AP.\n   - Connect to the AP, and a captive portal will automatically open, guiding you to the network configuration page.\n   - Navigate through the captive portal to configure Wi-Fi credentials.\n\n2. **Relay Control**:\n   - Access the web interface at the URL displayed on the LCD to toggle the relay state.\n   - Press the physical button to control the relay directly. The button press overrides web control.\n\n3. **LCD Display**:\n   - Shows the current mode and necessary connection details:\n     - AP mode without clients: SSID and password.\n     - AP mode with clients: URL for relay control.\n     - Wi-Fi connected: URL for relay control.\n\n## Hardware\n\n| Component                     | Description                                     | Link                     |\n|-------------------------------|-------------------------------------------------|--------------------------|\n| ESP32 Microcontroller         | The heart of the project.                      | [Link](https://www.amazon.com/DORHEA-Development-Bluetooth-ESP-WROOM-32-ESP32-DevKitC-32/dp/B0B18JQF16/ref=sr_1_4?crid=25G7VGNAWT774\u0026dib=eyJ2IjoiMSJ9.aR60pLT4ci7QASJykSqRfgGDG_jUr8SiNvrNmjAwDhDlvNy0StOQUgZXOfjYzId7mAdCB_HcCIMW05vQNfdyvUsbEBINIsiMudzG0CskZdi4rJSzAG7vivwW1w1u0zIILp9qtYudKr-yfV62xQc7B36pVaGWQckNOdX2xZdajdN8TSqnIwYr5pD6b5dRtL5Jnndt4iDOWy_oneP7mcrX-r2XoSbTcFxIw1wvP1exjfk.WI5xbtAzXLtw3q7DZOykH-29DSS3rbJIN8vR7MnfGZs\u0026dib_tag=se\u0026keywords=esp32%2Btype%2Bc\u0026qid=1731796381\u0026sprefix=esp32%2Btype%2Bc%2Caps%2C92\u0026sr=8-4\u0026th=1)               |\n| I2C LCD Display (16x2)        | Displays connection details and status.        | [Link](https://www.amazon.com/Freenove-Display-Compatible-Arduino-Raspberry/dp/B0B76Z83Y4/ref=sr_1_8?crid=22722MO4DGRTJ\u0026dib=eyJ2IjoiMSJ9.FgsyN-p9btDlxidPTK0VokPyhYbPLtrx6CIymEFmeu8HquPf1mye9_E3q4YqeJaCkussmozj30rz006pS-j-Zxs4xNDP58nwopVfpcqb5vmIXURN5D7p3oDzlXHki8dlP-cNjHTlMKlta6xKRd9v_0Njw1XWCWGWeQhFLQtSgclvgg-do2hPTlyNWCtahsDMEHyzilTH4SX9fIQR_nQql1cxyts22M1cXowWT20wPd4.-sOvicqK9vaTRdz1Plc3fm6ynNQ2crNDuc7zpBJGeSI\u0026dib_tag=se\u0026keywords=I2C%2BLCD%2BDisplay\u0026qid=1731796307\u0026sprefix=i2c%2Blcd%2Bdisplay%2Caps%2C95\u0026sr=8-8\u0026th=1)               |\n| Relay Module                  | Controls the electrical load.                  | [Link](https://www.amazon.com/Channel-Optocoupler-Isolated-Control-Arduino/dp/B07XGZSYJV/ref=sr_1_1?crid=PB1JA4J1TX9N\u0026dib=eyJ2IjoiMSJ9.aQ-rgB_Q-5VmyzSnoas2VhAkGjDhkILgD44Dnr2wRspw5Qp-LtaFXKKteFBa6X0ESbHH3MFNPzqsRRI1MOM1pVOcQiMHu4wNWgSGydyyO5NViYg3PHuXdIyPeQO-Xdltw8nPeWVZu8tJ9F3oZQ0nuQKFwaEkmtkYS0zkeis_vLL8fPbUh_z2U8_lRga2iK3UqjJLn6YKg0ZaioaMUuxjz0blPndgwRlDTCBhTjAGsyA.LGNlUcpLCycIGoVbeYfQDlwwR6OLPRAMTPuAvHs4J60\u0026dib_tag=se\u0026keywords=3.3+relay\u0026qid=1731796264\u0026sprefix=3.3+relay%2Caps%2C83\u0026sr=8-1)               |\n| Self-Lock Push Button         | Physical control of the relay.                 | [Link](https://www.amazon.com/Cylewet-Self-Locking-Latching-Button-CYT1091/dp/B075VBV4QH/ref=sr_1_8?crid=2KIK6ERG6BN0P\u0026dib=eyJ2IjoiMSJ9.Q0Cky4G0VZEtxUhetpGEcxkMA4g-0cejM6OzH7_EqwUG9l5s5uOP1NEe5xEu8aJlvH95Yr8B_k_6FD0LmWNwg297Td6C2Q40oG79wqW1Mavb5yGUdd6I5zddKtIvo89kQhaZNkyTd7MNJApQMUDWBUe8McBYsr18a85pK4X5KR-wpG2o6DsRET8pg1xFFyVLgSGe1A-SvmKNQ_pOElTnC_GC8kSqcHhYo9mFrb67JTE.0K4n9P1OeurHzMgPb1lFyRd3By2fWrSc6MVZ3T9eJJo\u0026dib_tag=se\u0026keywords=Self-Lock+Push+Button\u0026qid=1731796223\u0026sprefix=self-lock+push+button%2Caps%2C91\u0026sr=8-8)               |\n| Voltage Converter (110V-240V to 5V) | Powers the ESP32 from AC mains.               | [Link](https://www.amazon.com/Converter-Universal-Isolated-Switching-Version/dp/B07YXN8J6R/ref=sr_1_1?crid=3UPM554FWAPQ8\u0026dib=eyJ2IjoiMSJ9.zdqFicpFqyz1Z1tKWYnlpaLNMNrL8BoeqXUJ9g36tAzf7-meuGKPv8ctHFgPLYjgOYwsBWNwN3GqHpw6QOvg71q2i0jv1dObiiWN8LbpopJY6PtrnOiq0knwtIwI-0cHBaqu2N2BawjL0qkS1LwS2MJjvldHY9Mg5hg3434L-A1usjyi52DSxShrEv_PcLvCWp9L1CMRB3rPMPzA7B3d2Jn77lkj-A-EeUfR-7l4ozw.UM5AheMT8vLujvvUIKo2IlyK4jw8GPB3GHP7dHmLKUI\u0026dib_tag=se\u0026keywords=110v%2Bto%2B5v%2Bconverter\u0026qid=1731796176\u0026sprefix=110v%2Bto%2B5v%2Bconverter%2Caps%2C83\u0026sr=8-1\u0026th=1)           |\n| NEMA 5-15R Socket             | Standard US receptacle for connected devices.  | [Link](https://www.amazon.com/Leviton-1374-1-Receptacle-Straight-Grounding/dp/B0036ZA94S/ref=sr_1_1?crid=UHHV8AGXBC5B\u0026dib=eyJ2IjoiMSJ9.M0yUuQhHRnbxlmw__q1OQsjqiKK7Lzq-amBfNVHlUW3exoDVYdswoF4ccXi6TsctIF8pWhs2Qt5tf9ZHR8Z3b-TRseGydRwAubybP-5LmzyA4aRBD0qzCH1_tI_36UB1UWPJrbrNoz-0z4Qh6lH24Ce0I3_k8kpyx9AwWENTZDqyTovK3UAqsOv-Pujo6GcT32IMqSibLjM9dkEyyaP4l4SMC7syEMpwJ5QJnx4_aUpSXjkJQjaKH2TC8sQSaJGlR4VdoFqvllPZVTFponQ8T_omKow75SovG-NTfQMWdIE.1HBg6GjAmhffm_9SL_MLdXJNd9bSK1kwkIMoonTajvM\u0026dib_tag=se\u0026keywords=Leviton+1374-1\u0026qid=1731796140\u0026sprefix=leviton+1374-1%2Caps%2C85\u0026sr=8-1)          |\n| IEC 320 C14 Socket (AS-05)    | Power inlet for AC connections.                | [Link](https://www.amazon.com/Baomain-Panel-Power-Socket-Connector/dp/B00WFYS1HS/ref=sr_1_1?crid=2AH4T4U21RJY0\u0026dib=eyJ2IjoiMSJ9.o2AdHKFsyHimIjMr6q8nZA8UOt_GoRbGCrPzT085l6LmGa75eYUp2Iu93e91JlG-ZjGe-yor4HFuf1mvtRVtcm5KmduDByGhFHxt-kzASViMKf0OOzjHaLeEWpvepVyfPifnHwS5HujjkfdvMaR1ys0JTfGZoBOZZayyiODlNlgXQRUbeBY8whl7jbCTqxhqqfOeOG1r7tnm2FsTqq1ykwNWGQkgUMIFuup9lu8L_98.qGuYcbvfJGRp2hODLt11jA4VYX2CxGktAQs5OteeDsE\u0026dib_tag=se\u0026keywords=IEC%2B320%2BC14%2BAS-05%2BAC%2B250%2BV%2B10%2BA\u0026qid=1731795545\u0026sprefix=iec%2B320%2Bc14%2Bas-05%2Bac%2B250%2Bv%2B10%2Ba%2Caps%2C54\u0026sr=8-1\u0026th=1)             |\n| M3 Inserts    | M3 insert for lid locking.                | [Link](https://www.amazon.com/cSeao-120pcs-Inserted-Knurled-Embedded/dp/B07D683Q26/ref=sr_1_11?crid=N839MT9MEB0\u0026dib=eyJ2IjoiMSJ9.BwFSXFaGs6U0QlD21q7anfRjKx8fcWIVVXDrKtU1Yo7g1lHY48A7-26837xuO4F2Ssg_Sx_ynNHAGdIvsNa2ThFNgQkNyX-LUT8ivDBEAd1eKuCpKPvQGEbBa7O8YMQSP-sqK79dW-2i68HhO7yJYukDzecnrYyhUKayA2AelA53HvCPMeghReTvODpibVUNhc8p1PKd9ht5c3eqeiXtetUtZ2ZAUWoDsGnleXf0IsY.E7LUj37njgflZGeeeHaksSZCL2Vs69lXinDTYqzEfZo\u0026dib_tag=se\u0026keywords=3mm+insert\u0026qid=1731796825\u0026sprefix=3mm+insert%2Caps%2C80\u0026sr=8-11)             |\n| M3 screws    | M3 screws.                | [Link](https://www.amazon.com/Taiss-Screws-Stainless-Assortment-Wrenches/dp/B0CS6FVH6G/ref=sr_1_8?crid=1H1JREBPXZQUU\u0026dib=eyJ2IjoiMSJ9.ddCR5pjnGHbNJnXCOUJw9qTYo5zl7m08eLFdJc_fUtLRGMkxWxlrKIeJRBhaxZ-7rclPpb1MD236MeDwbb92bc4457UzaqqOPV6YFWt8ndilpIteXFTdQuuw4t4ZTmg5bL-p11dq7-HYxKo1yEmvMhUmdP8x4jqDqpTak4yG87hJNuASfoKwtGaksukNju9o2aWLTVBIhzuyhQ2MUTj1Gw78WoBxLgUfNBVZSBipvT4.FapOMKETEi3edFoJWFkEY2h6Zcm_MxtBZEvy5e0q5_o\u0026dib_tag=se\u0026keywords=3mm+screws\u0026qid=1731796914\u0026sprefix=3mm+screws%2Caps%2C86\u0026sr=8-8)             |\n\n\n\n## Custom Case\n\n- A 3D-printable case designed for this project is available in the `assets` folder.\n- The STL file can be printed with standard PLA or ABS material without support.\n\n## Example Web Interface\n\n- **Relay State**: Displays whether the relay is `ON` or `OFF`.\n- **Toggle Button**: Instantly toggles the relay state.\n- Uses modern AJAX (XHR) for a seamless user experience.\n\n## Known Issues and Future Improvements\n\n1. **Button Behavior**:\n   - Relay state may not update on the web interface while the button is pressed. This behavior is by design to prioritize physical control.\n\n2. **Suggestions**:\n   - Add password protection to the web interface for enhanced security.\n   - Include OTA (Over-the-Air) updates for easier firmware management.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogd09%2Fcplug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fogd09%2Fcplug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogd09%2Fcplug/lists"}