{"id":20483958,"url":"https://github.com/martin-ger/esp8266-wifi-socket","last_synced_at":"2025-04-13T14:35:19.979Z","repository":{"id":108933876,"uuid":"122332359","full_name":"martin-ger/ESP8266-WiFi-Socket","owner":"martin-ger","description":"Custom SW for the OBI \"Wifi Stecker Schuko\"","archived":false,"fork":false,"pushed_at":"2018-10-10T07:56:55.000Z","size":1630,"stargazers_count":64,"open_issues_count":1,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-27T05:34:51.304Z","etag":null,"topics":["acs712","esp8266","esp8266-arduino","obi","socket","switch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martin-ger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-02-21T12:16:49.000Z","updated_at":"2024-09-10T12:12:49.000Z","dependencies_parsed_at":"2023-03-10T15:01:09.737Z","dependency_job_id":null,"html_url":"https://github.com/martin-ger/ESP8266-WiFi-Socket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-ger%2FESP8266-WiFi-Socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-ger%2FESP8266-WiFi-Socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-ger%2FESP8266-WiFi-Socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-ger%2FESP8266-WiFi-Socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martin-ger","download_url":"https://codeload.github.com/martin-ger/ESP8266-WiFi-Socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248729000,"owners_count":21152329,"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":["acs712","esp8266","esp8266-arduino","obi","socket","switch"],"created_at":"2024-11-15T16:19:21.420Z","updated_at":"2025-04-13T14:35:19.968Z","avatar_url":"https://github.com/martin-ger.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESP8266 WiFi-Socket\nCustom SW for the \"Wifi Stecker Schuko\"\n\n*WARNING: This devices uses mains power! For good reasons it is not build to be opened and if you do so, you are responsible for your life! Never ever touch it or connect it to your computer when connected to mains.*\n\nGerman DIY market OBI is selling a WiFi socket (look for item \"OBI 2291706\"). It contains an ESP chip, two LEDs, a push button, power supply \nand a relay in a socket case. \n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180221_160706_s.jpg\"\u003e\n\n## Hardware\nOpening the case is somewhat tricky as they used deep lying \"never-seen-before-screws\" (\"tri-star\"), but with a little bit of drilling I managed it. The main board has the relay, the button, two LEDs, the power supply (the low voltage part of my modul runs at about 6.5V), an LDO 3.3V voltage regulator, and an ESP8266 on a separate daughter board:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180221_130652_s.jpg\"\u003e\n\nYou can nicely read the names of the ESP pins on the daughter board:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180221_131028_s.jpg\"\u003e\n\nThe ESP modul is named \"OW8266-02Q\" (most probably the same as the WT8266-S1 \"Wireless Tag\" http://www.seeedstudio.com/document/word/WT8266-S1%20DataSheet%20V1.0.pdf - at least I found the ADC - by trial and error):\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/ESP8266-WiFi-Socket/master/IMG_20180329_082642_s.jpg\"\u003e\n\nSoldering a pin header onto the board isn't a big deal (I first soldered it on straight and bend it down afterwards):\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180221_150011_s.jpg\"\u003e\n\nThis even fits into the case when flashing is done:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180221_152842_s.jpg\"\u003e\n\n## Flashing\nFlashing follows the usual procedure for the ESP:\n- Make sure you are DISCONNECTED from mains power (3,3V is enough)\n- Get your USB-UART adapter\n- Connect 3,3V, GND, Rx-Tx, Tx-Rx, GPIO0-GND\n- Power it up\n- Flash it using your favourite flash tool and an appropriate software\n\n## Programming\nThe device has the following pin assignment:\n- GPIO4 - blue WiFi LED\n- GPIO5  - Relay off (LOW pulse)\n- GPIO12 - Relay on (LOW pulse)\n- GPIO14 - Push Button\n\nIt is reported that when holding GPIO12 LOW, the Relay can also be switched by simply turning GPIO5 HIGH and LOW. There is a Tasmota mapping that uses these settings: https://github.com/arendst/Sonoff-Tasmota/issues/1988\n\n### Power Measurement\nUp to now the socket is somewhat smart. But there is plenty of space left in the case, so I decided to make it really smart and add a power measurement. I used an ACS712 hall effect current sensor that converts current values into voltage. I used the 5A version. The ACS712 has to be powered with 5V, so it needs an additional AMS1117-5 voltage regulator. The output of the ACS712 is in the range from 0-5V (with a 0 offset of 2.5V, i.e. if there is no current, the output is 2.5V). Before feeding it into the ESP's ADC it has to be divided with two resistors to 1V max.:\n \n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/IMG_20180331_085945_445.jpg\"\u003e\n\nYou can get the 6,5V from here:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/ESP8266-WiFi-Socket/master/IMG_20181010_094654095s.jpg\"\u003e\n\nCould be nicer, but it all fits into the case:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/ESP8266-WiFi-Socket/master/IMG_20180521_201028_s.jpg\"\u003e\n\nWhen you are using WiFi, make sure to set wifi_set_sleep_type(NONE_SLEEP_T), otherwise the ADC will produce some more random noise. The Arduino sketch will do the job for a ACS712 with max current of 5A and 230V. It computes the effective voltage by integrating over a multiple of the period and computes the current and the power consumption since the start of the sketch. These values are published via MQTT and can be fed e.g. in NodeRed:\n\n\u003cimg src=\"https://raw.githubusercontent.com/martin-ger/WiFi-Socket/master/Sceenshot_NodeRed.jpg\"\u003e\n\n### Arduino Sketch\nIn this repository you find a basic Arduino sketch that reads the pushbutton and connects to an MQTT server (https://github.com/martin-ger/ESP8266-WiFi-Socket/blob/master/OBISocket.ino). Find the basic WiFi and MQTT config in first lines of the sketch.\n\nIf you enable the define of ENABLE_POWER_MEASUREMENT, power measurement with the ACS712 will be included.\n\n### MQTT Broker Script\nThere is also a sample script for my MQTT Broker/Bridge, an alternative firmware that turns the switch into a OTA programmable MQTT client and broker. For further instructions see: https://github.com/martin-ger/esp_mqtt\n\nOn the CLI define the two flash variables @1 with the device number and @2 with the systems prefix and configure WiFi and the remote MQTT broker, e.g.:\n```\nset @1 0\nset @2 myhome\nset ssid MyWiFiSSID\nset ap_ssid MQTTbroker\nset ap_password stupidPassword\nset password MyWiFiPassword\nset mqtt_host test.mosquitto.org\n```\nNow you can send \"0\" or \"1\" MQTT messages to the topic @2/obiswitch/@1/command (in this example \"myhome/obiswitch/0/command\") and the switch will turn on and off. You can send the messages either to the given remote MQTT broker (in this example \"test.mosquitto.org\") or to the switch itself (use the IP of the switch). You might connect to the switch eiter via the home WiFi (in this example \"MyWiFiSSID\") or directly to the AP of the switch (in this example \"MQTTbroker\" with pw \"stupidPassword\").\n\nYou can also toggle the status locally using the button on the device. The blue LED will start to blink as soon as the switch has WiFi connectivity.\n\nThe retained topic @2/obiswitch/@1/status (in this example \"myhome/obiswitch/0/status\") will always report on the current state of the switch.\n\nHere is this script - you can install it directly OTA via this link: https://raw.githubusercontent.com/martin-ger/ESP8266-WiFi-Socket/master/script.obi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin-ger%2Fesp8266-wifi-socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartin-ger%2Fesp8266-wifi-socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin-ger%2Fesp8266-wifi-socket/lists"}