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?
it doesn't respond to the programmed sketch
... how do you know this?