I am new to Arduino and the ESP8266 platform. I recently purchased a Huzzah board from Adafruit to control some LEDs via mobile phone. I am using Arduino IDE 1.6.7 to program the board and the neopixel library to drive the LEDs. I am currently experiencing problems with the WiFi access point dropping out. Here is how the problem goes.
I have a WiFi access point that I send commands via a web browser connected to the ESP8266's network. It then reads the command and updates the LED sequences. If I send commands, they can be read but occasionally the WiFi network disappears and I can no longer send any commands. I tried commenting out the calls to the LEDs and the WiFi network never dissapears and I can send commands. I tried putting as many yield() calls in my LED sequences as possible thinking it was an issue with background tasks not running. That helped a little, but didn't solve my problem. I was hoping someone had some advice/help that they could give me to hopefully get it working. I followed a tutorial here https://learn.sparkfun.com/tutorials/es ... web-server for the Wifi bit.
Here is the relevant code
void setupWiFi() //setting up a WiFi network with SSID Lightsrip
{
WiFi.mode(WIFI_AP);
// Do a little work to get a unique-ish name. Append the
// last two bytes of the MAC (HEX'd) to "Thing-":
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
macID.toUpperCase();
String AP_NameString = "Lightstrip " + macID;
char AP_NameChar[AP_NameString.length() + 1];
memset(AP_NameChar, 0, AP_NameString.length() + 1);
for (int i=0; i<AP_NameString.length(); i++)
AP_NameChar[i] = AP_NameString.charAt(i);
WiFi.softAP(AP_NameChar,passkey);
}
void checkWifi()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Request received");
yield();
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
yield();
// Match the request
String s = "HTTP/1.1 200 OK\r\n";
s += "Content-Type: text/html\r\n\r\n";
s += "<!DOCTYPE HTML>\r\n<html>\r\n";
yield();
if (req.indexOf("/On") != -1){
power=true;
s+="Power is now on";
}
else if (req.indexOf("/Off") != -1){
power=false;
s+="Power is now off";
}
else if (req.indexOf("/LED1") != -1){
s+="LED 1 is now ";
if(LED1b==true){
s+= "off";
LED1b=false;
}
else{
s+="on";
LED1b=true;
}
}
else if (req.indexOf("/LED2") != -1){
s+="LED 2 is now ";
if(LED2b==true){
s+= "off";
LED2b=false;
}
else{
s+="on";
LED2b=true;
}
}
else if (req.indexOf("/LED3") != -1){
s+="LED 3 is now ";
if(LED3b==true){
s+= "off";
LED3b=false;
}
else{
s+="on";
LED3b=true;
}
}
else{
s+="Nothing changed, invalid command";
}
s+="</html>\n";
yield();
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
yield();
}