I modified a code which replies BAR when I send FOO. The problem is the if else statement always lands on else which prints Wrong command. I tried comparing it to string FOO(??) and also comparing it to char FOO with the same buffer size but no joy. This is the code:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "##########";
const char* password = "##########";
WiFiUDP Udp;
unsigned int localUdpPort = 9999; // local port to listen on
char incomingPacket[255]; // buffer for incoming packets
char command_1[255] = "FOO"; //Tried same buffer size... no luck
char replay_1[] = "BAR";
char wrong[] = "Wrong command";
void setup()
{
Serial.begin(74880);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
Udp.begin(localUdpPort);
}
void loop()
{
int packetSize = Udp.parsePacket();
if (packetSize)
{
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(incomingPacket); // Prints the same as from icoming packet which is FOO (Debbuging)
if (incomingPacket == command_1) { //Tried comparing to same buffer size "FOO" and string "FOO"... no luck
Udp.write(replay_1);
}
else {
Udp.write(wrong);
}
Udp.endPacket();
}
}