The GPS part is working fine and parsing through pynmea module and i get a location fix which is very accurate
However now i want to be able to send this location data to googlemaps and have it pull that data and send me an SMS with the link of location but with the while true statement it will just keep looping GPS data. Don't want that i need it to end but allow me to carry on with the SMS commands after its done getting a location
Anyone know any sources for reading material to get this working ?
Everything i have seen is written for arduino and i tried to make it work through python but failed.
https://www.youtube.com/watch?v=qQnjlwf-8yQ
I have looked into possibly sending the data via googlemaps api through http but this modem only supports 2G which is 385kb/s max which i don't think would be enough plus its only a testing ground for now anyway so thats not important.
Code: Select all
#!/usr/bin/python
import serial, time, pynmea2
#Enable Serial Communication
ser = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
#Transmitting AT Commands to the Modem
#\r indicates the Enter key
ser.flushOutput()
ser.flushInput()
ser.write('AT'+'\r') #Check to see if modem is responding
str = ser.readline()
print str
time.sleep(5)
ser.write('AT+CGNSPWR=1,AT+CGPSSTATUS=?'+'\r') #Turns on the GPS power
while str.find ("Location") > 1:
print ('Waiting for a fix - ',str)
ser.flushInput()
ser.flushOutput()
time.sleep(15)
str = ser.readline(100)
ser.write('AT+CGPSOUT=32'+'\r') #Outputs raw NMEA data
str = ser.readline()
print str
time.sleep(3)
ser.write('AT+CGNSTST=1'+'\r') #Starts sending data to UART
str = ser.readline()
print str
time.sleep(5)
#Parsing Raw NMEA data through pynmea2
ser.flushInput()
ser.flushOutput()
def parseGPS(str):
if str.find("GGA") > 0:
data = pynmea2.parse(str)
print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s " % (data.timestamp, data.latitude, data.lat_dir, data.longitude, data.lon_dir)
while True:
str = ser.readline()
parseGPS(str)
Code: Select all
#!/usr/bin/python
import serial
import time
ser = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
ser.write('ATE=0'+'\r\n')
ser.read()
print ser
time.sleep(.1)
ser.write('AT+CMGF=1'+'\r\n')
ser.read(10)
print ser
time.sleep(.1)
ser.write('AT+CNMI=2,1,0,0,0'+'\r\n')
ser.read(10)
print ser
time.sleep(.1)
ser.write('AT+CMGS="xxxxxxxxxxx"'+'\r\n')
ser.read(10)
print ser
time.sleep(.1)
ser.write('something http://googlemaps=loc etc etc'+'\r\n')
ser.read(10)
print ser
time.sleep(.1)
ser.write("\x1A")
for i in range(10):
ser.read(10)
print ser