0

I am trying to use an ESP8266 to receive UDP packets and turn a specific LED using the UDP string received. I have made the Arduino program to get the UDP string and display it in the serial Monitor (BTW I want to use AT commands).

Here is a sample output:

+IPD,6:foobar
+IPD,6:foobar
+IPD,13:foobarhesbbdb
+IPD,13:foobarhesbbdb

Problem:

Code

#include <SoftwareSerial.h>
SoftwareSerial softSerial(8, 9); // RX, TX
String line;
void setup() 
{
  uint32_t baud = 9600;

  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
  Serial.setTimeout(10);


  softSerial.println("AT+CWJAP=\"***\",\"***\"");

 delay(1000);
  softSerial.write("\n");
  delay(2000);
 softSerial.println("AT+CIPSTART=\"UDP\",\"0\",0,5005,2\"\r");
 softSerial.write("\n");



}

void loop() 

{ 

    while(softSerial.available() > 0) 
    {
      char a = softSerial.read();
      if(a == '\0')
        continue;
      if(a != '\r' && a != '\n' && (a < 32))
        continue;
      Serial.print(a);

    }

        while(Serial.available() > 0)
    {
      char a = Serial.read();
      Serial.write(a);
      softSerial.write(a);
    }


}

How do I extract only the string without +IPD,x.
I'm new to ESP8266. Please tell me what I'm doing wrong.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
notnavindu
  • 487
  • 1
  • 6
  • 18

1 Answers1

0

The (horribly) wrong thing you are doing is delay. To learn how to correctly extract only the string you are interested in, read this answer.

In addition, AT command lines should be terminated with exactly only \r and not whatever println happens to use for EOL. So use write with an embedded \r at the end.

hlovdal
  • 26,565
  • 10
  • 94
  • 165