Sonoff Wifi powerline switch mod

Found this interesting Wifi power switch on Ebay for only $6,11.  It’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.

Sonoff TH powerline switch

To connect it to my Mqtt broker and domotica I wanted to make my own firmware.
Easy said, easy done. There are plenty example on the net how to do this. Because there’s an esp8266 inside there are also numerous Arduino software example available.
First 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’t know how they can make it for that amount and even send it to the other side of the world.
Connected the usb adpater to my pc and voila, I’m in. Keep also in mind not connect it to the mains when connected to your pc. Both powersupply’s are not happy with each other.
Simple led blink program was working, connecting to wifi was also working, but unfortunately the red led and ota (over the air) update was not working.
The ota was complaining that the authentication was not correct and I was sure it was correct.
After 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?
This setup was working for me, cant say it will work for all Sonoff versions, but you can try setting the ide like this.
/*
    Gerneric Esp8266 Module: Flash Mode: DIO, Flash Frequency: 40MHz, CPU Frequency: 80MHz
    Flash Size: 1M (64K SPIFFS), Debug Port: Disabled, Debug Level: None,  Reset Method: ck
 */

Now the red led.
In some Arduino code that I found they say that the red led will lit when the relay will be activated. But both didn’t work. Red led and relay didn’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.
Looking at the schematic and the pcb some critical components for the led where not placed. Q3, Q4, R2 and R23 are not placed.
Q3 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.
Both are not placed, so that’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.
However I wanted the red led under software control and decided to use one of the free gpio ports from the Esp8266.
Soldered a wire from gpio4 (pin16) on the Esp8266 to the drain of Q3. See the pictures below for details.

That’s it everything working as wanted.

Wire connected to IO
Wire other side connected to Q3
Programmer connection
Usb 2 serial connection
Programmer connected to Sonoff
PlayPause
previous arrow
next arrow
 
Wire connected to IO
Wire other side connected to Q3
Programmer connection
Usb 2 serial connection
Programmer connected to Sonoff
previous arrow
next arrow
IoT Esp8266 Temperature and humidity sensor

This is my second project with the Esp-12-e module that contains the famous esp8266 from Espressif.
This sensor will connect to my Mqtt broker and send data to it. The broker will then with the help of Node red store it in an sqlite database and make some nice charts of it.
There are other similar sensor on the web, but I like to design and make my own. It’s my hobby and work.
The software will be writen with the Arduino ide for simple and quick design.
This is my second design now with Altium desiger. Switched from Eagle to Altium because Eagle has it’s limitation, not for this design but for more complexer. This board was not to difficult to start learning using Altium, and if I messed it up also not to expensive.

The hart of the board is the Esp-12-e module with a DHT22 Temperature and humidity sensor, all powered from a 16340 Li-ion battery that must last for at least a year. That’s what we hope.
The board contains also a ldo voltage regulator, led for debugging etc, some extra pads for  “you never know in the future” and a programming socket. This socket is only used ones to program in the OTA and after that updating the firmware can be done over the air.

For now there’s nothing more to see then the 3D images from Altium Designer. Pcb’s are ordered in China and I have to wait for 2~4 weeks before they are here.
The picture is the panalized version, but the download version is a single board.

 

Update 3/10/2016:
Boards are in.
After some quick testing the esp8266 was not always starting up. My mistake, I forgot the pull-up resistor(12k) on gpio2.
The esp8266 determines with the help of gpio 0,2 and 15 how it will boot. With the gpio2 floating this gave problems.
esp8266startup

Added the pull-up resistor (R7) already to the Altium files below. If there are no more errors maybe I going order some new pcb’s.

 

Update 14/10/2016:
I wrote a small test program to test the hardware and get some numbers out and from it. You can find the test program on github.
Hardware is working fine. DHT22 (btw is official a AM2302, see source ) temperature reading is slightly different from my (also uncalibrated) temperature meter. 0.4 °C is more then the 0.2°C according the datasheet, but I’m not sure how accurate the temperature meter is.
Humidity is even harder to say if it’s correct because I don’t have anything to compare with.
Current consumption is around 27μA with a supply voltage of 3.6V.
Calculated is 10μA for the Esp8266 + 8μA for the battery measure voltage divider + 4μA for the LDO quiescent current = 22μA.  Not bad result.
Because you can switch off the DHT22 completely by removing the power supply from it (gpio5) your not draining the additional 500μA standby current for this sensor. This will result in longer battery lifetime.

Update 7/10/2017:
Finally I got time to finish this project.
But what a disappointment, the battery on last for 1 day and we where hoping for a year 🙁 . Was sending every 30sec data to the mqtt broker and a collect and send data cycles from the esp8266 took 8 seconds.
So this made that the esp8266 120×8 seconds = 960 seconds = 16 minutes running every hour. 16min x 24 hours is 384 minutes. So the temperature and humidity sensor can run continue 384 minutes on a 3.6V Cr123a 1200mAh Li-io rechargeable battery. That’s not even that bad.
For longer battery life I optimized the code and reduced the data collect and send cycles time to 4 seconds. I’m now collecting the data during the periode that the wifi connection is setup, so that the total time that wifi is connected is reduced and with this the cycles time is down from 8 to 4.2 seconds.
I also changed the sample rate from 30sec to 5 minutes. This will bring down the running time 12×4.2 seconds=50 seconds every hour.
With this and a 2800mAh (Chinese specs) Cr123a battery that I ordered it should be possible to run 1 month from the battery, reducing the sample rate will even extend the battery life.
Pcb and battery where nicely fit in an Cr123a storage box, is no coincidence because the pcb was designed to fit in this box.

Update 11/03/2018:
It has been sometime ago with my last update.
What a drama with those Lithium-ion batteries, none of the batteries bought on ebay or Ali express have the capacity they promise. 1200mAh, 2800mAh forget it 250mAh is what you can get out of it. That’s why my first test with the sensor where that disappointed, if the battery only last 1/5 of the time promised 🙁
Bought now a Nitecore Li-Ion battery from Reichelt and now you know why this battery is 4x expensive then those from Ali-express, it was rated at 650mAh and after testing you could get 647mAh out of it, that’s better. The battery will last now for 1 month.
The second problem that occurs is that the DHT22 will stop working reliably below 3.3V. Bummer, the idea was that it should work down to 3.0V. Completely my fault and a bit of Adafruit. On there website was advertised that it works with 3.0V, however in the datasheet they talk about 3.3V, the rest of the internet (except those who copied Adafruit there text) are mentioning the 3.3V. Due this fault you can’t use a part of the battery charge because the sensor won’t work good.

With those problems in mind I decided to stop using the DHT22 and after some searching and reading the BME280 was the one the should do the job better. Have a look at this post to how this is going.

 

Design front Altium
Design bacl Altium
Pcb V3
Test setup V1
Finished pcb back
Programmer connected
Temperature validation
Standby power consumption
Data is coming in
Finished module with sensor
Finished box opened
Finished project
PlayPause
previous arrow
next arrow
 
Design front Altium
Design bacl Altium
Pcb V3
Test setup V1
Finished pcb back
Programmer connected
Temperature validation
Standby power consumption
Data is coming in
Finished module with sensor
Finished box opened
Finished project
previous arrow
next arrow

 

Altium 16 Design files V3

1858 Downloads

Tcp/ip gateway #2

 

UnderConstruction
For my Joshua domotica I needed a better tcp/ip gateway. The old gateway was only used as gateway, but this #2 revision will also be used as webserver to control the devices on the Joshua bus from a webpage so that it can be used from different mobile devices.

This new tcp/ip gateway will run on a Stm32F427 arm processor in combination with the Texas instruments ethernet phy DP83848. These combination is already tested and working well in this post.
For communication with the Joshua bus we have an Rs-485 driver, for storing images for the webpages  there’s a Sd card connected to the Stm32 with 4bit width sdio interface. There’s also an i2c eeprom on the pcb to store some specific Joshua network parameters.

To check the working of the gateway there’s a 320×240 color tft screen connected trough spi bus. This display uses the ILI9341 controller for the display and the XPT2046 for the touchscreen. The last one is fully compatible with the well known ADS7843.

For my previous arm projects i had used the Coocox ide, but after the update to the 2.xx version is become very crapy. Now I will use the Em::Bitz ide, known before as Em::Blocks.

 

Schematic sheet1
Schematic sheet 2
Finished pcb top
Finished pcb back
Pcb with display mounted
PlayPause
previous arrow
next arrow
 
Schematic sheet1
Schematic sheet 2
Finished pcb top
Finished pcb back
Pcb with display mounted
previous arrow
next arrow

 

If you want to make your own, or use parts of the design, feel free to download the design in Eagle.

1913 Downloads

Oldies Joshua Predecessor

The predecessor of my Joshua Domotica , here’s a more detailed overview of the electronics used.

 

Joshua predecessor controller board

First controller board for my domotica. Was running on a 8052AH Basic and mounted in a 19″ rack with the other eurocards. Not in use anymore, everything can now be done with a simple avr controller.

Same board controller board, bottom view.

 

96 channel Ir-receiver board

Ir receiver board to belongs to the above Joshua predecessor controller board. A lot of electronics for something simple we now these days with one receiver and the rest in software.

Same ir receiver board, bottom view. Routing and making a pcb was 25 years ago not that easy and cheap so wiring the pcb with roadrunner wire was the simplest and cheapest way to make the pcb. Until you made a mistake…
You can’t see it anymore but there where different colors for Vcc, gnd and data, but after all those years the colors are faded.

 

Ir Transmitter

The ir transmitter for the above receiver board. I used it only to program my learning remote controller, so that’s why it’s not build for daily use. You can switch between 3×32 channels with the jumpers.

The original Elektor design only supported 10 channels so I hacked in the other 22 channels that the Ir controller was capable of sending  by adding my own keyboard.

 

Amplifier interface

The interface card between my domotica and amplifier. Looking at the empty sockets I have already recycled some ics.

And on the back side again a lot of roadrunner wires.

From this interface board also a picture of the frontpanel.

 

Speech card

And the speech card, based on the Sp0256A and the CTS256A processor. We had a lot of fun with this speechcard. Nobody understood what was said and I didn’t get that, I understood everything that was coming out of the speaker. Looks like because me as the programmer did know what speech there was expected and therefore understood it all.

Backside with all the roadrunner wires again.

 

Rf Remote

I had someday a crazy idea to make a Rf remote control for the Joshua predecessor. This was begin of the ’90 when it was a bit complicated then now a days. This is the test setup to develop the software.

And the prototype, ram, rom, cpu all separated in dip package. The project never was finished, hard to realize with these components.

And the back with a lot of roadrunner wire again. Realizing this compact print on a regular 2 or 4 layer pcbs is hard to do, but with the roadrunner wire you can make as much “layers” as you like.

The rf board with tx and rx module. You can buy these modules now for a couple of dollars, but then they cost €75 for a set rx/tx.

 

Oldies Various

Various projects that I have made in the past. Some are still in use, other are overtaken by time.

 

Audio power slave switch.

My subwoofer uses 11watt when in standby, to save some energy this switch will switch the subwoofer on when there’s audio. Still in use.

 

S65 Test setup
https://evertdekker.com/wp/wp-content/uploads/slider61/audiopowerswitch.jpeg
The test setup for my S65 library. Some “modification” are done to get it all working.

 

Yampp

“Yet another mp3 player” a mp3 player that plays mp3 from a hdd, sounds not that special now, but then it was very unique. Special when you made you own. This was my first serious smd project. Just a kit that I soldered together. Even the components where 1206 it was not that simple, mainly because I didn’t have a aporpiate solderiron and solder.
Now these days soldering 0402 and 0.4mm qfp package aren’t any problem. If you use the stencil method, it’s a piece of cake.

 

Xbox360 Glitch

Xbox glitcher pcb and jtag programmer to exploit the xbox360 glitch hack. Because the Chinese pcb houses give you 10 pieces of the same pcb for the same price there where some left overs that I wanted to sell, but selling was the hardest part. Glitching your xbox360 is in a grey area and therefore not allowed to advertise with.

 

Voice recording

Nothing special, a Velleman 2653 kit to record and playback sounds. Can’t remember for what I have bought it, maybe just for playing with it.

 

Velleman IO & AD

Build this one the log the energy generated by the generators at one of my previous jobs.
4 pcb’s packed with components to read 2 AD channels and 2 IO channels and send it over Rs232 to the pc, hard to imagine now these days with all the Arduino’s etc that can doe the same job, even better with only 1 chip.

 

Elektor 8ch AD

Use for the same project as above, but didn’t get this one working. Never knew why…

 

Satellite smartcard

Home brew smartcard emulator for analog satellite tv. Not my design but made the pcb myself.
Watched a lot of channels with this smartcard 😉

 

Mini Crescendo

Famous design from Elektuur (Elektor) magazine, the mini-crescendo.
This was the light version of the Cresendo mosfet amplifier, still using it. This board is from the post crescendo that I used as active subwoofer, the last one is taken out of use.

 

6802 controller board

Controller board with 6802 controller, ram (missing) and eprom. Never used it, didn’t had an eeprom programmer myself.

 

Automated cat litter

Some crazy idea of me; I forgot sometimes to clean the cat litter on time and then the cats pied some where in the house and I had even more cleaning up to do.
There was nothing to buy on the internet, only cat litters that removed the poop from the litter, not refreshing the litter.
Automated cat litter that cleaned the litter after 4 visits from the cats. This is the operator (for me, not the cats) front panel. Home made frontpanel with recessed button behind it, lcd display and connector to the top lid of the litter.

Backside of the controller board. The sub pcb is an power line modem that I wanted to use for the domotica, however the communication was that poor that I dropped the idea to use these. Module was also to expensive to use it for all the network nodes.

 

Voice recognition

Voice recognition was not new for me, have used already a long time but now it was time to make my own. It works, now I’m trying to port it to the Atmel Avr series.  Project still running……………….