serialrx 1.52 KB
import serial
import RPi.GPIO as GPIO
import time

out_a = 16
out_b = 12
in_a = 20
in_b = 21

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(out_a, GPIO.OUT, initial = 0)
GPIO.setup(out_b, GPIO.OUT, initial = 0)

GPIO.setup(in_a, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(in_b, GPIO.IN, pull_up_down=GPIO.PUD_UP)

ser = serial.Serial("/dev/ttyS0")

while(1):
	d_in=ser.readline().decode('ascii')
	d_in = d_in.split(',')
	
	if d_in[0]==("$GPRMC"):#GPS
		if d_in[2]=='A':
			now = d_in[9]
			tid = d_in[1]
			time = tid[:2]
			min = tid[2:4]
			ar = now[3:]
			mane=now[1:3]
			dag = now[:1]
			timezone = ("CET")
			print('{}.{}.{}-{}:{} {}'.format(ar,mane,dag,time,min,timezone))
			oclock = ('{}.{}.{}-{}:{} {}'.format(ar,mane,dag,time,min,timezone))

			latitude=d_in[3]
			ltdg =latitude[:2]
			ldg=float(ltdg)
			lmdg=(latitude[2:])
			limdg=float(lmdg)
			lfddg=ldg+(limdg/60)
			print('{},{}'.format(lfddg, d_in[4]))
			lat = ('{}'.format(lfddg))

			longtitude=d_in[5]
			lotdg =longtitude[:3]
			lodg=float(lotdg)
			lomdg=longtitude[3:]
			loimdg=float(lomdg)
			lofddg=lodg+(loimdg/60)
			print('{},{}'.format(lofddg, d_in[6]))
			lon = ('{}'.format(lofddg))

			GPIO.output(out_b, 1)
			if GPIO.input(in_a):
				f = open ('/var/www/html/index.html','a')
#				tilfil = d_in[3]+'\t'+d_in[5]+'\n'
				locInfo = oclock + '\n' + lat + '\t' + lon +'\n'
				f.write(locInfo)
				f.close()
				print("Location saved!")
				GPIO.output(out_a, 1)
			else:
				GPIO.output(out_a, 0)
		else:
			print("ERROR: Data is invalid")

ser.close()