Can't use output from ethercard Help newbie alert.

Hi All

Please will someone help. I will post my code but can’t get the if(data == “H”) to work. been on this for a few days and can’t figure it. I know it is a simple problem but the answer eludes me.

Thanks

// Demonstrates usage of the new udpServer feature.
//You can register the same function to multiple ports, and multiple functions to the same port.
//
// 2013-4-7 Brian Lee cybexsoft@hotmail.com

#include <EtherCard.h>
#include <IPAddress.h>

#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip = { 192,168,0,170 };
// gateway ip address
static byte gwip = { 192,168,0,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac = { 0x70,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

//callback that prints received packets to the serial port
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[4], 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_ip: ");
ether.printIp(src_ip);
Serial.println("data: ");
Serial.println(data);

// here is the problem
if(data == “H”) {
digitalWrite(9, HIGH);

}
else
{
digitalWrite(9, HIGH);
delay(250);
digitalWrite(9, LOW);

}

}

void setup(){
pinMode(9, OUTPUT);
Serial.begin(57600);
Serial.println(F("\n[backSoon]"));

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F(“Failed to access Ethernet controller”));
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println(F(“DHCP failed”));
#endif

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);

//register udpSerialPrint() to port 1337
ether.udpServerListenOnPort(&udpSerialPrint, 1337);

}

void loop(){
//this must be called for ethercard functions to work.
ether.packetLoop(ether.packetReceive());
}

if(data == "H")

data is a (single) char not a string constant. Should that be

if(data == 'H')

Thanks Tried it but then get
Arduino: 1.7.9 (Windows 8.1), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"

udpListener.ino: In function 'void udpSerialPrint(uint16_t, uint8_t*, uint16_t, const char*, uint16_t)':

udpListener.ino:41:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I know it has to do with the data type but can't sort it

data is actually a pointer so a char array

you can probably use

if(data[0] == 'H')

If data only contains the character H, you can also use strcmp

i(strcmp*data, "H") ==0)

Question:
what does the line Serial.println(data) actually print?

Thanks

This is the output

[backSoon]
IP: 192.168.0.170
GW: 192.168.0.1
DNS: 0.0.0.0
dest_port: 1337
src_port: 1234
src_ip: 192.168.0.171data:
H

Hi

if(data[0] == 'H')

did the trick thanks a lot