2

I flashed a sketch to a Sonoff basic switch R2 through Arduino IDE (with FTDI). Flash is completed and Sonoff runs the sketch successfully. The code is just a typical setup for making esp8266 a soft access point.

#include <ESP8266WiFi.h>

WiFiServer server(80);
IPAddress staticIP(192,168,1,22);
IPAddress gateway(192,168,1,9);
IPAddress subnet(255,255,255,0);

byte relayPin = 12;

void setup()
{

 pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);
 WiFi.mode(WIFI_AP);
 WiFi.softAP("****", "****");
 WiFi.softAPConfig(staticIP, gateway, subnet);
 delay(1000);
 server.begin();


 }


void loop()
{

if(WiFi.softAPgetStationNum() > 0) {
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);

}

delay(500);
}

But when I connect Sonoff to main power it doesn't respond to the programmed sketch and it constantly just turns on/off the lamp every 500ms-1000ms approximately and when I push the Sonoff's button relay stops being heard, but the light still turns on and off.

Any insights?

  • 3
    it doesn't respond to the programmed sketch ... how do you know this? – jsotola Feb 06 '20 at 00:16
  • 1
    Relay doesn't open/close as instructed – BrainTrance Feb 06 '20 at 00:21
  • 4
    it looks like your sketch is actually written to do what you described – jsotola Feb 06 '20 at 03:35
  • No, it doesn't. A constant flashing with no input is not what I instructed it to do. – BrainTrance Feb 06 '20 at 09:55
  • 2
    if you are confident in your code, then that means that the program has received an input .... you did not say what the input is ... you actually did not describe what you expect to happen – jsotola Feb 06 '20 at 16:17
  • According to this, you need to connect at least one device to the softAP to get it working. please check that your phone or any other device is not connected to it. If it is then it is the issue because of which the lights have been turning on and off and your script is executing. And also what is your max_connection parameter for WiFi.softAP()? – Lucifer Feb 11 '20 at 11:57

0 Answers0