Complete the code to import the module needed to read serial data from the GPS module.
import [1]
The serial module is used to read data from the GPS module via serial communication.
Complete the code to open the serial port to read GPS data at 9600 baud rate.
ser = serial.Serial('/dev/ttyS0', [1])
The GPS module commonly communicates at 9600 baud rate, so we set it accordingly.
Fix the error in reading a line from the GPS serial port.
line = ser.[1]()The readline() method reads one line of data from the serial port, which is needed to get one GPS sentence.
Fill both blanks to decode the GPS data line and check if it starts with the correct prefix.
data = line.[1]('utf-8') if data.[2]('$GPGGA'):
GPS data from serial is bytes, so we decode it to a string. Then we check if the string starts with '$GPGGA' which is a GPS sentence type.
Fill all three blanks to create a dictionary with latitude, longitude, and fix quality from the GPS data fields.
fields = data.split(',') gps_info = { [1]: fields[int([2])], [3]: fields[4], 'fix_quality': fields[6] }
The latitude is in field 2, longitude in field 4, and fix quality in field 6. We create keys 'latitude' and 'longitude' for those fields.
