-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPS Sensor Code
66 lines (56 loc) · 2.33 KB
/
GPS Sensor Code
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
import time
import board
import busio
import adafruit_gps
import pyrebase
config = {
"apiKey": "AIzaSyBwQWFxeHPKHXG2WwrHGFIDxzNZN3X1X4k",
"authDomain": "qi6uycgHVvhL6iXir96ZR4vU3H73.firebaseapp.com",
"databaseURL": "https://bats-explorer-de16a-default-rtdb.firebaseio.com",
"storageBucket": "qi6uycgHVvhL6iXir96ZR4vU3H73.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
# If using I2C, we'll create an I2C interface to talk to using default pins
i2c = board.I2C() # uses board.SCL and board.SDA
# Create a GPS module instance.
gps = adafruit_gps.GPS_GtopI2C(i2c, debug=False) # Use I2C interface
# Turn on the basic GGA and RMC info (what you typically want)
gps.send_command(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
# Turn on just minimum info (RMC only, location):
# Set update rate to once a second (1hz) which is what you typically want.
gps.send_command(b"PMTK220,1000")
# Main loop runs forever printing the location, etc. every second.
last_print = time.monotonic()
while True:
gps.update()
# Every second print out current location details if there's a fix.
current = time.monotonic()
if current - last_print >= 1:
last_print = current
if not gps.has_fix:
# Try again if we don't have a fix yet.
print("Waiting for fix...")
continue
# We have a fix! (gps.has_fix is true)
# Print out details about the fix like location, date, etc.
print("=" * 40) # Print a separator line.
print(
"Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
gps.timestamp_utc.tm_mday, # struct_time object that holds
gps.timestamp_utc.tm_year, # the fix time. Note you might
gps.timestamp_utc.tm_hour, # not get all data like year, day,
gps.timestamp_utc.tm_min, # month!
gps.timestamp_utc.tm_sec,
)
)
# print("Latitude: {0:.6f} degrees".format(gps.latitude))
# print("Longitude: {0:.6f} degrees".format(gps.longitude))
dataGPS = {
"Latitude" : float(gps.latitude) ,
"Longitude" : float(gps.longitude)
}
db.child("GPS Data").push(dataGPS)
db.update(dataGPS)
time.sleep(30)