pytrack coordinates() issue



  • coordinates() returns (None, None) in every cca. 5th execution. GPS lock is stable, it is an NMEA reading/parsing issue.



  • @this.wiederkehr said in pytrack coordinates() issue:

    Yes, I also noticed, that the library is not very well programmed and does not honor the quectel specifics. There is an information manuel from quectel regarding the i2c operation which gives guidlines on how to get the data (downloadable from the webpage if you login).

    Thanks a lot for sharing your code, I will try it as soon as I can.

    Regards... Béla



  • @joeri said in pytrack coordinates() issue:

    You can use this check to determine if a timeout occurred

    The issue is not how to check it was a timeout or not. The issue is why there is a random timeout at all?



  • Yes, I also noticed, that the library is not very well programmed and does not honor the quectel specifics. There is an information manuel from quectel regarding the i2c operation which gives guidlines on how to get the data (downloadable from the webpage if you login).

    The noteworthy things are

    • They have an internal i2c buffer which is 255 bytes
    • The buffer takes 2 ms to refill
    • The last byte always is 0x0a
    • Buffer is always filled with 0x0a from the front or to the end.
    • If interval is set to 1sec they propose to read all sentences available all 0.5 sec (in order not to loose any data).

    Here is my own attemp for a method to get the sentences and do the checksum check.
    This puts the sentences into self.sentences as bytes. You have to use your own parser to get the data from the sentences.

        def get_sentences(self):
            done = True
            leftover = b''
            self.gps_data = self.gps_default
            valid_sentences = []
            while done:
                buffer = self.i2c.readfrom(GPS_I2CADDR, 255)
                last_read_time = utime.ticks_us()
                sentences = buffer.lstrip(b'\n').rstrip(b'\n').split(b'\n')
                length = sum(len(sentence) for sentence in sentences) + len(sentences) + 1
                if length < 255 and buffer[-3] == b'\n'[0]:
                    done = False
                    sentences[0] = leftover + sentences[0]
                else:
                    sentences[0] = leftover + sentences[0]
                    leftover = sentences.pop()
    
                for sentence in sentences:
                    if len(sentence) == 0:
                        continue
                    if sentence[0] == b'$'[0] and sentence[-1] == b'\r'[0]:
                        if self._test_checksum(sentence):
                            valid_sentences.append(sentence)
                diff = utime.ticks_us() - last_read_time
                if diff < 2000:
                    utime.sleep_us(2000-diff)
            self.sentences = valid_sentences
    
        def _test_checksum(self, sentence):
            l = sentence[1]
            for c in sentence[2:-4]:
                l = l ^ c
            if l == int(sentence[-3:-1], 16):
                return True
            return False
    


  • You can use this check to determine if a timeout occurred

        # Activate the GNSS
        l76 = L76GNSS(pytrack, timeout=60) # GSP timeout set to 60 seconds
        
        # Get gps fix
        gpsResult = l76.coordinates()
    
        # Determine whether we got a valid fix
        if gpsResult == (None, None):
            print("No fix")
        else:
            print("fix lat: " + str(gpsResult[0]) + "long:" + str(gpsResult[1]))
    


  • @bmarkus
    coordinates() returns (None, None) if a timeout occurs. You can verify this with coordinates(debug=True). See previous topic "pytrack false timeouts" for a possible solution.


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.