-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgpsStream.py
More file actions
27 lines (22 loc) · 741 Bytes
/
gpsStream.py
File metadata and controls
27 lines (22 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
import socket
import gps
import time
session = gps.gps("localhost","2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
server_address = ('<broadcast>', 11445)
# Bir UDP Soket oluşturur
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(2)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while True:
rep = session.next()
time.sleep(1)
try:
if(rep["class"] == "TPV"):
message=str(rep.lat) + "/" + str(rep.lon) + "/" + str(rep.track)
# Veriyi gönderir.
sock.sendto(message.encode('ascii'), server_address)
except Exception as e:
message="noGPS"
sock.sendto(message.encode('ascii'), server_address)