udp.read() character string question

I am trying to utilize the udp.read function to read a packet sent over my local network and then compare that to a key phrase, if they match it will execute a piece of code. However, whenever i use a packet sender, it correctly receives and displays the packet i send but will not compare to the key character string i have set. When i display both the received packet and the key string via the serial.print function it will return the exact same phrase. When i convert them to integers they convert to two different integers, if i do a compare to individual characters in the string the code will correctly compare. Any ideas what i am missing? how can 2 strings contain the exact same set of characters but return different values when converted to integers? Is the udp.read() function not returning a character string?


void loop()
int packetSize = Udp.parsePacket();
if (packetSize)
// receive incoming UDP packets
Serial.printf(“Received %d bytes from %s, port %d\n”, packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read(incomingPacket, 255);

if (len > 0)
incomingPacket[len] = 0;

Serial.print("PACKET KEY = ");

//compare incoming packet to key
if (incomingPacket == PacketKey)
digitalWrite(ledoutput, HIGH); //turn on the light
digitalWrite(ledoutput, LOW); //turn off light

Serial.printf(“UDP packet contents: %s\n”, incomingPacket);


Serial window returns the following:

Received 17 bytes from, port 55056
PACKET KEY = feed the monsters
UDP packet contents: feed the monsters

EspUDP_test.ino (1.88 KB)

     if (incomingPacket == PacketKey)

is not how to compare a string to a string.

Try strcmp(...)

Thank you so much! That did the trick. Am I confusing a String with a string? It's interesting that that "==" compare function does not work but the reference material indicates that it will.

Am I confusing a String with a string?

The reference page that you linked to is about Strings, not strings.