Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-020
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
O.V.B Sewmina
2022-020
Commits
d9f3c6d1
Commit
d9f3c6d1
authored
May 13, 2022
by
Nirman M.A.H.L
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update gps.ino
parent
438d9be1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
180 additions
and
0 deletions
+180
-0
gps.ino
gps.ino
+180
-0
No files found.
gps.ino
0 → 100644
View file @
d9f3c6d1
#define TINY_GSM_MODEM_SIM800
#define TINY_GSM_RX_BUFFER 256
#include <TinyGPS++.h>
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
const
char
FIREBASE_HOST
[]
=
"ENTER_FIREBASE_HOST"
;
const
String
FIREBASE_AUTH
=
"ENTER_FIREBASE_AUTH"
;
const
String
FIREBASE_PATH
=
"/"
;
const
int
SSL_PORT
=
443
;
char
apn
[]
=
"internet"
;
char
user
[]
=
""
;
char
pass
[]
=
""
;
#define rxPin 4
#define txPin 2
HardwareSerial
sim800
(
1
);
TinyGsm
modem
(
sim800
);
#define RXD2 16
#define TXD2 17
HardwareSerial
neogps
(
2
);
TinyGPSPlus
gps
;
TinyGsmClientSecure
gsm_client_secure_modem
(
modem
,
0
);
HttpClient
http_client
=
HttpClient
(
gsm_client_secure_modem
,
FIREBASE_HOST
,
SSL_PORT
);
unsigned
long
previousMillis
=
0
;
long
interval
=
10000
;
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
(
"esp32 serial initialize"
);
sim800
.
begin
(
9600
,
SERIAL_8N1
,
rxPin
,
txPin
);
Serial
.
println
(
"SIM800L serial initialize"
);
neogps
.
begin
(
9600
,
SERIAL_8N1
,
RXD2
,
TXD2
);
Serial
.
println
(
"neogps serial initialize"
);
delay
(
3000
);
Serial
.
println
(
"Initializing modem..."
);
modem
.
restart
();
String
modemInfo
=
modem
.
getModemInfo
();
Serial
.
print
(
"Modem: "
);
Serial
.
println
(
modemInfo
);
http_client
.
setHttpResponseTimeout
(
90
*
1000
);
}
void
loop
()
{
Serial
.
print
(
F
(
"Connecting to "
));
Serial
.
print
(
apn
);
if
(
!
modem
.
gprsConnect
(
apn
,
user
,
pass
))
{
Serial
.
println
(
" fail"
);
delay
(
1000
);
return
;
}
Serial
.
println
(
" OK"
);
http_client
.
connect
(
FIREBASE_HOST
,
SSL_PORT
);
while
(
true
)
{
if
(
!
http_client
.
connected
())
{
Serial
.
println
();
http_client
.
stop
();
// Shutdown
Serial
.
println
(
"HTTP not connect"
);
break
;
}
else
{
gps_loop
();
}
}
}
void
PostToFirebase
(
const
char
*
method
,
const
String
&
path
,
const
String
&
data
,
HttpClient
*
http
)
{
String
response
;
int
statusCode
=
0
;
http
->
connectionKeepAlive
();
String
url
;
if
(
path
[
0
]
!=
'/'
)
{
url
=
"/"
;
}
url
+=
path
+
".json"
;
url
+=
"?auth="
+
FIREBASE_AUTH
;
Serial
.
print
(
"POST:"
);
Serial
.
println
(
url
);
Serial
.
print
(
"Data:"
);
Serial
.
println
(
data
);
String
contentType
=
"application/json"
;
http
->
put
(
url
,
contentType
,
data
);
statusCode
=
http
->
responseStatusCode
();
Serial
.
print
(
"Status code: "
);
Serial
.
println
(
statusCode
);
response
=
http
->
responseBody
();
Serial
.
print
(
"Response: "
);
Serial
.
println
(
response
);
if
(
!
http
->
connected
())
{
Serial
.
println
();
http
->
stop
();
// Shutdown
Serial
.
println
(
"HTTP POST disconnected"
);
}
}
void
gps_loop
()
{
boolean
newData
=
false
;
for
(
unsigned
long
start
=
millis
();
millis
()
-
start
<
2000
;){
while
(
neogps
.
available
()){
if
(
gps
.
encode
(
neogps
.
read
())){
newData
=
true
;
break
;
}
}
}
if
(
true
){
newData
=
false
;
String
latitude
,
longitude
;
latitude
=
String
(
gps
.
location
.
lat
(),
6
);
longitude
=
String
(
gps
.
location
.
lng
(),
6
);
Serial
.
print
(
"Latitude= "
);
Serial
.
print
(
latitude
);
Serial
.
print
(
" Longitude= "
);
Serial
.
println
(
longitude
);
String
gpsData
=
"{"
;
gpsData
+=
"
\"
lat
\"
:"
+
latitude
+
","
;
gpsData
+=
"
\"
lng
\"
:"
+
longitude
+
""
;
gpsData
+=
"}"
;
PostToFirebase
(
"PATCH"
,
FIREBASE_PATH
,
gpsData
,
&
http_client
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment