2023-06-16 15:53:48 +02:00
|
|
|
from ipyleaflet import Map, Marker
|
|
|
|
import pynmea2
|
|
|
|
import serial
|
|
|
|
import io
|
|
|
|
|
2023-06-16 19:34:20 +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))
|
|
|
|
last_time=00
|
|
|
|
|
|
|
|
|
|
|
|
def check_last_update(time,last_time):
|
2023-06-16 19:34:20 +02:00
|
|
|
if time==last_time:
|
2023-06-16 15:53:48 +02:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
line = sio.readline()
|
|
|
|
msg = pynmea2.parse(line)
|
|
|
|
except serial.SerialException as e:
|
|
|
|
print('Device error: {}'.format(e))
|
|
|
|
break
|
|
|
|
except pynmea2.ParseError as e:
|
|
|
|
print('Parse error: {}'.format(e))
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if check_last_update(time=msg.timestamp,last_time=last_time)==True:
|
|
|
|
if last_time==00:
|
2023-06-16 19:34:20 +02:00
|
|
|
center = (msg.latitude, msg.longitude,)
|
|
|
|
m = Map(center=center, zoom=15)
|
2023-06-16 15:53:48 +02:00
|
|
|
marker = Marker(location=center, draggable=False)
|
|
|
|
m.add_layer(marker);
|
|
|
|
display(m)
|
2023-06-16 19:34:20 +02:00
|
|
|
last_time=msg.timestamp
|
2023-06-16 15:53:48 +02:00
|
|
|
else:
|
|
|
|
marker.location=(msg.latitude, msg.longitude)
|
|
|
|
last_time=msg.timestamp
|