-2

I have a SIM900 module and Arduino, both are working fine. In my previous programs I have use strstr() command to find specific word from a string but they were constants and pre defined in the program but now I want to read serial communication from SIM900 and detect a specific word from it. But it is showing me

invalid conversion from 'char' to 'const char'

This is my program:

int x;
char sms;
char response;
char disp;
void setup()
{
  Serial.begin(2400);
}


void loop() {
  while(Serial.available() == 0);

  if(Serial.available() > 0)
  {    
    sms = Serial.read();

    disp = sms;
    if (strstr(disp,"track")) //Comparing word entered with word stored in program
    {
      Serial.println("Found the  word!");
    }
  }
}
1

There are two problems.

1) you are trying to have the Arduino's single UART talk to both the SIM900 and the PC.

2) disp needs to be an array of char's, as to compare for words phrases.

Try the following. It implements a 2nd Soft serial port to which you can connect the SIM900. Along with building an array char at a time.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

char buffer[16];
#define buffer_size sizeof(buffer)/sizeof(buffer[0])
int8_t buffer_pos = 0;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("Serial to mySerial demo started");

  buffer_pos = 0;
}

void loop() {
  char inByte;
  while (mySerial.available()) {
    inByte = mySerial.read();
    while (buffer_pos >= buffer_size) {
      for (int8_t i = 0; i < buffer_size - 1; i++) { // if shift buff left if at end of buff
        buffer[i] = buffer[i + 1];
      }
      buffer_pos--;
    }
    buffer[buffer_pos++] = inByte;
    if (strcasestr(buffer, "track")) {
      buffer_pos = 0;
      Serial.println("TRACK FOUND!");
    } else {
      Serial.write(inByte);
    }
  }
}
  • mpflaga thanks for taking your time to help me but your solution didn't work,It's showing up "TRACK FOUND!" for anything I send(to whatever word I send),I tried to change "strcmp" to "strstr" but in this method it's not reading string completely to the end.it's showing unfinished data.I took the screenshots.s29.postimg.org/i0mrhzw13/image.png.I will also add code that I modified. – pra Aug 29 '14 at 18:14
  • My modified code:freetexthost.com/mwez052ng4, My requirment is very simple ,I send sms to sim900 a specific code and arduino should receive this and search for that key word,If it finds that keyword it needs to print predefined text. – pra Aug 29 '14 at 18:19
  • did you try "strcasestr" I see your picture is upper case – mpflaga Aug 29 '14 at 20:17
  • yes,I did still no use :( – pra Aug 30 '14 at 3:05
  • I don't know what's wrong with above program,but I have made another program:here: freetexthost.com/rw6cdpf3m3 , Here is the output : s18.postimg.org/amcjzqfu1/Untitled.png, it basically reads serial data from sim900, I just need code to detect specific word from that text,for eg: "145" in that incoming data, since it is serial data not a const char,please help me – pra Aug 30 '14 at 3:22
-2

In C++ constant chars and chars aren't convertible (easily). The easiest solution in this case is to change both chars to const.

    int x;
    char sms;
    char response;
    const char disp;
    void setup()
    {
      Serial.begin(2400);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.