-->
Page 1 of 1

ESP12F HTTP Throwing Exceptions

PostPosted: Fri Apr 14, 2017 1:52 pm
by anujmattoo
I am working on RGB led controller and controlling the lights from mobile app and sending the HTTP commands to ESP in AP mode.

The code works perfectly initially and when using few commands and when speed up the HTTP commands from Mobile app to ESP, the ESP works for sometime and then crashes and reset.
I am sending around 20-30 request per second.

I am using git core version of ESP8266 library for Arduino.

How to solve this issue, earlier it was solved by using the git core version, but it is crashing again. What to do?

Here is the code : -

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>

#define RED_LED     12
#define WHITE_LED   13
#define BLUE_LED    14 //16  //14
#define GREEN_LED   16 //14  //15

char ssid[10] = "Downlight";

WiFiServer server(5045);
WiFiClient client;

void setup()
{
  pinMode(RED_LED, OUTPUT);
  pinMode(WHITE_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);

  WiFi.mode(WIFI_AP);

  Serial.begin(115200); //Start communication between the ESP8266-12E and the monitor window
  WiFi.softAP(ssid);

  server.begin();
}


void loop()
{
  client = server.available();
  if (!client)
  {
    return;
  }
 
  String req = client.readStringUntil('\r');
  Serial1.println(req);
  client.flush();


  if ((req.indexOf("/RGB/") != -1))
  {
    int pos = req.length();
    int ind1 = req.indexOf("/RGB/") + 5;
    String teststring = req.substring(ind1, pos);

    int ind2 = teststring.indexOf("/");
    String hexRGB = req.substring(ind1, ind2 + ind1);

    Serial.print("\n");
    Serial.print("Hex RGB: ");
    Serial.print(hexRGB);

    hexRGB.toUpperCase();
    char c[6];

    hexRGB.toCharArray(c, 7);
    long r = convertToInt(c[0], c[1]); //red
    long g = convertToInt(c[2], c[3]); //green
    long b = convertToInt(c[4], c[5]); //blue

    analogWrite(RED_LED, r * 4);
    analogWrite(GREEN_LED, g * 4);
    analogWrite(BLUE_LED, b * 4);

    client.flush();
  }
}
int convertToInt(char upper, char lower)
{
  int uVal = (int)upper;
  int lVal = (int)lower;
  uVal = uVal > 64 ? uVal - 55 : uVal - 48;
  uVal = uVal << 4;
  lVal = lVal > 64 ? lVal - 55 : lVal - 48;
  return uVal + lVal;
}