Sonoff Installation

Posted on
  • Hi guys,

    I started to post on "Sonoff troubles" but I think my problem is now different.

    I try to install Espruino on a simple Sonoff.

    I download Espruino 1.94
    I upload it to sonoff via Esptool after I had pressed the button and plugged in the module :

    $ --port /dev/ttyS8 write_flash 0 espruino_1v94_esp8266_combined_512.bin v2.0.1
    Detecting chip type... ESP8266
    Chip is ESP8266
    Uploading stub...
    Running stub...
    Stub running...
    Configuring flash size...
    Auto-detected Flash size: 1MB
    Flash params set to 0x0020
    Compressed 524288 bytes to 326519...
    Wrote 524288 bytes (326519 compressed) at 0x00000000 in 28.7 seconds (effective 146.0 kbit/s)...
    Hash of data verified.
    Hard resetting...

    It seems to be OK.
    After that, I unplugged the module, repplugged it.
    I'm not able to connect to Sonoff with Web IDE nor putty. Even if I've set baudrate to 115200 bd.

    In WEB IDE I have "Connect" and a prompt ">" but I'm not able to type anything.

    Do you have any idea ?

    Thank you,

    1 Attachment

    • sonoff.PNG
  • Maybe just try unplugging the USB-TTL completely and plug the Sonoff into the mains? You should be able to see it appear as a new ESPsomething access point if it's working.

    It's highly likely that your USB-TTL converter won't supply enough power on the 3.3v line. When I did mine in the video I'd got a beefed up 3.3v regulator added to it.

  • OK thank you,

    is it possible to subsitute the 3.3 FTDI with Lipo ?

  • I don't think so unless you can drop the voltage with a diode. LiFePo4 batteries are in the right voltage range though.

    You could always run from the mains, and should be able to connect the USB-TTL converter (just not with the 3.3v supply connected). The only reason I'm less happy about suggesting that is you want to be really careful you don't touch the mains connection.

  • Hello,

    Thank you for your advice, I was thinking of doing this but I was not sure it would work, but I gave it a try and... it still fails.
    To do so, I've plugged the main to the Sonoff and :
    Sonoff |------------| FTDI
    TX ------------ RX
    RX ------------ TX
    GND ------------ GND

    (I'm sure my wiring RX/TX is ok. If i swap it fails miserably to load the .bin)

    Here is the output of esptool :

    kiwis:esptool-master kiwis$ ./ --port /dev/tty.wchusbserial410 write_flash 0 ../­n v2.2-dev
    Detecting chip type... ESP8266
    Chip is ESP8266EX
    Uploading stub...
    Running stub...
    Stub running...
    Configuring flash size...
    Auto-detected Flash size: 1MB
    Flash params set to 0x0020
    Compressed 524288 bytes to 326299...
    Wrote 524288 bytes (326299 compressed) at 0x00000000 in 29.2 seconds (effective 143.5 kbit/s)...
    Hash of data verified.
    Hard resetting...

    Moreover find attached the new output off the IDE with baudrate configured to 115200. A bit better, but not fully satisfying.

    I will investigate on the FTDI side and may be Sonoff...

    Can you confirm this is the right file I'm loading :


    Thank you for your help.


    1 Attachment

    • Capture d’écran 2017-10-19 à 21.51.58.png
  • Hello,

    Finally succeded to install the firmware, but I had to change parameters in the esptool command line ; -fs and -fm

    ./ --port /dev/tty.SLAB_USBtoUART write_flash -fs 8MB -fm dout 0x0 ../­n 

    But, now I'm not able to connect to Wifi. I will double check my wifi configuration.

    Connecting WiFi
    Disconnected from WiFi
    Disconnected from WiFi
    Disconnected from WiFi
    MQTT connecting
    Uncaught InternalError: Unable to create socket
     at line 4 col 2
    in function "connect" called from line 1 col 29
    b=new f(,b);b.connect();return b
    in function "connect" called from line 35 col 4
    in function "mqttConnect" called from line 72 col 17
    in function called from system

    Do you think something is missing in the code ?

    1 Attachment

    • Capture d’écran 2017-10-20 à 21.45.34.png
  • @user82278, could you please publish your code you upload and try to run?

  • Hello @allObjects,

    Sorry, I didn't exposed my "project" here :

    I'm just trying to reproduce Gordon's Home automation project, so this is the code I try :
    (available here :­)

    Naturally I've changed the Wifi ssid and password.

    var WIFI_NAME = "Espruino";
    var WIFI_OPTIONS = { password : "helloworld" };
    var MQTT_HOST = "raspberrypi";
    var PATH = "/mydevice/";
    var LED = D13;
    var RELAY = D12;
    var BTN = D0;
    var mqtt;
    var wifi;
    function setState(v) {
      mqtt.publish(PATH+"status", v?1:0);
    function mqttMessage(pub) {
      console.log("MQTT=> ",pub.topic,pub.message);
      if (pub.topic == PATH+"set") {
      if (pub.topic == PATH+"eval") {
        try {
          mqtt.publish(PATH+"response", eval(pub.message));
        } catch(e) {
          mqtt.publish(PATH+"exception", e.toString());
    function mqttConnect() {
      mqtt = require("MQTT").connect({
        host: MQTT_HOST,
      mqtt.on('connected', function() {
        console.log("MQTT connected");
        setTimeout(function() {      
        }, 1000);
      mqtt.on('publish', mqttMessage);
    function onInit() {
      console.log("Connecting WiFi");  
      setInterval(function() {
        if (!mqtt) return;
        if (!mqtt.connected) {
          console.log("MQTT disconnected... reconnecting.");
      }, 60*1000);
      wifi = require("Wifi");
      wifi.on('connected',function() {
        console.log("Connected to WiFi");  
      wifi.on('disconnected',function() {
        console.log("Disconnected from WiFi");  
      wifi.connect(WIFI_NAME, WIFI_OPTIONS,
        console.log("Successful connect.");
      // wait, and connect MQTT
      setTimeout(function() {
        console.log("MQTT connecting");
      }, 10000);
  • Update :
    I was able to connect to Wifi with this code loaded on a Wemos D1. SO the code is fine. The only difference is that on the Wemos it is espruino 4m running and not 512k.

    1- Can I load espruino 512k on a Wemos D1 ?

    I will try to load the firmware and the same code on an other Sonoff to try.

    Have a nice sunday.

    2 - How can I change my notverypersonnal nickname on this forum ? It fails each time when I perform the action my profile.

  • I installed it on Wemos, works fine.

    In the firmware .zip file there is readme file with a command line for 4MB upload.
    I used that without any changes in params and it worked.

  • I found the "-fm dout" to be a critical setting to get it to stick.

  • I've had to use the dio flash mode on my wemos boards. If both dout and dio work, dio is better.

  • I've had a report from a user that ./ --port /dev/tty.SLAB_USBtoUART write_flash -fs 8MB -fm dout 0x0 ../­n worked for them - apparently fs and fm were needed.

    I guess maybe some revisions are different - the one I used for the video here:­KXw

    worked fine with the normal flashing commands.

  • SONOFF - 1 outlet - Reprogramming a $30 WiFi Switch - N outlets!

  • I was able to flash Tasmota FW using the following­a/wiki/Esptool#upload-firmware instructions (-fm dout).

    But I didn't have any luck with Espruino 2v00 version (haven't tried older versions unfortunately). I have tried with and without the -fm dout as suggested but seen no access-point exposed upon restart.

    Is there here anybody who managed to use the 2v00?

  • Which firmware are you using - the 512k combined?

    Does the flash succeed?

    If you use putty or similar you should see output on boot - set to 115200 baud. There might be some initial output at the start with a baudrate of 74880 if it's looping and resetting set to that rate to see what the messages are saying.

  • Yes I used this one­no_2v00_esp8266_combined_512.bin .

    You mean connecting through the FTDI?

  • I'm using version 2v00.17 on my Sonoff.
    Have downloaded espruino_2v00.17_esp8266.tgz. --port /dev/ttyUSB0 erase_flash
    cleans sonoff,

    root=$(pwd)/espruino_2v00.17_esp8266 --port /dev/ttyUSB0 --baud 230400 write_flash \
      --flash_freq 40m --flash_mode qio --flash_size 512KB \
      0x00000 $ root/boot_v1.6.bin \
      0x01000 $ root/espruino_esp8266_user1.bin \
      0x7C000 $ root/esp_init_data_default.bin \
      0x7E000 $ root/blank.bin
    installs on Sonoff.

    > Reset ();
    = undefined
      ____ _
    | __ | ___ ___ ___ _ _ | _ | ___ ___
    | __ | _ - | . | _ | | | | | . |
    | ____ | ___ | _ | _ | | ___ | _ | _ | _ | ___ |
              | _ |
      2v00.17 (c) 2018 G.Williams
    Espruino is open source. Our work is supported
    only by sales of official boards and donations:
    Flash folder 512KB: 256/256, manuf 0xe0 chip 0x4014
  • @Frida Thanks! Will try that once I convince myself to dig into the lamp guts again :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Sonoff Installation

Posted by Avatar for user82278 @user82278