2023-06-16 15:53:48 +02:00
|
|
|
from ipyleaflet import Map, Marker
|
|
|
|
import pynmea2
|
|
|
|
import serial
|
|
|
|
import io
|
|
|
|
|
2023-06-17 13:05:18 +02:00
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5.0)
|
2023-06-16 15:53:48 +02:00
|
|
|
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
|
2023-06-17 13:05:18 +02:00
|
|
|
last_time = 00
|
2023-06-16 15:53:48 +02:00
|
|
|
|
2023-06-17 13:05:18 +02:00
|
|
|
while True:
|
2023-06-16 15:53:48 +02:00
|
|
|
try:
|
2023-06-17 13:05:18 +02:00
|
|
|
line = sio.readline().rstrip('\n') # Remove newline character
|
2023-06-16 15:53:48 +02:00
|
|
|
msg = pynmea2.parse(line)
|
2023-06-17 13:05:18 +02:00
|
|
|
latitude = msg.latitude
|
|
|
|
longitude = msg.longitude
|
|
|
|
time = msg.timestamp
|
2023-06-16 15:53:48 +02:00
|
|
|
except serial.SerialException as e:
|
2023-06-17 13:05:18 +02:00
|
|
|
# print('Device error: {}'.format(e))
|
2023-06-16 15:53:48 +02:00
|
|
|
break
|
|
|
|
except pynmea2.ParseError as e:
|
2023-06-17 13:05:18 +02:00
|
|
|
# print('Parse error: {}'.format(e))
|
2023-06-16 15:53:48 +02:00
|
|
|
continue
|
2023-06-17 10:55:28 +02:00
|
|
|
except Exception as e:
|
|
|
|
continue
|
2023-06-16 15:53:48 +02:00
|
|
|
else:
|
2023-06-17 13:05:18 +02:00
|
|
|
if last_time == 00:
|
2023-06-17 10:55:28 +02:00
|
|
|
center = (latitude, longitude)
|
|
|
|
m = Map(center=center, zoom=15)
|
|
|
|
marker = Marker(location=center, draggable=False)
|
2023-06-17 13:05:18 +02:00
|
|
|
m.add_layer(marker)
|
2023-06-17 10:55:28 +02:00
|
|
|
display(m)
|
2023-06-17 13:05:18 +02:00
|
|
|
last_time = time
|
2023-06-17 10:55:28 +02:00
|
|
|
else:
|
2023-06-17 13:05:18 +02:00
|
|
|
marker.location = (latitude, longitude)
|
|
|
|
last_time = time
|