How to Identify GPS Coordinates as a String to be Sent to Cloud

Hi everyone.

I need to send GPS coordinates to dweet . io.

I am using a SIM7000E module connected to an arduino nano.

I can grab the coordinates using the AT command "AT+CGNSINF".

After that though, I need to be able to define the coordinates i get from "AT+CGNSINF" as a string so that i can input the string name into the URL to perform a get request to dweet.

This is my code currently.

#include <SoftwareSerial.h>

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

int rx=10;
int tx=11;

void setup() {
  
pinMode(tx,OUTPUT);
pinMode(rx,INPUT);

Serial.begin(9600);
delay(1000);

SIM7000E.begin(19200);
delay(1000);

Serial.println("Initialising");
delay(1000);

//setting up module

SIM7000E.print("ATE1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CPIN?\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CIMI\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CGSN\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CMNB=1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CNMP=38\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CBANDCFG=\"CAT-M\",28\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CGNAPN?\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+COPS?\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CSTT?\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CSTT=\"telstra.m2m\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CIICR\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CIFSR\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CIPPING=\"www.google.com\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+CDNSCFG=\"8.8.8.8\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+SAPBR=3,1,\"APN\",\"TELSTRA.M2M\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+SAPBR=1,1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+SAPBR=2,1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);
 
//getting GPS coordinates 

SIM7000E.print("AT+CGNSPWR=1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(5000);

SIM7000E.print("AT+CGNSINF\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(5000);

//sending data to dweet

SIM7000E.print("AT+HTTPINIT\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+HTTPPARA=\"CID\",1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+HTTPPARA=\"URL\",\"http://dweet.io/dweet/for/mything?*coordinates*\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPACTION=0\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPREAD\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPTERM\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:


}

Thanks for any help.

Instead of printing, use a character array to store the result of the AT+CGNSINF command; add a terminating '\0`. Next you can use standard functions (e.g. strtok, strchr, strstr, strcmp) to parse the received data. Note that the array nees to be big enough to store the data.

Can you post the typical data that you get when you issue the AT+CGNSINF command? Next modify your sketch to print the same data in HEX (as I'm not sure what the end of the data will be) and post it here.

Below the idea

  SIM7000E.print("AT+CGNSINF\r\n");
  while (SIM7000E.available()) {
    char ch = SIM7000E.read();
    Serial.write(ch);
    Serial.print(" ");
    if (ch < 0x10) {
      Serial.print("0");
    }
    Serial.println(ch, HEX);
  }
  delay(5000);

The idea for character arrays can be found in Serial Input Basics - updated. Example 2 will probably apply; adjust the size of the array to suite your needs (the number of characters in the longest reply plus one extra for the '\0'.use SIM7000E instead of Serial when reading. If the last HEX value that you see in the previously modified code is 0A, you don't need to change the endmarker; if it's 0D, you have to chance the endmarker to '\r'.

PS
Please use code tags when posting the received data.

1 Like

Wow thanks for the response.

Next modify your sketch to print the same data in HEX

Not exactly sure how to do this. I tried:

SIM7000E.print("AT+CGNSINF\r\n, HEX");

Did not change the output.

As for the output. It is as follows.

Initialising
AT+CGNSPWR=1

OK
AT+CGNSINF

+CGNSINF: 1,1,20220612051331.000,27.4705,153.02

The coordinates start at "27.". I changed the coordinates to the middle of Brisbane, AUS. But this is whats basically outputted.
Note that there should be more values being printed. However, its stops showing any characters after "02".
I dont know whether thatll be an issue.

Ill check out the link you attached.

So I inputted your code and I got back something different than before.

Initialising
A A
T T
+ +
C C
G G
N N
S S
P P
W W
R R
= =
1 1


O O
K K


A A
T T
+ +
C C
G G
N N
S S
I I
N N
F F

+ +
C C
G G
N N
S S
I I
N N
F F
: :
   
1 1
, ,
1 1
, ,
2 2
0 0
2 2
2 2
0 0
6 6
1 1
2 2
0 0
5 5
4 4
8 8
0 0
4 4
. .
0 0
0 0
0 0
, ,
- -
3 3
7 7
. .
2 2
2 2
1 1
5 5
7 7
6 6
, ,
1 1
5 5
3 3
. .
0 0
5 5
4 4
3 3
. .
, ,
0 0
4 4

I changed the coordinates again a little but this is what I got.

At first I got hexadecimal characters. I took out "HEX" so i could read them better and got these figures. I also took out "0x10" from line 6 and changed it to just "0". I ended up getting longer and more accurate coordinates for some reason.

Quick question: why does it output two columns of data?

Also, does this mean that the coordinates have been added to an array?

thanks

hm well you seem to need some more time to understand what the suggested code does.
And it would be very good for you to learn more basics about programming.

I got the impression that you are a real beginner, that did not yet understand what variables are.

this line of code

char ch = SIM7000E.read();

reads out a single byte from the receive-buffer of the serial interface of the SIM700-module
and stores this single character into the variable named "ch"

this line of code

Serial.write(ch);

prints a single character to the serial monitor

this line

Serial.print(" ");

prints a space

if (ch < 0x10) {
      Serial.print("0");
    }

prints a leading zero in case the value is smaller than 10

Serial.println(ch, HEX);

prints the same character that is stored into variable named "ch" as hexadecimal value.
Do you understand? the exact same value once printed as character in the second colum printed as hexadecimal value. THis is for analysing if the SIM700-module sends some non-printable characters.

Changing this to decimal is completely contradictionary

For learning more general basics
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

1 Like

in your original code things like

Send a hardcoded charactersequence to the SIM700 module
and then readout und print the received characters to the serial monitor
in the most compact and most direct way ever possible.

Most direct way means the characters are printed out and then these characters are lost
and can't be processed anymore. Processing the data is what you want to do.
You want to extract the coordinates from the received characters and then send them to some cloud-service.

And the only way to do this is to not directly print them by writing code like

Serial.write(SIM7000E.read());

You have to store the characters in an array of char.
The serial input basics shows how this can be done.

Attention !

The serial input basics tutorial assumes that you really know what variables and what arrays are. If you have not yet understood what variables and/or arrays are.
You should learn this before.

best regards Stefan

1 Like

You missed or did not understand the printing in HEX ( Serial.println(ch, HEX); )

1 Like

Thanks for the breakdown of the code. I initially assumed the two columns were both presenting data in hexadecimal format without a closer inspection.

I will check out the tutorial and do some more reading.

According to journal dev, an array of char is a string.

So the goal is to store the received coordinates in a string.

From there is it safe to assume that you can add the name of the string into a URL like:

http://dweet.io/dweet/for/mything?ch

and the coordinates will end up being sent?

I know I need to read more on the basics but Im so close to finishing this.

Yep youre right.

This is the output produced when using your code exactly:

Initialising
A 41
T 54
+ 2B
C 43
G 47
N 4E
S 53
P 50
W 57
R 52
= 3D
1 31

 0D

 0D

 0A
O 4F
K 4B

 0D

 0A
A 41
T 54
+ 2B
C 43
G 47
N 4E
S 53
I 49
N 4E
F 46

 0D

 0D

 0A
+ 2B
C 43
G 47
N 4E
S 53
I 49
N 4E
F 46
: 3A
  20
1 31
, 2C
1 31
, 2C
2 32
0 30
2 32
2 32
0 30
6 36
1 31
2 32
0 30
6 36
5 35
3 33
5 35
6 36
. 2E
0 30
0 30
0 30
, 2C
- 2D
4 72
7 37
. 2E
5 35
2 32
1 31
5 35
8 38
4 34
, 2C
3 51
5 35
3 33
. 2E
. 2E
5 35
. 2E
, 2C

 0A

Do you have any kind of demo-code that uses your SIM700-module and send any kind of data to that cloud-servcie that you want to send the data to?

The whole thing will not be as simple as sending an email from an Email-App to an Email-server.

An Email-App is doing a lot of stuff in the background to make it easy for the user of the app.
To get this easiness to the user is the result of a lot of hard work from the App-developper.
In this case you are the developper.

So which cloud-service do you want to use?
You will have to learn how to connect to this cloudservice
how authentification with this cloud-service works
how sending data to this cloud-service works etc.

In any way it is always a good idea to give an overview about your complete project.
There might be easier to achieve approaches to achieve the same goal.

best regards Stefan

1 Like

In the original post I have code showing how ill be sending the data and where.

I am simply using dweet.io.

The way it works is that you simply add the data you want to send in the url and perform a GET request.

For example: http://dweet.io/dweet/for/mything?*data*

From there, I can access the data from any device connected to the internet by typing into a browser "https://dweet.io/get/latest/dweet/for/mything

Code for sending to dweet via at commands:

//sending data to dweet

SIM7000E.print("AT+HTTPINIT\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+HTTPPARA=\"CID\",1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

SIM7000E.print("AT+HTTPPARA=\"URL\",\"http://dweet.io/dweet/for/mything?*coordinates*\"\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPACTION=0\r\n"); //get request
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPREAD\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(4000);

SIM7000E.print("AT+HTTPTERM\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);

As you know I need to add the gps coordinates i receive from the module to a array of char.

But the next problem I have is actually adding the contents of that particular string to the URL that will be used to make a GET request.

And then having this done every 5 minutes or so to complete the GPS tracker.

Ok so you want to replace coordinates in this string with your actual coordinates?

Something like...


const char header[]  = "AT+HTTPPARA=\"URL\",\"http://dweet.io/dweet/for/mything?";
const char trailer[] = "\"\r\n";
char coordinates[20] = "67.033333,172.55555";

void setup()
{
  
  Serial.begin(115200);

  char url[100]= "";
  strcat(url, header);
  strcat(url, coordinates);
  strcat(url, trailer);

  Serial.println(url);
}

void loop()
{
  
}

19:47:32.613 -> AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?67.033333,172.55555"

1 Like

steps do do:

  • adapting the function of the serial input basics to receive the answer from your SIM700-module into an array of char
  • learning how to parse this array of char until the characters of the coordinates begin
  • learning how to extract the coordinate characters from the array of char
  • learning how to append the coordinate-characters to another array of char to finally do
SIM7000E.print(myGetRequest);

best regards Stefan

1 Like

Only if it ends with a '\0', else it's just an array of char.

If ch is the variable, no. If ch is the value of the text, yes.

Take your time; Rome was not built in one day.

1 Like

Thank you

Ill try and work that into my code.

My only issue is:

char coordinates[20] = "67.033333,172.55555";

I dont want to have to manually input the coordinates

Of course... you will need to extract them from the response you get back from the GPS unit.

1 Like

Adafruit's GPS library will do all the parsing and return Lat/Lon as a type float.
Convert to type string by doing a little research:
C++ Arduino convert float to string - Google Search

1 Like

I added your code in.

It sort of works. However it prints one character from the array after the url and does that 20 times.


#include <SoftwareSerial.h>

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

int rx=10;
int tx=11;

//char ch[50];

const char header[]  = "AT+HTTPPARA=\"URL\",\"http://dweet.io/dweet/for/mything?";
const char trailer[] = "\"\r\n";
char ch[95];


void setup() {
  // put your setup code here, to run once:
String s;

pinMode(tx,OUTPUT);
pinMode(rx,INPUT);

Serial.begin(9600);
delay(1000);

SIM7000E.begin(19200);
delay(1000);

Serial.println("Initialising");
delay(1000);

SIM7000E.print("AT+CGNSPWR=1\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(5000);

SIM7000E.print("AT+CGNSINF\r\n");
  while (SIM7000E.available()) {
    char ch[95] = {SIM7000E.read()};
    
    char url[150]= "";
    strcat(url, header);
    strcat(url, ch);
    strcat(url, trailer);

  Serial.print(url);
  }

  delay(5000);
  

SIM7000E.print("AT\r\n");
while(SIM7000E.available())
Serial.write(SIM7000E.read());
delay(2000);


}

void loop() {
  // put your main code here, to run repeatedly:

}

Output:

Initialising
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?A"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?T"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?+"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?C"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?G"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?N"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?S"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?P"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?W"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?R"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?="
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?1"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?O"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?K"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?A"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?T"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?+"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?C"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?G"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?N"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?S"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?I"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?N"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?F"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?
"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?+"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?C"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?G"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?N"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?S"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?I"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?N"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?F"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?:"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything? "
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?1"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?,"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?1"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?,"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?2"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?2"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?2"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?6"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?1"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?6"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?5"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?4"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?8"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?4"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?7"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?."
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?0"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?,"
AT+HTTPPARA="URL","http://dweet.io/dweet/for/mything?,"

Doesnt get to the GPS coordinates numbers either. Stops after displaying time.

Ill take a look. Im skeptical because the module returns a bunch of other parameters with the coordinates like time, altitude, speed over ground etc.

Youre probably able to isolate the characters somehow though im guessing.

This sounds like you want to say : I get this result (posted output)
user @mrburnette can you go on developping code for me

@arackanev:

it is about time that user @arackanev starts to modify the given code so that user @arackanev

herself / himself

learns how to use string-manipulating functions

best regards Stefan