Hello all,
Please I need your Help, because I am a beginner in C and also didn't get it in the Arduino forum.
I am trying to control a GSM modem to send and receive SMS's to read a temperature sensor and switch ON or OFF a motor. I send the AT commands to the modem and need to look for the answer, as well as, read SMS's the split the information.
I already read books about C trying to understand Pointers and Vectors, but, I am a lot confused ( vectors do not need pointers because the name is already pointing to the [0] of the vector, etc.) and I do not find any example similar to what i am using.
At the moment I sent AT command to the modem, read the response but I can not compare it.
Again your help is appreciated because I spend already a week looking for a solution.
Thanks in advance.
Manuel
below is a summary of the code used:
I get the following error: undefined reference to 'strstr ( char *, const char * )'
#include <SoftwareSerial.h> #include <string.h> boolean newData = false; #define rx_pin 2 #define tx_pin 3 const byte num_chars = 100; char receivedchars [num_chars]; unsigned long timeout; byte rx_ret =0; char * strstr ( char *, const char * ); char *OK; char ok_str[]={"OK\n\r"}; SoftwareSerial mySerial(rx_pin, tx_pin); //rx, tx byte power= 8; //byte rx_finished = 0; void setup() { // define pin modes for tx, rx: pinMode(rx_pin, INPUT); pinMode(tx_pin, OUTPUT); pinMode(power, OUTPUT); // set the data rate for the SoftwareSerial port mySerial.begin(9600); Serial.begin(9600); delay(200); Serial.println("<Arduino is ready>"); digitalWrite(power, HIGH); delay (2000); digitalWrite(power, LOW); delay(500); mySerial.flush(); // erase } void loop() { boolean newData = false; mySerial.println("AT"); rx_ret = read_input_data(175); if(rx_ret){ Serial.println("was here"); } OK = strstr (receivedchars, ok_str); if(OK ){ Serial.println("OK received"); } showNewData(); while(1){ // to avoid keeping senn the command continuesly } } byte read_input_data(int timeout) { unsigned long prev_time = millis(); byte num_bytes = 0; byte i =0; //delay(timeout); byte rx_state = 0; while((mySerial.available()) || ((unsigned long)(millis()- prev_time) <= timeout)){ num_bytes = mySerial.available(); //Serial.println(num_bytes); while(num_bytes) { num_bytes--; if(i < num_chars){ receivedchars [i] = mySerial.read(); i++; receivedchars [i] = '\0'; //end the string with null char } else { mySerial.read(); newData = true; } } } rx_state = 1; return (rx_state); } // this routine is only to debug porposes void showNewData() { if (newData = true){ Serial.println(receivedchars); receivedchars[0]='\0'; newData = false; } }
What