{"id":789,"date":"2016-09-15T20:56:34","date_gmt":"2016-09-15T19:56:34","guid":{"rendered":"http:\/\/EvertDekker.com\/?p=789"},"modified":"2023-01-01T15:24:28","modified_gmt":"2023-01-01T14:24:28","slug":"sonoff-powerswitch-mod","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=789","title":{"rendered":"Sonoff Wifi powerline switch mod"},"content":{"rendered":"<hr \/>\n<p>Found this interesting Wifi power switch on Ebay for only $6,11.\u00a0 It&#8217;s not clear to me if this is the original design or a copy of it. Detailed info can be found on this <a href=\"https:\/\/www.itead.cc\/wiki\/Sonoff\">Wiki page<\/a>.<\/p>\n<figure id=\"attachment_813\" aria-describedby=\"caption-attachment-813\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/2016\/09\/Sonoff-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-813 size-medium\" src=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/2016\/09\/Sonoff-1-300x239.jpg\" width=\"300\" height=\"239\" srcset=\"https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/2016\/09\/Sonoff-1-300x239.jpg 300w, https:\/\/evertdekker.com\/wp\/wp-content\/uploads\/2016\/09\/Sonoff-1.jpg 727w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-813\" class=\"wp-caption-text\">Sonoff TH powerline switch<\/figcaption><\/figure>\n<p>To connect it to my Mqtt broker and <a href=\"http:\/\/www.evertdekker.com\/wp\/?cat=18\">domotica<\/a> I wanted to make my own firmware.<br \/>\nEasy said, easy done. There are plenty example on the net how to do this. Because there&#8217;s an esp8266 inside there are also numerous Arduino software example available.<br \/>\nFirst step was soldering a header to the empty programming socket and connect my Usb to serial adapter to it. Take a note that you must have a 3.3V usb to serial adapter, they can be found for under a dollar on ebay. Don&#8217;t know how they can make it for that amount and even send it to the other side of the world.<br \/>\nConnected the usb adpater to my pc and voila, I&#8217;m in. Keep also in mind <span style=\"text-decoration: underline;\">not connect<\/span> it to the mains when connected to your pc. Both powersupply&#8217;s are not happy with each other.<br \/>\nSimple led blink program was working, connecting to wifi was also working, but unfortunately the <strong>red led<\/strong> and <strong>ota<\/strong> (over the air) update was not working.<br \/>\nThe ota was complaining that the authentication was not correct and I was sure it was correct.<br \/>\nAfter lot of Googleing and some tries it was clear that the memory settings in the Arduino ide where not correct, but what must it be then?<br \/>\nThis setup was working for me, cant say it will work for all Sonoff versions, but you can try setting the ide like this.<br \/>\n<em>\/* <\/em><br \/>\n<em>\u00a0\u00a0\u00a0 Gerneric Esp8266 Module: Flash Mode: DIO, Flash Frequency: 40MHz, CPU Frequency: 80MHz<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 Flash Size: 1M (64K SPIFFS), Debug Port: Disabled, Debug Level: None,\u00a0 Reset Method: ck<\/em><br \/>\n<em>\u00a0*\/<\/em><\/p>\n<p>Now the red led.<br \/>\nIn some Arduino code that I found they say that the red led will lit when the relay will be activated. But both didn&#8217;t work. Red led and relay didn&#8217;t worked. Relay was simply fixed, it needed the 5V from the Sonoff build in power supply, connected to the mains and the relay worked, but still no red led.<br \/>\nLooking at the <a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/Downloads\/Sonoff_TH_Schematic.pdf\">schematic<\/a> and the pcb some critical components for the led where not placed. Q3, Q4, R2 and R23 are not placed.<br \/>\nQ3 and R2\/22 are used for the Sonoff version that have also the 433Mhz receiver. Q4 and R23 are used to lit the red led if the relay is activated.<br \/>\nBoth are not placed, so that&#8217;s why the led will not lit. If you want to let the red led work together with the relay, just place Q4 (2N7002) and R23 (1K) and it works.<br \/>\nHowever I wanted the red led under software control and decided to use one of the free gpio ports from the Esp8266.<br \/>\nSoldered a wire from gpio4 (pin16) on the Esp8266 to the drain of Q3. See the pictures below for details.<\/p>\n<p>That&#8217;s it everything working as wanted.<\/p>\n<div class=\"n2_ss_slider_publish__option_code\" dir=\"ltr\" data-mode=\"id\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Found this interesting Wifi power switch on Ebay for only $6,11.\u00a0 It&#8217;s not clear to me if this is the original design or a copy of it. Detailed info can be found on this Wiki page. To connect it to my Mqtt broker and domotica I wanted to make my own firmware. Easy said, easy [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[130,129,135,134],"class_list":["post-789","post","type-post","status-publish","format-standard","hentry","category-esp8266","tag-arduino","tag-esp8266","tag-red-led","tag-sonoff"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=789"}],"version-history":[{"count":28,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/789\/revisions"}],"predecessor-version":[{"id":1720,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/789\/revisions\/1720"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}