Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- import time
- import httplib
- import RPi.GPIO as GPIO
- gpsModule = serial.Serial('/dev/ttyUSB0',9600)
- gpsModule.timeout = 1
- GPIO.cleanup()
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(16, GPIO.OUT)
- if gpsModule.closed:
- gpsModule.open()
- def uploadLocation(Lat,Long):
- try:
- httpRequest = httplib.HTTPConnection("trackchild.byethost16.com")
- httpRequest.request("GET","/insertLocation.php?value=" + Lat + "|" + Long)
- client = httpRequest.getresponse()
- print client.read()
- except Exception as e:
- print e
- while True:
- count = 0
- latitude = 0
- longitude = 0
- oldLatitude = 0
- oldLongitude = 0
- dataString = ""
- dataString = gpsModule.readline()
- print dataString
- try:
- if (dataString.find("$GPRMC") > -1):
- splitedData = dataString.split(",")
- for values in splitedData:
- if (count == 3):
- rawLatitude = float(values)
- degree = (int(rawLatitude/100))*100
- minute = (rawLatitude - degree)/60
- degree = degree/100
- latitude = float("{0:.5f}".format(degree + minute))
- print latitude
- if (count == 5):
- rawlongitude = float(values)
- degree = (int(rawlongitude/100))*100
- minute = (rawlongitude - degree)/60
- degree = degree/100
- longitude = float("{0:.5f}".format(degree + minute))
- print longitude
- gpsModule.flushInput()
- count = count + 1
- uploadLocation(str(latitude),str(longitude));
- except Exception as e:
- print e
- GPIO.output(16,True)
- time.sleep(0.5)
- GPIO.output(16,False)
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement