In this post, you’re going to learn how to flash custom firmware in the Sonoff device, so that you can control it with your own web server. I recommend that you read my previous post to get familiar with the Sonoff. We also have additional resources that describe how to flash a custom firmware to the Sonoff device using an FTDI programmer and the Arduino IDE.
Sonoff TH16 Wifi Temperature and Humidity Sensor Switch+Si7021 RF Controller for DIY Smart Home, Wireless Remote Control Home Appliances and Work with Amazon Alexa, 1 Set -Amazon.com.
If you don’t have a Sonoff yet, you can get one for approximately $5 – visit Maker Advisor to find the best price.
First, watch the step by step video tutorial belowSafety warning
Make sure you disconnect your Sonoff from mains voltage. Then, open the box enclosure.
Sonoff pinout
The Sonoff is meant to be hacked, and you can see clearly that these connections were left out, so that you can solder some pins and upload a custom firmware. That’s the pinout.
I’ve soldered 4 header pins, so that I can easily connect and disconnect wire cables to my Sonoff device.
Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »
Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »
Preparing your 3.3V FTDI module
You need an FTDI module to upload a new firmware to your Sonoff. Use the schematics provided as a reference.
Warning: uploading a custom firmware is irreversible and you’ll no longer be able to use the app eWeLink.
I’ve added a toggle switch in the power line, so that I can easily turn the Sonoff on and off to flash a new firmware without having to unplug the FTDI module.
I used hot glue to glue the ends of the wires together. This prevents you to make wrong connections between the FTDI and the Sonoff in the future.
Boot your Sonoff in Flashing Mode
To flash a new firmware to your Sonoff, you have to boot your Sonoff in flashing mode. Follow this 4 step process:
1) Connect your 3.3V FTDI programmer to your computer
2) Hold down the Sonoff button
3) Toggle the switch to apply power to the Sonoff circuit
4) Then, you can release the Sonoff button
Now, your Sonoff should be in flashing mode and you can upload a new firmware.
Opening the Arduino IDE
You should have the ESP8266 add-on installed in the Arduino IDE – If you don’t have the add-on installed, first follow this tutorial on How to Install the ESP8266 Board in Arduino IDE.
You can upload the full sketch to your Sonoff (replace with your SSID and password):
Preparing your Arduino IDE
Having your Sonoff device still in flashing mode.
Wait a few seconds while the code is uploading. You should see a message saying “Done Uploading”.
Troubleshooting
If you try to upload the sketch and it prompts the following error message:
It means that your Sonoff is not in flashing mode. You’ll need to repeat the process described in section “Boot your Sonoff in flashing mode” described earlier in this guide.
Final circuit
After uploading the code, re-assemble your Sonoff. Be very careful with the mains voltage connections.
It’s the exact same procedure as shown in the introductory guide.
ESP8266 IP Address
Open the Arduino serial monitor at a baud rate of 115200. Connect GPIO 0 of your ESP8266 to VCC and reset your board.
After a few seconds your IP address should appear. In my case it’s 192.168.1.70.
Demonstration
For the final demonstration open any browser from a device that is connected to the same router that your Sonoff is. Then type the IP address and click Enter!
Now when you press the buttons in your web server you can control the Sonoff switch and any device that is connected to it.
Sonoff tutorials list:
Wrapping up
That’s it for now, I hope you had fun learning about the Sonoff device. Make sure you subscribe to my blog, because I’ll be posting more tutorials about the Sonoff.
Do you have any questions? Leave a comment down below!
Thanks for reading,
Rui
Start a new topic
use sonoff device with another application - WITHOUT REFLASHING!!!fyv
i want to write application to replace eweLink, but i dont want flash device.
is it possible?
![]()
i allready have mqtt server, app and any device.
i want to add sonoff to my system/app without flashing
33 CommentsSorted by Oldest First
Henning Madsen
Dear fyv, - Like you do, I not feel me comfortable to trust EweLink, in case where development solutions go to my customer. I like the idea from ITEAD, to build intelligent solutions, based one selected existing modules.
If I over the next 2 years by/sell thousand of solutions, and so potently the customer/user not will be able to connect E-weLink - have seen many example at this yearly in this forum. It is bad business for all.
What idea do you have to make a new connections platform? I do also have some server capacity available here, if we need some random security for the end user.
Sincerely
HCM Development
Norway
fyv
2 people like this
Israel Ferreira
I too want this. A simple API would do the trick. Please release it.
Sascha Srdoch
Hi, guys, did you manage to find a solution for this issue ? Has anyone managed to build his own app ?
Patrick Martin
Doesn't make sense of how to have own APP without Reflashing.
Current software running on Sonoff contains MCU code for current APP.
For MCU to run another code, then the MCU must be programmed for such
In order to program MCU - flashing is the only method to upload your new program.
Sonoff FAQs point to ESP for such development.
- don't be so resistant to FAQs, they will help you. Really.
There is plenty of evidence others have successfully accomplished own apps.
סוגי נח
1 person likes this
Cedric Saveuse
Patrick, then an easier way to flash would make sense. Not having to solder would be good. Mqtt pre-installed would be great. I like the eWeLink app (great for some users in my household), but would love to use OpenHab in parallel. Would it not be easy to add this possibility with a simple firmware update? Love these products & own 22 by now... S20, POW, Basic & TH16 along with one SC...
Morten Kvistgaard
MQTT without reflashing (and thereby loosing the eWeLink) has been mentioned in many posts. It would really solve a lot.
E W
#1 How about making the latest stock firmware available as .bin files so that users can recover the ewelink capability after flashing and experimenting with alternatives. As it is now, flashing the device is a one way street with no way to restore original functionality. No need to release the source code, just make the latest compiled firmware downloadable. Almost all other devices like routers etc. provide a database of downloadable stock firmware for their products.
#2 Solder the 5 pin header as factory stock. It couldn't add more than a few cents to the price.
Alexandre Piel
@Patrick actually it does make sense to use sonoff firmware with another app. And you can actually do it by telling to the device to use another server during the paring mode. See https://blog.ipsumdomus.com/sonoff-switch-complete-hack-without-firmware-upgrade-1b2d6632c01
Me I would like to keep the firmware and the sonoff app, and only have an API to send some command to the itead server in order to control my devices. Right now the only way would be to build a kind of proxy server between the device and the itead server. But it would bring some latency and most likely some issue...
Right now the Sonoff are using web socket and I doubt that one day they switch to MQTT. Maybe they could provide an MQTT interface on there server but I also doubt about it. It would already be great to have a proper API before to even think about MQTT.
By the way, for flashing the Sonoff you don't need to do any soldering, you don't even need to open the Sonoff. You can just use OTA directly with the itead interface, like if you would update the firmware but instead you put your own firmare.
Ian Biddle
It would resolve all these issues if the servers that the SONOFF devices connect too, worked and were stable. I think it may be too late for that now, as trust in the ability to keep the servers up and stable has now mostly gone from the SONOFF community due to multiple server outages. Its going to take a long time to regain all that trust again.
As the servers are located on AMAZON in Germany. I think you should just restore everything back to a known working server backup set, and spool up a few extra resources for now just to get it working. Then start a new server build. (Your going about this the wrong way. Unless you want to loose your customers)
Ian Biddle
I purchased my first 2 SONOFF devices on 2nd January. Only managed to get 1 to setup and that took about 10 attempts and most of the day. It mostly does not work. I keep getting communication errors. I'm not even going to try with the second until I have seen the system up and running for several months without fault. I don't want to connect anything in the house to a system that is unreliable and untrustworthy.
If it had worked well on the first day then I would have probably purchased about 30 devices by now. The devices seem more than fine, Its the surrounding infrastructure where its all let down.
Morten Kvistgaard
I have a few months experience with Sonoff. I set up my system, before the IFTTT update, so I had no choice but reflashing the fw. I now use simple Arduino OTA with custom fw for each device. And the GUI is provided by Blynk. I have several devices. All are rock solid and stable. Blynk servers also... I have prolly purchased 30 devices by now ;)
Morten Kvistgaard
'... By the way, for flashing the Sonoff you don't need to do any soldering, you don't even need to open the Sonoff. You can just use OTA directly with the itead interface, like if you would update the firmware but instead you put your own firmare.'
Really? How so? I remember that the itead interface, just updated the fw without any user interactions. No possibility to insert your own?
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |