Hi, I need a code which receive a key word and compare that word with the word setted and if is the same send me a message with something and if not send me the message Error.
Can someone help me ? I tried to make it but doesnt work
The code you posted does something. You did not say what it does.
You did not say how that differs from what you want.
It's hard to help you without knowing what the problem is.
GSM.listen();
The last created instance of SoftwareSerial is already listening. Since you only have one instance, it is not necessary to call listen() on every pass through loop().
if (GSM.available())
{
while (GSM.available())
The if statement is not necessary. The while statement will do nothing if there is no serial data to read.
{
buffer[count++] = GSM.read();
if (count == 64)break;
}
Why break at 64 when the array can hold twice that number of characters? Why is the array not being NULL terminated, to make it a string?
if (Serial.available())
GSM.println(Serial.read());
If you send a string to the Arduino, via the serial port, why are you then sending it to the GSM with a carriage return and line feed after each character?
void Cmd_Read_Act(void)
{
char buffer2[128];
for (int i = 0; i < count; i++)
{
buffer2[i] = char(buffer[i]);
}
Why are you copying the data, when you are going to simply through the data away when this function ends?
I try do make the code for what i need , but its not working...
The code what i posted is made from some tutorial , i watch them and i try to make what i need, but is not working.
redaot:
I try do make the code for what i need , but its not working...
The code what i posted is made from some tutorial , i watch them and i try to make what i need, but is not working.
Neither are you. I asked some questions. You whined that the code doesn't work, for some undefined definition of work. This forum does not work that way. You need to answer ALL of the questions asked.
And i try to implement the function wich i speack above; i want to receive a sms just when i send a key word . The code doesnt work... Some help ?
#include <SoftwareSerial.h>
#include <String.h>
byte buffer[64];
int count=0;
SoftwareSerial SIM900(7, 8);
String yourPassword = "TRACK";
String password;
char incoming_char=0;
char senderNumber[20];
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000);
}
void SIM900power()
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void loop()
{
SIM900.listen();
if (SIM900.available()) // If date is comming from from GSM shield)
{
while(SIM900.available()) // reading data into char array
{
buffer[count ]=SIM900.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
Cmd_Read_Act(); //Read the 'COMMAND' sent to SIM900 through SMS
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0;
}
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i )
{ buffer[i]=NULL;} // clear all index of array with command NULL
}
void Cmd_Read_Act(void) //Function reads the SMS sent to SIM900 shield.
{
char buffer2[64];
for (int i=0; i<count;i )
{ buffer2[i]=char(buffer[i]);}
if (strstr(buffer2,"TRACK")) //Comparing password entered with password stored in program
{
Serial.println("Password Authenticated.");
Serial.println("Sending reply SMS. ");
sendSMS();
}
}
void sendSMS()
{
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.println("AT + CMGS = \"+407524*****\"");
delay(100);
SIM900.println("Test");
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
SIM900power();
}
Nonsense. The code works just fine. You simply expect it to do something other that what it actually does. However, since you couldn't be bothered to explain what is actually does or what you expect it to do, we can NOT help you.
PaulS:
Nonsense. The code works just fine. You simply expect it to do something other that what it actually does. However, since you couldn't be bothered to explain what is actually does or what you expect it to do, we can NOT help you.
The code doesnt work after is uploaded .
I want to set a "Password" , when i send the password from another phone to the sim card what is in GSM module, if its the same password i want the module to send me back a message .
So, here is the code for wich i want to make that "login" with a word or when i make a call from a number what is set to send me the message with location.
Why does the SIM900 instance have a good name while the ss instance has a stupid name?
Now you have entire story
Not by a long shot. The code you posted does NOT look for an SMS with the word login in it. The code does SOMETHING. You STILL, despite repeated requests, have NOT told us what the code ACTUALLY does.
Do not bother posting again if you are not going to tell us what the code actually does.
By the way, I think you are flogging a dead horse. You can NOT listen to the SIM900 and a GPS at the same time.
SIM900.listen();
if (SIM900.available())
{
while (SIM900.available()) // reading data
{
buffer[count ] = SIM900.read(); // writing data
if (count == 64)break;
}
Serial.write(buffer, count); // if no data transmission ends, write buffer
while (GpsSerial.available())
{
While the SIM900 instance is listening, the GpsSerial instance is not. There will never be data in the GpsSerial buffer while the SIM900 instance is listening.
Quit beating a dead horse. Get a Mega with multiple hardware serial ports.