forked from aniket11bh/i-Bike_DevelopmentCodes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGSM_test1.ino
113 lines (96 loc) · 2.23 KB
/
GSM_test1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
int count_nl=0;
int gsm_flag=0;
String gsm_inputString="";
String gsm_latilongistring="";
String gsm_string;
String gsm_lati="", gsm_longi="";
int gsm_move_status_flag=0;
float gsm_v_lati,gsm_v_longi;
void serialEvent3()
{
while(Serial3.available()>0)
{
char inchar = (char)Serial3.read();
gsm_inputString+= inchar;
delayMicroseconds(150);
if(inchar == '\n')
count_nl++;
if (count_nl == 3)
{
gsm_string = gsm_inputString;
gsm_flag=1;
Serial.println(gsm_inputString);
count_nl=0;
gsm_inputString="";
} //must print wanted string
}
}
void call_gsm( String input)
{
if(gsm_flag == 1) //inplies a message was received
{
int i,j,k;
gsm_latilongistring="";
for( i=0 ; input[i] != '\n'; i++)
{
}
i++;
for ( i>0 ; input[i] != '\n' ; i++)
{
}
i++;
for (j=0 , i>0 ; input[i] != '\n' ; i++,j++)
{
gsm_latilongistring+=input[i];
}
//gsm_latilongistring[j]=',';
Serial.println(gsm_latilongistring);
//Parsing lati longi
for( j=0; gsm_latilongistring[j] !=',' ; j++)
{
gsm_move_status_flag = int(gsm_latilongistring[j])-48;
}
j++;
for( k=0 , j>0 ; gsm_latilongistring[j] !=',';j++,k++)
{
gsm_lati += gsm_latilongistring[j];
}
gsm_lati[k]='\0';
j++;
for( k=0 , j>0 ; gsm_latilongistring[j] !=',';j++,k++)
{
gsm_longi += gsm_latilongistring[j];
}
gsm_longi[k]='\0';
j++;
//converting to actual values
gsm_v_lati=gsm_lati.toFloat();
gsm_v_longi=gsm_longi.toFloat();
Serial.print("lati=");Serial.println(gsm_v_lati,8);
Serial.print("longi=");Serial.println(gsm_v_longi,8);
gsm_flag=0;
}
}
void modem_initialization(void)
{
Serial3.print("AT\r");// Attention command to wake up GSM modem
delay(500);
Serial3.print("ATE0\r");
delay(200);
Serial3.print("AT+CMGF=1\r"); // setting up GSM in text mode
delay(500);
Serial3.print("AT+CNMI=1,2,0,0,0\r"); // setting up GSM in text mode
delay(500);
}
void setup() {
Serial.begin(38400);
Serial3.begin(38400);
gsm_inputString="";
modem_initialization();
// put your setup code here, to run once:
}
void loop()
{
call_gsm(gsm_string);
Serial.println("lalallallallalalllalalallalallalallala");
}