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?

6
  • 3
    it doesn't respond to the programmed sketch ... how do you know this?
    – jsotola
    Commented Feb 6, 2020 at 0:16
  • 1
    Relay doesn't open/close as instructed Commented Feb 6, 2020 at 0:21
  • 4
    it looks like your sketch is actually written to do what you described
    – jsotola
    Commented Feb 6, 2020 at 3:35
  • No, it doesn't. A constant flashing with no input is not what I instructed it to do. Commented Feb 6, 2020 at 9: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
    Commented Feb 6, 2020 at 16:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.