Sim808 Car GPS Alarm SMS restart issues

Hello everyone,

this is my first post and since I only have very litte knowledge about coding, please don’t judge me to hard :slight_smile: I guess there might be a better way to write my program and also format it, so I’m open to get some ideas :slight_smile:

Here is a short explanation of my project:
I want to build a GPS car alarm tracker. I know there are many videos and topics and I have read many of them but non of them worked for me or my setup (will explain later). I porbably could buy a commercial one but I like the challange and to learn it for myselfe.
So in principle what the tracker should be able to do in the final version is the following. When somebody enters my car, a PIR sensor detects the motion and sends me an alarm message. Aditionally I want to be able to track my car or maybe set up a geo fence. Everything should be controlled via SMS.

So far I more or less merged the two examples of the Fona Library (GPS and send and receive SMS). At the moment I can send an SMS, switch GPS on/off and get coordinates into the Serial Monitor ;D

Here is my setup:
Arduino UNO (later NANO or PRO MINI), Sim808 EVB 3.2

Problem:
I would be happy to get the SMS with the googlemaps link and have a solid foundation of code to add more SMS commands and functions if I want :slight_smile:
But as soon I turn on the SMS code at line 291 in the function getGPS() the arduino restarts once I send the command with SMS.
Similar thing happens if I turn on the SMS command in line 224, which just returns the message I sent previously ONLY that it works for one time, after the second it looks like the arduino restarts.
I’ve read something of memory problems when this happens but I’m not sure if this happens in my case. I also found that it might be caused by the Serial.println(), I will try that later to comment them out.

So far I’m super happy with the code, for my standards :wink: and if you have any suggestions or tipps how I can get it running better I would be very thankfull.

You can find the .ino file attached

Cheers,
Kilocheat

KiloTracker_Foru.ino (10.3 KB)

const int gsmOnOff = 13; //Define pin for powering GSM modul

Wouldn't gsmPower be a better name? Or powerPin?

int caseCounter = 0;

You are not counting cases.

  while (!Serial);

You only need that on models with 32U4 chips, which the UNO doesn't have.

You ARE fond of useless delay()s, aren't you?

// read sent SMS and set caseCounter according to message to exectue desired action
void getSendSMS()

So, why isn't the function called getSentSMS()?

      sprintf(message2, "https://maps.google.com/?q=""%s,%s""%s""%s,%s%s",LAT,LONG,middle,LAT,LONG,endit);

What, EXACTLY, is in message2 after this statement executes?

char replybuffer[255]; // this is a large buffer for replies

Where do you use this array? You are locking up 1/8th of your memory for an array you never use.

char smsBuffer[250];

Perhaps giving ChattyKathy your mobile number isn't a good idea.

        if ( smsBuffer[0] == option_1[0] &&  smsBuffer[1] == option_1[1] && smsBuffer[2] == option_1[2] && smsBuffer[3] == option_1[3] && smsBuffer[4] == option_1[4]) {

memcmp() would certainly involve less typing.

I've read something of memory problems when this happens but I'm not sure if this happens in my case

Google "Arduino Free Memory" and learn.

Hey,

@PauS thank you very much for your fast and helpful answer.

      sprintf(message2, "https://maps.google.com/?q=""%s,%s""%s""%s,%s%s",LAT,LONG,middle,LAT,LONG,edit);

I thought that message2 now contains the link and can be send to my mobile number. At least when I print it in Serial Monitor, I get the Link.

char replybuffer[255]; // this is a large buffer for replies

Thanks for this one, probably came along when I mixed the two examples :slight_smile:

char smsBuffer[250];

Perhaps giving ChattyKathy your mobile number isn't a good idea.

Who would get my mobile number and why? smsBuffer only contains the message and if the mobile number of the sender doesn't fit to my one nothing happens. Or did I misunderstand something there?

I will check the memcmp(). If I'm correct I would do something like:

char str1[15];
char str2[15];
int result;
result = memcmp(str1, str2, 5);

At least when I print it in Serial Monitor, I get the Link.

I expected you to share that with us.

Who would get my mobile number and why?

Anyone you gave it to, for whatever reason you gave it to them.

smsBuffer only contains the message and if the mobile number of the sender doesn't fit to my one nothing happens.

But all your messages are very short. Do you REALLY need a 250 character buffer to hold the 5 character valid messages?

Or did I misunderstand something there?

Perhaps I was too subtle.

Hello again,

thank you again for your answer. It helped me already a lot. I deleted the not used variable and made the smsBuffer smaller. So far i can get the location link (googlemaps) as an sms ;D and in the serial monitor, which looks like this:

> https://maps.google.com/?q=50.470776,11.445034&ll=50.470776,11.445034&z=20

Don't worry this is not my location, I changed some numbers :wink:

The next thing I want to integrate is the memcmp() to validate my mobile number and the messages. Maybe also a sleep mode to reduce the power consumption, I just saw the low power.h for the arduino.

If you have any more comments, tipps to get the code smoother I'd be very happy.

Thanks.

Cheers.

If somebody wants to have the code I can post my updated version