Untitled
raw download clone
TEXT
views 73
,
size 836 b
#!/usr/bin/env python

import paho.mqtt.client as mqtt
import serial
import time
import pynmea2
import threading
import sys


serialStream_gps = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)
mqttc = mqtt.Client()
mqttc.connect("vps2.lawanghosting.pw", 1883, 60)
mqttc.loop_start()
data_lat=dict()
data_lon=dict()
data_nmea=""
id=1
while True:
    try:
        sentence = serialStream_gps.readline()
	       # time.sleep(1)
    except KeyboardInterrupt:
        streamer.close()
    if sentence.find('GGA') > 0:
        data_nmea = pynmea2.parse(sentence)
        lon=data_nmea.longitude
        lat=data_nmea.latitude
        data_out="%s,%s,%s" %(id,lat,lon)
        print data_out
        print "{time}".format(time=data_nmea.timestamp)

        mqttc.publish("OBU/gps",data_out)
close fullscreen
Login or Register to edit or fork this paste. It's free.