Commit f60f9c140d87ed9f65400f7c92dd4c872b576052

Authored by Raymond Bakke Pedersen
1 parent 86855a7f

la til GPS_read

Showing 1 changed file with 70 additions and 0 deletions   Show diff stats
GPS_read 0 → 100644
  1 +import serial
  2 +import RPi.GPIO as GPIO
  3 +import time
  4 +
  5 +out_a = 16
  6 +out_b = 12
  7 +in_a = 20
  8 +in_b = 21
  9 +
  10 +GPIO.setwarnings(False)
  11 +GPIO.setmode(GPIO.BCM)
  12 +
  13 +GPIO.setup(out_a, GPIO.OUT, initial = 0)
  14 +GPIO.setup(out_b, GPIO.OUT, initial = 0)
  15 +
  16 +GPIO.setup(in_a, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  17 +GPIO.setup(in_b, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  18 +
  19 +ser = serial.Serial("/dev/ttyS0")
  20 +
  21 +while(1):
  22 + d_in=ser.readline().decode('ascii')
  23 + d_in = d_in.split(',')
  24 +
  25 + if d_in[0]==("$GPRMC"):#GPS
  26 + if d_in[2]=='A':
  27 + now = d_in[9]
  28 + tid = d_in[1]
  29 + time = tid[:2]
  30 + min = tid[2:4]
  31 + ar = now[3:]
  32 + mane=now[1:3]
  33 + dag = now[:1]
  34 + timezone = ("CET")
  35 + print('{}.{}.{}-{}:{} {}'.format(ar,mane,dag,time,min,timezone))
  36 + oclock = ('{}.{}.{}-{}:{} {}'.format(ar,mane,dag,time,min,timezone))
  37 +
  38 + latitude=d_in[3]
  39 + ltdg =latitude[:2]
  40 + ldg=float(ltdg)
  41 + lmdg=(latitude[2:])
  42 + limdg=float(lmdg)
  43 + lfddg=ldg+(limdg/60)
  44 + print('{},{}'.format(lfddg, d_in[4]))
  45 + lat = ('{}'.format(lfddg))
  46 +
  47 + longtitude=d_in[5]
  48 + lotdg =longtitude[:3]
  49 + lodg=float(lotdg)
  50 + lomdg=longtitude[3:]
  51 + loimdg=float(lomdg)
  52 + lofddg=lodg+(loimdg/60)
  53 + print('{},{}'.format(lofddg, d_in[6]))
  54 + lon = ('{}'.format(lofddg))
  55 +
  56 + GPIO.output(out_b, 1)
  57 + if GPIO.input(in_a):
  58 + f = open ('/var/www/html/index.html','a')
  59 +# tilfil = d_in[3]+'\t'+d_in[5]+'\n'
  60 + locInfo = '\n' + '<p>' + oclock + '\n' + lat + '\t' + lon + '\t' + 'star3' +'\t' + '1' + '\n' + <\p>
  61 + f.write(locInfo)
  62 + f.close()
  63 + print("Location saved!")
  64 + GPIO.output(out_a, 1)
  65 + else:
  66 + GPIO.output(out_a, 0)
  67 + else:
  68 + print("ERROR: Data is invalid")
  69 +
  70 +ser.close()
... ...