I need to compare the received text them make an action turn on/off a led.

I have the following edit version of a sketch courtesy W.A. Smith

Arduino web server that gets text from an HTML, textarea text box on the hosted web page.The web page is stored on the micro SD card.

I need to compare the received text them make an action turn on/off a led.

I am new in this and loss to see where I am going wrong.
Any assistance would be greatly appreciated

This is the part were of the code where I try to compare the in coming text with my string (ledon,ledoff)

// print the received text to the Serial Monitor window

// if received with the incoming HTTP GET string
if (GetText(txt_buf, TXT_BUF_SZ)) {
Serial.println("\r\nReceived Text:");
Serial.println(txt_buf);
if (strcmp (txt_buf, “ledoff” == 0)){
Serial.println(“off”);
digitalWrite(PULSE, LOW);
}
if (strcmp (txt_buf, “ledon” == 0)){
Serial.println(“on”);
digitalWrite(PULSE, HIGH);

if (strcmp (txt_buf, "ledon" == 0))Are the closing brackets of the strcmp() function in the right position, I wonder ?

Hi UKHeliBob,

meanwhile I was able to resolve the problem this way.

if (!strcmp (txt_buf, "ledoff")){
Serial.println("off");
digitalWrite(PULSE, LOW);
}
if (!strcmp (txt_buf, "ledon")){
Serial.println("on");
digitalWrite(PULSE, HIGH);
Thanks!!

Now you have the brackets in the right place, unlike the original code. As you have discovered you don't need to explicitly test for zero as long as the expression being tested returns 0 (false) if an exact match is found

// if received with the incoming HTTP GET string
if (GetText(txt_buf, TXT_BUF_SZ))

Now I'm trying to pass a value from the txt_buf to control a dac.

dac.voutWrite(0, txt_buf);

If I replace the txt_buf let's say by 3000 I have 3 volts in the dac, so the dac cod I2C is working,do I have to convert txt_buf?

appreciated the help!!

do I have to convert txt_buf?

Obviously. If dac_buf contains "3000", atoi(dac_buf) will return the value 3000.

if(strcmp(txt_buf, "ledoff") == 0)
{
   // txt_buf contains ledoff

Pay attention to where the parentheses are, and compare that to your code. Not the same.

Here I compare the entire string and cod is working ok, but I just want to compare the first letter of the string in this case the l.

if (!strcmp (txt_buf, "ledon")){

Serial.println("on");

digitalWrite(PULSE, HIGH);
}

Thank you for the help

but I just want to compare the first letter of the string in this case the l.

So, do it.

if(txt_buf[0] == 'l')

Hi PaulS,

Thanks for your help.