Capture incoming SMS from 4G shield

Goal: Receive SMS, and based on that message perform an action.
Issue: my IF statement does not perform action as expected, i think my issue is needing to turn the data into a string or array.

In the code below, the manuf. says the _4G.readNewSMS function is called, and then the SMS text field is stored temporarly in

_4G._buffer

. See file 4G.PNG to see what i mean.
If I text it “action” no line is printed.

//////////////////////////////////////////////
  // 1. Wait for new incoming SMS
  //////////////////////////////////////////////
  error = _4G.readNewSMS(30000);

  if (error == 0)
  {
    Serial.println(F("-----------------------------------"));
    Serial.print(F("SMS index: "));
    Serial.println(_4G._smsIndex, DEC);

    Serial.print(F("SMS Stte: "));
    Serial.println(_4G._smsStatus);

    Serial.print(F("Phone number: "));
    Serial.println(_4G._smsNumber);

    Serial.print(F("SMS day: "));
    Serial.println(_4G._smsDate);

    Serial.print(F("SMS time: "));
    Serial.println(_4G._smsTime);

    Serial.print(F("SMS body: "));
    Serial.println((char *)_4G._buffer);
   Serial.println(F("-----------------------------------"));
  

  if (_4G._buffer == "action " ){
    Serial.println("111111111111111111");

Ser.png shows the serial monitor output with no 1111 line printed.

ser.PNG

  if (_4G._buffer == "action " ){

If _4G._buffer is a char array, that is NOT how you compare strings. strcmp() is.

PaulS:

  if (_4G._buffer == "action " ){

If _4G._buffer is a char array, that is NOT how you compare strings. strcmp() is.

In the example code below I have tried implimenting your suggestion with the real life trigger being 810..

 if (strcmp((_4G._buffer, "810") == 0 ){
    Serial.println("111111111111111111");
    
  }
 
  else
  {}

The following error is produced, is my syntax incorrect? Thanks again.

exit status 1
cannot convert 'bool' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'

It is saying that _4G._buffer is a bool and not a "text" field.

Can you provide the library link?

arduino_new:
It is saying that _4G._buffer is a bool and not a “text” field.

Can you provide the library link?

I had the wrong syntx… had an extra (…when using the below code i dont get compile errors, just battling a small hardware issue right now to know if the compare method works.

(warning, automatic download)
Library download link: Library

4G shield documentation page with code examples: Shield Info and examples

if (strcmp(_4G._buffer, "810") == 0 ){
    Serial.println("111111111111111111");
    
 }
 
  else
  {}

PAUL!!!

I owe you a beer. It works flawlessly..

Extremely happy with how simple this was...1 line of code!