I have a nano with a enc28j60 to which i've a working udpListener sketch as per the included library.
What i'm trying to achieve is to send a UDP of wither a "H" or "L" which for testing purposes turns an LED on and off, whilst also printing to the serial port.
Below is the included function i've modified from the ethercard library
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);
Serial.print("dest_port: ");
Serial.println(dest_port);
Serial.print("src_port: ");
Serial.println(src_port);
Serial.print("src_port: ");
ether.printIp(src_ip);
Serial.println("data: ");
Serial.println(data);
//my added code
if (data == "H"){
digitalWrite(ledPin, HIGH);
Serial.print("LED ON");
}
if (data == "L"){
digitalWrite(ledPin, LOW);
Serial.print("LED OFF");
}
}
With the serial terminal open I can see that the nano is receiving the UDP character, but isn't acting upon it.
Form my rather limited programming knowledge I suspect its something to do with it incorrectly reading the data out of the buffer. The data is declared as a const char and given the variable *data as per the included example, however when it is printed to the serial terminal
Serial.println(data);
the above works and prints the character to the terminal but the below doesn't print or turn the led pin high or low
if (data == "L"){
Any help would be greatly appreciated