Earn Maker Points on Every Order! Learn More!

Flashing SONOFF Firmware on NodeMCU

Back to Blog
Flashing SONOFF Firmware on NodeMCU - Flashing SONOFF Firmware on NodeMCU - Flashing SONOFF Firmware on NodeMCU - Flashing SONOFF Firmware on NodeMCU

Flashing SONOFF Firmware on NodeMCU

Sonoff is a WiFi controlled switch which is embedded with ESP8266 IC and has relays to control the device via the Internet. This IC can be flashed and reprogrammed by Arduino IDE. The makers of Sonoff published the libraries and Arduino files on their GitHub page. Initially, it has only for Sonoff made boards only, after that it supports many ESP8266 boards and Development boards like NodeMCU. In this tutorial, we will see how to flash the Sonoff Tasmota Firmware into the NodeMCU development boards. In the new updated firmware, you can easily choose the different ESP8266 Boards easily.

Components Needed:

Download the Sonoff Tasmota Firmware from this link.

If you are not installed the ESP8266 on boards manager follow this step to install it. In case you have previously installed then skip this step and continue to Cloning GitHub repository part.

Step 1: Open Arduino IDE and open Preferences. Add this URL at Additional Boards Manager URLs field – http://arduino.esp8266.com/versions/2.4.1/package_esp8266com_index.json

And click OK.

1.Arduino IDE ESP Board URL

Step 2: Now navigate to Boards Manager (Tools>Boards>Boards Manager).

2.Tools

Step 3: Now search for esp8266 on the search bar and Install it. As I have already installed it shows in grey. You can go ahead and install.

3.Boards Manager

Step 4: Now open the Sonoff Tasmota folder that we downloaded from GitHub Page. Navigate to ‘lib’ folder from extracted files and copy all the contents, then paste it into Arduino ‘libraries’ folder on your computer.

4.Arduino Libraries

Step 5: Now Open the sonoff.ino file and then open the userconfig.h

5.User Config

Now edit the SSID and Password fields with your WiFi network SSID and Password. Also, give a unique name by your choice in #define PROJECT “sonoff”.

Eg.  #define PROJECT “nodefactory”

6.WiFi Credentials

Step 5: Now connect your NodeMCU and choose the correct COM Port and Board Version. Make sure the settings are like this for NodeMCU 1.0 Board.

Board: NodeMCU 1.0 (ESP12-E Module)

Flash Size: “4M(1M SPIFFS)

CPU Frequency: 80 MHZ

Upload Speed: “115200”

7.Board Settings

Then Flash the Firmware by clicking Upload.

Step 6: Once Flashing is done Open Advanced IP Scanner. And search for the IP address inside your network IP. In my case, My IP will range from 192.168.255.0-255 (Means the IP will be range from 0-255). Click scan and you can see the project name you given in the userconfig.h file as device name here.

8.IP Scanner

Step 7: Note down the IP Address and paste it into your browser URL and click enter. It will show the Sonoff Tasmota page to configure your module.

9.Sonoff Home

Step 8: By default, it will be in Sonoff Basic. So you need to change it to ‘Generic’ in ‘Configuration’ menu. Click ‘Configuration’ and inside that choose ‘Configure Module’.

10.Sonoff Config

Step 9: Select the board as Generic and Save. The device will restart. This option is for all ESP8266 boards.

11.Select Generic

Step 10: Now if you click the configuration, then you can able to see more GPIO options. Using that you can select the GPIO Functions.

12.Generic ESP8266

Depending on the GPIO setting the option will appear on the Homepage like DHT, Relay, Switch and Many more.

Other NodeMCU Tutorials:

IOT Home Automation using Blynk and NodeMCU

Voice Controlled Home Automation | Google Assistant | NodeMCU

Upload Sensor Data to ThingSpeak using NodeMCU

Getting Started with NodeMCU Wi-Fi Development Board | ESP8266

Share this post

Comments (34)

  • Willian Gomes Arruda

    Hello, thanks for the post, the sonoff originally has the maximum of 4ch relay, using the nodemcu would be possible to create a 8ch relay based board ? thanks.

    November 21, 2018 at 12:25 AM
    • Sharath

      Ya, you can. The GPIO (or Digital Pins D0, D1,etc) can be used as each channel. One thing you need to care about is that the pins don’t have an alternate function. Example, GPIO1 and GPIO3 are used for serial communication. So if any device using that pins (internally or externally) either the relay or the communication will be interrupted. So check the Pinout of NodeMCU and choose the pins that don’t have an alternate function using it. The Pinout can be found here – https://www.factoryforward.com/iot-home-automation-using-blynk-nodemcu/

      November 21, 2018 at 10:58 AM
  • Ajit Singh

    Hi, if we use sonoff basic we can control the device via ewLink app. After flashing with above technique will I be able to control my nodemcu+relay using ewLink app ?

    December 20, 2018 at 1:46 AM
    • Sharath

      No it’s not possible. But you an create your own App using MIT App inventor or Blynk. The eWelink is only for original sonoff only, even in that if you flash custom firmware it won’t work.

      December 20, 2018 at 8:58 PM
  • pandian

    I need help. this project is not working(not connect wifi network. correct ssid and password, but not connect)

    January 2, 2019 at 9:34 PM
    • Sharath

      Can you tell me in detail about what problem you are facing?
      Are you facing during upload?
      IDE/Text Editor you are using?

      January 3, 2019 at 10:20 PM
      • pandian

        this function does not work

        void WifiBegin(uint8_t flag, uint8_t channel)
        {

        }

        January 8, 2019 at 6:29 PM
    • pandian

      Please reply me, Sir

      January 5, 2019 at 10:31 AM
      • Sharath

        If you tell me where you are facing the problem, then only I can analyze what might be the problem.
        To check whether your NodeMCU is connected to Wi-Fi, use advance IP Scanner as in Step 6.

        January 5, 2019 at 11:18 AM
  • Yakoe Nicol Tablado

    How do I configure that with Hass.io? can you help me with that?

    January 3, 2019 at 7:40 AM
    • Sharath

      I didn’t try hass.io yet, but you might need to use Raspberry Pi for this. NodeMCU has limited memory.

      January 4, 2019 at 5:51 PM
  • pandian

    this function does not work

    void WifiBegin(uint8_t flag, uint8_t channel)
    {

    }

    January 8, 2019 at 6:28 PM
    • Sharath

      I think you didn’t have a proper Wi-Fi library. Did you followed the Step 1 to 3 correctly?
      Check that, did you got the ESP8266 Examples in File>Examples.

      To verify Wi-Fi library is working or not, Open File>Examples>ESP8266 then choose any related example (choose station mode example if available). If station mode example available flash it to the NodeMCU and turn ON Wi-Fi on your mobile phone and search for new Wi-Fi networks. If you find any network with full signal and related to NodeMCU Names then it is working.

      As looking at the error you mentioned it is most probably related to Wi-Fi Library not installed properely.

      January 9, 2019 at 11:34 AM
  • manu

    hi,

    I am able to control D6 & D8 using Relay1i & Relay 2i
    but no matter whatever GPIO pin I select, Relay 3i & 4i will not get triggered.
    Any specific requirements for 4 channel relay to work with Tasmota on Nodemcu ?

    February 5, 2019 at 12:01 PM
    • Sharath

      No, its same for all relays, no specific changes. Try to use the 3&4th relay with the working pins to make sure the relays are actually working.
      Did you changed the module type from ‘Basic’ to ‘Generic’? If you can see step 10’s screenshot with all the GPIO Pins then it is correct. Else select dropdown and choose Generic, then the NodeMCU will restart.

      February 5, 2019 at 1:43 PM
  • ron bentley

    I keep getting compile errors. I am very new to this but cannot seem to find out what i am doing wrong. Below is the start of the error but it seems to repeat

    Arduino: 1.8.8 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\IRKelvinator.cpp: In member function ‘void IRKelvinatorAC::setTemp(uint8_t)’:

    C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\IRKelvinator.cpp:96:41: error: no matching function for call to ‘max(unsigned int, uint8_t&)’

    temp = max(KELVINATOR_MIN_TEMP, temp);

    February 20, 2019 at 1:53 PM
    • Sharath

      Are you using that IRKelvinator library in the code? If it is not needed then you can navigate to that file location and delete it. C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266

      February 20, 2019 at 3:21 PM
  • Charudatt Uplap

    If I don’t give any SSID/Password, will it invoke the WiFiManager and allow me to enter it using the WEB GUI page ?

    I want to invoke the WiFi Manager config on the NODEMCU build.

    March 22, 2019 at 5:03 PM
    • Sharath

      Yes, using configure WiFi option you can change the SSID and Password. It will store it in EEPROM. But for the first time to access it, you might need any wifi network.

      March 22, 2019 at 8:52 PM
  • Harminder Singh

    Flashing SONOFF Firmware on NodeMCU
    SPIFFS Warning: mkspiffs canceled!

    how can i remove this error

    April 25, 2019 at 10:07 AM
    • Sharath

      Either you are using an older version or it may be a cache problem.

      1.Try Changing the board to Arduino (or any other).

      2.Compile it (you may get an error. Just ignore no need to do anything).

      3.Again change back to NodeMCU Board. Then Upload.

      It is just to clear the old cache file in a simple way. Otherwise, you have to navigate and locate it. The IDE will build a new file whenever you change the Board types. Hope it may work.

      April 25, 2019 at 10:33 AM
  • SUMIT KUMAR

    the selected serial port _
    does not exist or your board is not connected

    June 11, 2019 at 12:47 PM
  • SUMIT KUMAR

    Arduino: 1.8.5 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    Sketch uses 606228 bytes (58%) of program storage space. Maximum is 1044464 bytes.
    Global variables use 50108 bytes (61%) of dynamic memory, leaving 31812 bytes for local variables. Maximum is 81920 bytes.
    esptool.py v2.6
    2.6
    esptool.py v2.6
    Serial port COM3
    Connecting…….._____….._____….._____….._____….._____….._____…..____Traceback (most recent call last):
    File “C:\Users\SUMIT KUMAR\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py”, line 25, in
    esptool.main(fakeargs)
    File “C:/Users/SUMIT KUMAR/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py”, line 2653, in main
    esp.connect(args.before)
    File “C:/Users/SUMIT KUMAR/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py”, line 468, in connect
    raise FatalError(‘Failed to connect to %s: %s’ % (self.CHIP_NAME, last_error))
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    _
    the selected serial port _
    does not exist or your board is not connected

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    June 11, 2019 at 12:49 PM
  • kostas

    Good evening. I would like you to tell me how I can
    activate a relay through the configure timer of tasmota. Thanks

    June 19, 2019 at 9:21 PM
  • Sajid Salam Ghouri

    Simple steps:
    download esptool
    open cmd as administrator
    D:\esptool\esptool>
    setup.py install
    esptool.py –port COM3 flash_id
    esptool.py –port COM3 erase_flash
    copy sonoff56.5.0.bin
    esptool.py –port COM3 write_flash -fs 4MB -fm dout 0x0 sonoff-6.5.0.binn

    October 10, 2019 at 10:25 PM
  • John Abbagnale

    Hello everyone.
    I followed all the steps as indicated in the tutorial, when it’s time to compile the sketch I have in return this series of errors:

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_uploadReadByte(WiFiClient&)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/ESP8266WebServer.h:160: multiple definition of `ESP8266WebServer::_collectHeader(char const*, char const*)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:268: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_parseRequest(WiFiClient&)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:348: multiple definition of `ESP8266WebServer::_uploadWriteByte(unsigned char)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:353: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `String::operator+=(char)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:359: multiple definition of `ESP8266WebServer::_uploadReadByte(WiFiClient&)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:364: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::urlDecode(String const&)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:581: multiple definition of `ESP8266WebServer::urlDecode(String const&)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:586: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_parseArguments(String)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:273: multiple definition of `ESP8266WebServer::_parseArguments(String)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:278: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_parseFormUploadAborted()’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:611: multiple definition of `ESP8266WebServer::_parseFormUploadAborted()’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:616: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_parseForm(WiFiClient&, String, unsigned int)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:368: multiple definition of `ESP8266WebServer::_parseForm(WiFiClient&, String, unsigned int)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:373: first defined here

    libraries\ESP8266WebServer\Parsing.cpp.o: In function `ESP8266WebServer::_parseRequest(WiFiClient&)’:

    C:\Users\John\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WebServer\src/Parsing.cpp:70: multiple definition of `ESP8266WebServer::_parseRequest(WiFiClient&)’

    sketch\Parsing.cpp.o:sketch/Parsing.cpp:75: first defined here

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    Any idea how to solve this issue?
    I tried to upload a different sketch on the ESP module (a simple test script), and it works with no flaws.
    Thank you in advance

    October 12, 2019 at 2:50 PM
  • Abhijit Borah

    How do we to set the proper local time zone (and without DST) in the settings? Thank you.

    October 20, 2019 at 6:41 PM
  • PL

    Hi!

    Tried to follow the instructions as written but still there are some problems.
    First of all the ” Additional Boards Manager URLs” provided here is not working anymore. The correct location is http://arduino.esp8266.com/stable/package_esp8266com_index.json

    And still i’m getting several errors.
    One of these are like “EEPROM.h/PubSubClient.h/esp-knx-ip.h/Wire.h/IRremoteESP8266.h” etc have multiple libraries. Probably that’s not the problem as the libraries are present.
    But finally i get:
    exit status 1
    ‘memmove_P’ was not declared in this scope

    I have no idea what to do..

    Thanks!

    November 3, 2019 at 6:45 PM
  • jason

    Hi Im getting this error as below.. NOT sure how to solve this.. Kindly assist.. Thank you so much..

    In file included from sketch\sonoff.ino.cpp:1:0:

    C:\Users\HOME\Downloads\arduino-1.8.5-Sonoff-Tasmota-5.11.1\arduino-1.8.5-Sonoff-Tasmota-5.11.1\portable\packages\esp8266\hardware\esp8266\2.4.0\cores\esp8266/Arduino.h:240:21: fatal error: algorithm: No such file or directory

    #include

    ^

    compilation terminated.

    exit status 1

    November 30, 2019 at 7:39 PM
    • Sharath

      You need to check whether the boards are installed properly or the library files are in correct path

      December 1, 2019 at 11:47 PM
  • Mohammed Hajooze

    It is great work, I am new to MQTT, how can I configure it to work with cloud? Is there any specific cloud MQTT service?

    December 6, 2019 at 3:49 AM
  • Massimiliano

    Sorry my stupid question, but where I can found the file sonoff.ino? I downloaded the Sonoff Tasmota Firmware from the github page that you have indicated on the top of the article (https://github.com/arendst/Sonoff-Tasmota), I unzipped the contenute of the lib folder in my arduino library but inside the examples (menù file of the Arduino IDE) I don’t found the sonoff.ino. Thanks and ciao

    February 8, 2020 at 6:45 AM

Leave a Reply

Back to Blog