udp.read() character string question
i trying utilize udp.read function read packet sent on local network , compare key phrase, if match execute piece of code. however, whenever use packet sender, correctly receives , displays packet send not compare key character string have set. when display both received packet , key string via serial.print function return exact same phrase. when convert them integers convert 2 different integers, if compare individual characters in string code correctly compare. ideas missing? how can 2 strings contain exact same set of characters return different values when converted integers? udp.read() function not returning character string?
code:
void loop()
{
int packetsize = udp.parsepacket();
if (packetsize)
{
// receive incoming udp packets
serial.printf("received %d bytes %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 = ");
serial.println(packetkey);
//compare incoming packet key
if (incomingpacket == packetkey)
{
digitalwrite(ledoutput, high); //turn on light
delay(2000);
digitalwrite(ledoutput, low); //turn off light
}
serial.printf("udp packet contents: %s\n", incomingpacket);
}
serial window returns following:
received 17 bytes 192.168.2.97, port 55056
packet key = feed monsters
1073644364
udp packet contents: feed monsters
1073669168
code:
void loop()
{
int packetsize = udp.parsepacket();
if (packetsize)
{
// receive incoming udp packets
serial.printf("received %d bytes %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 = ");
serial.println(packetkey);
//compare incoming packet key
if (incomingpacket == packetkey)
{
digitalwrite(ledoutput, high); //turn on light
delay(2000);
digitalwrite(ledoutput, low); //turn off light
}
serial.printf("udp packet contents: %s\n", incomingpacket);
}
serial window returns following:
received 17 bytes 192.168.2.97, port 55056
packet key = feed monsters
1073644364
udp packet contents: feed monsters
1073669168
Arduino Forum > Using Arduino > Programming Questions > udp.read() character string question
arduino
Comments
Post a Comment