sonoff esp8266

Posted on
  • Hi, forgive me for my bad english. I'm using a sonoff module that have a relay and a led. I have falsh firmware with espruino v1.87 and I have wrote a code to control the relay and the led from a we page.

    If I use the board connected on USB, it works well. But when I add the save() function, I can't control anymore the relay and the led. If I plugg off the usb and connect the board to 220V (france), the board is not responding on wifi. So I think that the board doesn't store my code:

    var relay = D12;
    var led = D13;
    
    function toggleDevice(toggle){
      digitalWrite(relay, toggle);
      digitalWrite(led, toggle);
    }
    
    function startServer() {
      var http = require('http');
      var httpServer = http.createServer(function(req, res) {
        var params = url.parse(req.url, true);
    
        if (params.query !== null && params.query.device !== "") {
          var status = params.query.device;
          toggleDevice(status);
        }
        res.end("<h1>Hello world</h1>");
      });
    
      httpServer.listen(80);
      print('HTTP server is running');
    }
    
    function onInit() {
      var wifiSSID = "xxxxxx";
      var wifiPass = "xxxxxxxx";
    
      var wifi = require('Wifi');
      wifi.connect(wifiSSID, {password:wifiPass}, function(err, data){
        if (err) {
          print('Error while connecting to access point' + wifiSSID);
          return;
        }
    
        print("connected? err=", err, "info=", wifi.getIP());
        startServer();
      });
      wifi.stopAP();
      wifi.save();
    }
    
    E.on('init', onInit());
    //save(); 
    

    Any idea please ?

  • You don't have to reconfigure the wifi in on init.

    Once you do wifi.save() the parameters are saved and will be remembered.

  • How are you powering sonoff when it's not connected to the commuter via USB?

    Does it have it's own dc convertor from mains voltage?

    Wi fi won't come up if the power supply is not powerful enough - I think you need around 600ma.

  • OK for the wifi parameter. I will remove the wifi.save function. The sonoff module use an input directly from the main power (90V-250V) and has his own convertor: https://www.itead.cc/sonoff-wifi-wireles­s-switch.html

  • ...wifi.stopAP() is puzzling me...: why would you stop it? You did not even start an access point... but may be, I miss a point here...

    anyway: where does the print() go when you are not connected anymore to the Web IDE? Is it blocking the device, because the/a buffer is full with print?

    Remove the print()s and give it another shot...

  • E.on('init', onInit()); isn't doing what you expect and could be breaking things.

    I'd just remove that line...

  • Salut @azer, what's your status?

  • Hello. I ended up using arduino to program my esp. I'll try again using espruino when i have more time.

  • Ok, thanks 👍

  • ...wifi.stopAP() is puzzling me...: why would you stop it? You did not even start an access point... but may be, I miss a point here...

    stopAP is for when you don't want the ESP to be an access point. It is possible for it to be mixed/both, but probably cleaner to turn off the AP if not used.

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

sonoff esp8266

Posted by Avatar for azer @azer

Actions