diff --git a/3-transport/lessons/1-location-tracking/code-gps-decode/pi/gps-sensor/app.py b/3-transport/lessons/1-location-tracking/code-gps-decode/pi/gps-sensor/app.py index a5de9192..098e1d84 100644 --- a/3-transport/lessons/1-location-tracking/code-gps-decode/pi/gps-sensor/app.py +++ b/3-transport/lessons/1-location-tracking/code-gps-decode/pi/gps-sensor/app.py @@ -22,10 +22,14 @@ def print_gps_data(line): print(f'{lat},{lon} - from {msg.num_sats} satellites') while True: - line = serial.readline().decode('utf-8') + try: + line = serial.readline().decode('utf-8') + + while len(line) > 0: + print_gps_data(line) + line = serial.readline().decode('utf-8') - while len(line) > 0: - print_gps_data(line) + except UnicodeDecodeError: line = serial.readline().decode('utf-8') time.sleep(1) diff --git a/3-transport/lessons/1-location-tracking/code-gps/pi/gps-sensor/app.py b/3-transport/lessons/1-location-tracking/code-gps/pi/gps-sensor/app.py index 0dfad1e9..11963a42 100644 --- a/3-transport/lessons/1-location-tracking/code-gps/pi/gps-sensor/app.py +++ b/3-transport/lessons/1-location-tracking/code-gps/pi/gps-sensor/app.py @@ -9,10 +9,14 @@ def print_gps_data(): print(line.rstrip()) while True: - line = serial.readline().decode('utf-8') + try: + line = serial.readline().decode('utf-8') + + while len(line) > 0: + print_gps_data() + line = serial.readline().decode('utf-8') - while len(line) > 0: - print_gps_data() + except UnicodeDecodeError: line = serial.readline().decode('utf-8') time.sleep(1)