Announcement

Collapse
No announcement yet.

SonOff basic WiFI flashing via esp tools

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SonOff basic WiFI flashing via esp tools

    By accident here updated one of two SonOff basic device to firmware 1.6.

    Then using Windows Atom attempted to update firmware via JTAG.


    Left here with a bricked device looking at the serial link. It would boot up and keep trying to connect to the WiFi connection.


    This morning installed python esptools on my Linux laptop.


    1 - Download Esptool Source code from download to a known folder.
    2 - Install esptools - python setup.py install


    3 - save current flash.bin (optional)


    IBMNBK:/# esptool.py --port /dev/ttyUSB0 read_flash 0x00000 0x100000 image1M.bin
    esptool.py v2.3.1
    Connecting....
    Detecting chip type... ESP8266
    Chip is ESP8266EX
    Features: WiFi
    Uploading stub...
    Running stub...
    Stub running...
    1048576 (100 %)
    1048576 (100 %)
    Read 1048576 bytes at 0x0 in 95.7 seconds (87.7 kbit/s)...
    Hard resetting via RTS pin...


    IBMNBK:/# ls *.bin
    image1M.bin

    4 - erase current firmware (optional)

    IBMNBK:/# esptool.py --port /dev/ttyUSB0 erase_flash
    esptool.py v2.3.1
    Connecting....
    Detecting chip type... ESP8266
    Chip is ESP8266EX
    Features: WiFi
    Uploading stub...
    Running stub...
    Stub running...
    Erasing flash (this may take a while)...
    Chip erase completed successfully in 2.8s
    Hard resetting via RTS pin...

    4 - write mcsTasmota.bin current firmware

    IBMNBK:/# esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 mcsTasmota.bin
    esptool.py v2.3.1
    Connecting....
    Detecting chip type... ESP8266
    Chip is ESP8266EX
    Features: WiFi
    Uploading stub...
    Running stub...
    Stub running...
    Configuring flash size...
    Compressed 506976 bytes to 350565...
    Wrote 506976 bytes (350565 compressed) at 0x00000000 in 30.9 seconds (effective 131.1 kbit/s)...
    Hash of data verified.

    Leaving...
    Hard resetting via RTS pin...

    5 - Checking boot up via minicom / serial connection

    Welcome to minicom 2.7

    OPTIONS: I18n
    Compiled on Feb 7 2016, 13:37:27.
    Port /dev/ttyUSB0, 09:29:04

    Press CTRL-A Z for help on special keys

    00:00:00 WIF: Connecting to AP1 default in mode 11N as sonoff-7596...
    00:00:07 WIF: Connect failed as AP cannot be reached
    00:00:07 WIF: Connecting to AP1 default in.

    This is the same issue that I have seen when updating the sonoff basic with sonoff firmware version 1.6.

    Connecting to AP1 default in mode 11N as sonoff-7596

    Scanning wireless here do not see SSID sonoff-7596 such that this is were I believe the Sonoff Firmware revision 1.6 upgrade the sonoff basic radio.

    Looking now for Sonoff basic firmware 1.5X and will try to upload this firmware to the Sonoff basic device.

    Found one called sonoff-basic-DHTxx.fw.afe.bin. Cleared firmware and uploaded this firmware then uploaded mcs.bin

    Looks a bit different but radio stuff is the same. Hitting pairing button and see:

    0:01:31 RSL: sonoff/RESULT = {"Reset":"Reset and Restarting"}
    SettingsDefault
    00:01:32 CFG: Use defaults
    00:01:33 APP: Restarting
    ets Jan 8 2013,rst cause:1, boot mode3,6)

    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v4ceabea9
    ~ld

    00:00:00 Project sonoff Sonoff (Topic sonoff, Fallback MCS_44BDAC, GroupTopic sonoffs) Version 5.9.10
    00:00:00 WIF: Connecting to AP1 default in mode 11N as sonoff-7596...
    00:00:07 WIF: Connect failed as AP cannot be reached
    00:00:07 WIF: Connecting to AP1 default in mode 11N as sonoff-7596...
    00:00:14 WIF: Connect failed as AP cannot be reached
    00:00:14 WIF: WPSConfigactive for 1 minute

    Scanning the wireless network with openWRT do see the client / AP named ESP_44BDAC

    Channel: 1 | Mode: Master | BSSID: 2E:3A:E8:44:BD:AC | Encryption: open

    Switched to Windows 7 Arduino software IDE programmer. Also noticed that it is available for Linux.
    1 - download it here ==> IDE
    2 - In Ubuntu downloaded arduino-nightly-linux64.tar.xz and extracted as arduino-nightly to the download directory
    3 - in download directory do a cd arduino-nightly
    4 - run the install.sh
    5 - you should see an icon on your desktop when complete.
    [ATTACH]69149[/ATTACH]
    6 - configuration of IDE for use with SonOff
    A - Open Arduino IDE and go to Preferences.
    B - Under Additional Boards Manager URLs field, enter hxxp://arduino.esp8266.com/stable/package_esp8266com_index.json
    C - Open Tools > Board > Boards Manager.
    D - Search for ESP8266 and install.
    E - Option settings in the Arduino IDE should look like this:
    • Flash Mode: DIO
    • Flash Frequency: 40MHz
    • Upload Using: Serial
    • CPU Frequency: 80MHz
    • Flash Size: 1M (64K SPIFFS)
    • Debug Port: Disabled
    • Debug Level: None
    • Reset Method: ck
    • Upload Speed: 115200
    • Port: Your COM port connected to Sonoff


    Again cleared the flash and installed a generic firmware with wifi. Cleared the flash again and installed original SonOff sketch. Change wireless below to your AP stuff.

    Code:
    /*
      Simple Wifi Switch
    */
    
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266mDNS.h>
    
    MDNSResponder mdns;
    
    // Replace with your network credentials
    const char* ssid = "YOUR_WIFI_SSID";
    const char* password = "YOUR_WIFI_PASSWORD";
    
    ESP8266WebServer server(80);
    
    String web_on_html = "<h1>SONOFF switch is ON</h1><p><a href=\"on\"><button>ON</button></a>&nbsp;<a href=\"off\"><button>OFF</button></a></p>";
    String web_off_html = "<h1>SONOFF switch is OFF</h1><p><a href=\"on\"><button>ON</button></a>&nbsp;<a href=\"off\"><button>OFF</button></a></p>";
    
    int gpio_13_led = 13;
    int gpio_12_relay = 12;
    
    void setup(void){  
      //  Init
      pinMode(gpio_13_led, OUTPUT);
      digitalWrite(gpio_13_led, HIGH);
      
      pinMode(gpio_12_relay, OUTPUT);
      digitalWrite(gpio_12_relay, HIGH);
     
      Serial.begin(115200); 
      delay(5000);
    
      WiFi.begin(ssid, password);
      Serial.println("Connecting to wifi..");
    
      // Wait for connection
      while (WiFi.status() != WL_CONNECTED) {
        digitalWrite(gpio_13_led, LOW);
        delay(500);
        Serial.print(".");
        Serial.println(WiFi.localIP());
        Serial.println(WiFi.status());
        digitalWrite(gpio_13_led, HIGH);
        delay(500);
      }
      
      Serial.println("");
      Serial.print("Connected to ");
      Serial.println(ssid);
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());
      
      if (mdns.begin("esp8266", WiFi.localIP())) {
        Serial.println("MDNS responder started");
      }
      
      server.on("/", [](){
        if(digitalRead(gpio_12_relay)==HIGH) {
          server.send(200, "text/html", web_on_html);
        } else {
          server.send(200, "text/html", web_off_html);
        }
      });
      
      server.on("/on", [](){
        server.send(200, "text/html", web_on_html);
        digitalWrite(gpio_13_led, LOW);
        digitalWrite(gpio_12_relay, HIGH);
        delay(1000);
      });
      
      server.on("/off", [](){
        server.send(200, "text/html", web_off_html);
        digitalWrite(gpio_13_led, HIGH);
        digitalWrite(gpio_12_relay, LOW);
        delay(1000); 
      });
      
      server.begin();
      Serial.println("Server ready..");
    }
     
    void loop(void){
      server.handleClient();
    }

    Went back to Linux and I was able to program the SonOff basic using the python SonOTA uploader.

    After uploading original SonOff bins went back to using the SonOTA script ran it again after the above, saw the sonoff-xxxx (instead of the ITEAD-*) AP.

    The script then said I was in the finalstage piece and kept uploading the firmware.

    I had done this before except it did not work with version 1.6 of the SonOff firmware.

    Thinking the bins attached are SonOff firmware 1.5 or 1.4x and those may write to the Wifi card in the Sonoff Wifi basic device.

    Then updated it to the mcs.bin.

    All is well now.
    Last edited by Pete; June 2nd, 2018, 02:30 PM.
    - Pete

    Auto mator
    Homeseer 3 Pro - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU - Mono 6.4X
    Homeseer Zee2 (Lite) - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro - Mono 6.4X

    X10, UPB, Zigbee, ZWave and Wifi MQTT automation.

  • #2
    Great news. Perhaps I can try something like what you did and awaken my dead Sonoff 4CH Pros. Assuming you did this on Linux?
    Don

    Comment


    • #3
      Originally used Arduino IDE on Windows 7.

      The configuration for the Sonoff is the same for Windows 7 or Linux.

      Guessing you have connected your Sonoff to a TTL-USB serial device.



      That said I am attaching a couple of original SonOff bins that might have fixed this issue.

      After uploading original SonOff bins went back to using the SonOTA script ran it again after the above, saw the sonoff-xxxx (instead of the ITEAD-*) AP.

      The script then said I was in the finalstage piece and kept uploading the firmware.

      I had done this before except it did not work with version 1.6 of the SonOff firmware.

      Thinking the bins attached are SonOff firmware 1.5 or 1.4x and those may write to the Wifi card in the Sonoff Wifi basic device.

      Then I was good to go.

      Just a thought and what may work. Don't do anything above rather do the following with the SonOTA script.

      1 - Start up your sonoff and
      2 - hit the button 3 times rapidly to reset SonOff
      3 - hit the button 4 times rapidly to go to AP mode while running the script.

      If the above works then
      4 - you will see the ITEAD-* AP and the FinalStage AP if this methodology works...

      If not then update your Sonoff with the original sonoff bins attached above.

      I just rewrote parts above to make more sense.

      Tell me if it doesn't make sense.
      Last edited by Pete; June 2nd, 2018, 02:18 PM.
      - Pete

      Auto mator
      Homeseer 3 Pro - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU - Mono 6.4X
      Homeseer Zee2 (Lite) - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro - Mono 6.4X

      X10, UPB, Zigbee, ZWave and Wifi MQTT automation.

      Comment

      Working...
      X