Skip to content

Build Sonoff Basic

Yurik72 edited this page May 20, 2020 · 13 revisions

At the moment there are two example:

  1. Sonoff_basic

  2. Sonoff_Basic_web

Main difference, that web version supports embedded file browser to navigate by SPIFFS file system and Web Interface to toggle Sonoff

Instruction for Sonoff_basic &Sonoff_Basic_web:

  1. Prepare your Arduino for work with ESP8266, for instance have a look (https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/)

  2. Download the library https://github.com/Yurik72/ESPHap and unzip it into the Arduino library folder. For Windows, this is usually C:\Users<username>\Documents\Arduino\libraries

  3. From the attached archive https://github.com/Yurik72/ESPHap/tree/master/wolfssl unpack wolfSSL_3_13_0.rar into the same folder of the Arduino libraries. Better name it "wolfsll"

  4. Download or install WiFiManager library from https://github.com/tzapu/WiFiManager

4.1 Open the sketch https://github.com/Yurik72/ESPHap/tree/master/examples/Sonoff_basic or https://github.com/Yurik72/ESPHap/tree/master/examples/Sonoff_basic_web. You can change GPIO, different devices can have different pins, hovewer for Sonoff Basic is GPIO 12.

const int relay_gpio = 12;
  1. Next, prepare Sonoff, for example, see here https://medium.com/@jeffreyroshan/flashing-a-custom-firmware-to-sonoff-wifi-switch-with-arduino-ide-402e5a2f77b.

5.1. Solder a shield to Sonoff board

5.2 Connect USB UART adapter to the Sonoff soldered shield with the following pinouts:

3.3v-> 3.3v;

GND-> GND;

RX-> TX;

TX-> RX;

NOTE ! Sonoff must be disconnected from the 220v!

5.3 Connect USB UART to the computer. In Arduino, select appropriate COM port and choose ESP8285 board (ESP8285 is not mistake !!!!)

5.4 If USB UART has reset button, then press the firmware download button, wait for the download message and press and hold the button on Sonoff and press the Reset button, wait for the download to start, after that the button on Sonoff can be released.

If USB UART without the Reset button, then remove the USB from the computer, press and hold the button on the Sonoff, insert the USB and click "download". After the download starts, you can release the button.

All this is necessary to put Sonoff in boot mode (GPIO0 connected to GND at the time of power-up)

  1. After the download is done, Sonoff starts in Access Point mode, find the WiFi point named "ES" on your computer and connect

  2. After the connection, you will probably be redirected to the start page, if not, enter 192.168.1.4 in the browser and select your Wifi, input the password and confirm

  3. The device restarts.

  4. Open the phone -> Apple home -> add device.

  5. Make a choise to add new device manually and we see something like ES ....... available, select it and agree of course that it is not certified, input password 11111111 and let's go .....

  6. As a rule, everything will pass the first time and you will immediately see it in the devices list. You can turn it on and off. To check the reverse reaction, you can click on the Sonoff button to see that the status is updated ..

If something went wrong (Pairing process is the most capricious) it is better to remove everything from the device, reflash it and try again.

In my experience, I have had a maximum of 3 attempts. although in the majority everything goes the first time

For experienced users : Pairing data is saved on the SPIFFS file system "/pair.dat". it may be that Sonoff has already saved that but Apple not. Therefore to resume Pairing error,just delete this file and start pairing again. In principle, you can uncomment a long button press

// SPIFFS.remove (pair_file_name); // clean pairing data

// WiFi.disconnect (true); // lost saved wifi credentials

then with a long press the device will forget everything

Note !! there are new version of example Sonoff_basic_web, which includes build in web server. You can manage your file content, via http:/browse and set sonof state via http: In case of wrong pairing you just need to remove file "pair.dat". Other benefits of this version you can download this file and reuse later on any device. Device not needed to more pairing

Well, now we can disconnect USB, connect Sonoff to 220 and enjoy..

Clone this wiki locally