Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Vulcnar
#45300 Hi all,
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

Code: Select allvoid 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();
}
User avatar
By bbx10node
#45385 Try the https://github.com/Makuna/NeoPixelBus library in UART mode using GPIO2.

Any library that disables interrupts on the ESP8266 will cause problems because the WiFi code does not work when interrupts are disabled for more than a few milliseconds. The Adafruit NeoPixel library disables interrupts during bit banging so it works fine on other CPUs but not the ESP8266.
User avatar
By Achton
#47279 @Vulcnar: Like you, I started out with Adafruit's library for my ESP project, but I have not yet gotten to enabling WiFi and the WS2812Bs at the same time, so have not yet run into the drop out issues (but have heard of them).
On reading your reply I am now considering switching to Makuna's pixel library instead.
Earlier, I had a hard time getting it to work at all, so that's why I went ahead with the Adafruit one.
Could you provide some insight into the issues you came across with Makuna's lib and what you did to fix them?

About my project: I will be running two (short) LED strips on 5V, some push buttons and a trimpot on 3V3, and anticipate having mains power for my thing (so not battery power). I will also be using an MQTT service to send/receive messages. I am using tzapu's brilliant WifiManager library for AP management. Also, this is on a WeMos D1 mini. (BTW, I had huge problems with resets while doing this on solderless breadboards, so switched to perfboards instead, which fixed that right up.)