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 :

    $ esptool.py --port /dev/ttyS8 write_flash 0 espruino_1v94_esp8266_combined_512.bin 
    esptool.py v2.0.1
    Connecting....
    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.
    
    Leaving...
    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$ ./esptool.py --port /dev/tty.wchusbserial410 write_flash 0 ../espruino_1v93_esp8266_combined_512.bi­n 
    esptool.py v2.2-dev
    Connecting........_____....._____....._
    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.
    
    Leaving...
    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 :

    espruino_1v94_esp8266_combined_512.bin

    Thank you for your help.

    Regards;


    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

    ./esptool.py --port /dev/tty.SLAB_USBtoUART write_flash -fs 8MB -fm dout 0x0 ../espruino_1v93_esp8266_combined_512.bi­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
    c)
     ^
    in function "connect" called from line 1 col 29
    b=new f(b.host,b);b.connect();return b
                                ^
    in function "connect" called from line 35 col 4
      });
       ^
    in function "mqttConnect" called from line 72 col 17
        mqttConnect();
                    ^
    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 : https://www.espruino.com/Home+Automation­)

    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) {
      RELAY.write(v);
      LED.write(!v);
      mqtt.publish(PATH+"status", v?1:0);
    }
    
    function mqttMessage(pub) {
      console.log("MQTT=> ",pub.topic,pub.message);
    
      if (pub.topic == PATH+"set") {
        setState(pub.message!=0);
      }
      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() {      
          mqtt.subscribe(PATH+"#");
        }, 1000);
      });
      mqtt.on('publish', mqttMessage);
    }
    
    
    function onInit() {
      console.log("Connecting WiFi");  
      setInterval(function() {
        if (!mqtt) return;
        if (!mqtt.connected) {
          console.log("MQTT disconnected... reconnecting.");
          mqtt.connect();
        }
      }, 60*1000);
    
      wifi = require("Wifi");
      wifi.on('connected',function() {
        console.log("Connected to WiFi");  
      });
      wifi.on('disconnected',function() {
        console.log("Disconnected from WiFi");  
      });
      wifi.setHostname("MYDEVICE");
      wifi.stopAP();
      wifi.connect(WIFI_NAME, WIFI_OPTIONS,
                   function(ap){ 
        console.log("Successful connect.");
      });
      // wait, and connect MQTT
      setTimeout(function() {
        console.log("MQTT connecting");
        mqttConnect();
      }, 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.

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

Sonoff Installation

Posted by Avatar for user82278 @user82278

Actions