Advertisement
locxtronic

Raspberry Pi Child Tracker

Jul 2nd, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. import serial
  2. import time
  3. import httplib
  4. import RPi.GPIO as GPIO
  5.  
  6. gpsModule = serial.Serial('/dev/ttyUSB0',9600)
  7. gpsModule.timeout = 1
  8.  
  9. GPIO.cleanup()
  10. GPIO.setmode(GPIO.BCM)
  11. GPIO.setup(16, GPIO.OUT)
  12.  
  13. if gpsModule.closed:
  14.     gpsModule.open()
  15.  
  16. def uploadLocation(Lat,Long):
  17.     try:
  18.        
  19.         httpRequest = httplib.HTTPConnection("trackchild.byethost16.com")
  20.         httpRequest.request("GET","/insertLocation.php?value=" + Lat + "|" + Long)
  21.         client = httpRequest.getresponse()
  22.         print client.read()
  23.        
  24.     except Exception as e:
  25.         print e
  26.        
  27. while True:
  28.  
  29.     count = 0
  30.     latitude = 0
  31.     longitude = 0
  32.     oldLatitude = 0
  33.     oldLongitude = 0
  34.     dataString = ""
  35.  
  36.     dataString = gpsModule.readline()
  37.     print dataString
  38.    
  39.     try:
  40.  
  41.         if (dataString.find("$GPRMC") > -1):
  42.             splitedData = dataString.split(",")
  43.             for values in splitedData:
  44.                 if (count == 3):
  45.                     rawLatitude = float(values)
  46.                     degree = (int(rawLatitude/100))*100
  47.                     minute = (rawLatitude - degree)/60
  48.                     degree = degree/100
  49.                     latitude = float("{0:.5f}".format(degree + minute))
  50.                     print latitude
  51.                 if (count == 5):
  52.                     rawlongitude = float(values)
  53.                     degree = (int(rawlongitude/100))*100
  54.                     minute = (rawlongitude - degree)/60
  55.                     degree = degree/100
  56.                     longitude = float("{0:.5f}".format(degree + minute))
  57.                     print longitude
  58.  
  59.  
  60.                 gpsModule.flushInput()
  61.                 count = count + 1
  62.  
  63.             uploadLocation(str(latitude),str(longitude));
  64.  
  65.  
  66.     except Exception as e:
  67.         print e
  68.  
  69.     GPIO.output(16,True)
  70.     time.sleep(0.5)
  71.     GPIO.output(16,False)
  72.     time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement