pytrack sample code



  • can somebody post sample code to get the LAT and LONG from the pytrack module and post to TTN ?



  • @abhishek2101 they're linked below in @jcaron's post:

    ...
    You should probably try to dump more information from the GPS chip so see what's going on. Also note that the L76GNSS.py module is pretty basic (for instance it only parses GPS data, while the chip is capable of using other GNSS). You should explore alternatives, such as:



  • @dan
    can you link them here please.



  • @abhishek2101 you can try both, whichever works



  • @dan
    so which libraries I should use ?



  • @jcaron I've added the links to the docs, thanks. I've also opened an issue about adding support for GPGLL.



  • @dan it may make sense to add links to those libraries in the documentation (tutorials and reference).

    Actually, reading https://forum.pycom.io/topic/2992/pytrack-gps-library-only-works-with-glonass-derived-positions again, the Pycom lib only listens for GLONASS signals (GNGLL) and ignores GPS signals (GPGLL). This should definitely be fixed. It's probably a matter of adding something like:

    if gngll_idx < 0:
        gngll_idx = nmea.find(b'GPGLL')
    

    just after line 58. Didn't try it (don't have a Pytrack).



  • @abhishek2101 said in pytrack sample code:

    @dan
    Google maps on my iPhone shows my location at the same place within few seconds.

    Apples and oranges.

    A pure GPS device (like the Pytrack) needs to following to find its position:

    • the almanac, which gives a list of their satellites, their orbits, correction parameters, etc.
    • signal from at least 4 satellites, from which it will derive their position (ephemeris) and differential time of arrival.

    The full almanac takes at least 12.5 minutes to receive (provided you can actually receive the signal from at least one satellite), as the GPS signal has very very low bandwidth (50 bits/s) and only a small part of it is available for the almanac. Note that those 12.5 minutes start from the time the GPS receiver has locked onto at least one satellite, which may take a while as well.

    Locking on satellites may take a few minutes. It's a lot faster once you have an almanac and know your approximate position as you'll know which satellites should be visible. Otherwise it's just a matter of scanning for them. The almanac is also required for correction data.

    A phone does several things very differently, because it has access to the Internet. The GPS is actually often used as a last resort:

    • first, it uses nearby cell towers and Wi-Fi APs. It sends a list of what it "sees" to a server, which in turn gives it a position. This is often done in the background, so when you start the app, the phone actually already knows its position. Depending on the environment, this position may be very accurate, or a lot less. This is visible with the "circle of confidence" shows in maps (the light blue disc around the small blue dot). In dense urban environments, it's usually nearly as precise as GPS, and it works indoors.

    • if the phone decides to actually use the GPS chip, it can retrieve the almanac (and more) from the Internet instead of receiving it over GPS

    • it already knows its approximate position, so it makes it easier to select satellites to scan for

    • once if has locked onto satellites, it will adjust the position it thought it had with the (usually) more precise GPS location.

    Now, back to the "pure GPS" Pytrack: it is normal for it to take a while especially at first (not sure if/how the chip actually saves data for future uses), as it needs to receive the almanac, and find satellites. Once it has locked on enough satellites, it should be able to deliver a position pretty quickly.

    You should probably try to dump more information from the GPS chip so see what's going on. Also note that the L76GNSS.py module is pretty basic (for instance it only parses GPS data, while the chip is capable of using other GNSS). You should explore alternatives, such as:



  • @abhishek2101 said in pytrack sample code:

    I am outside with pytrack having access to open sky.

    You have to learn more about the GPS stuff. The pycom library is very basic, you have to know more anyway or have to use a third party library.

    You need wide area of clear sky, nice weather and no noise on the frequencies. It needs some time for the GPS chip to see enough satellites for a triangulation. If you just outside a building or next to a steep mountain, you may be in the shadow of this obstacle.

    Your phone will do some tricks. First it guesses your position from the last call. It uses a frequently loaded file of statellite positions to reduce search time. Additional it may guess your postion by lookng for a set of known WiFis and their signal strength.

    The pycom module does none of this tricks. So locking needs longer. In some cases a better antenna or a better position will solve the connection problem, but there is no connector for an external antenna :(



  • @abhishek2101 said in pytrack sample code:

    @dan
    I am outside with pytrack having access to open sky.

    following is the code

    from L76GNSS import L76GNSS
    from pytrack import Pytrack
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    while (True):
    
        coord = l76.coordinates()
        print(coord)
    

    still after 20 minutes I only see (none, none).

    One only I saw coordinate values but that came in after approx 40 minutes.

    How are we suppose to use pytrack if it takes so long to lock onto satellites (that too, not always) or am I missing anything. Please help.

    need to fix this asap, can somebody help.



  • @dan
    I am outside with pytrack having access to open sky.

    following is the code

    from L76GNSS import L76GNSS
    from pytrack import Pytrack
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    while (True):
    
        coord = l76.coordinates()
        print(coord)
    

    still after 20 minutes I only see (none, none).

    One only I saw coordinate values but that came in after approx 40 minutes.

    How are we suppose to use pytrack if it takes so long to lock onto satellites (that too, not always) or am I missing anything. Please help.





  • @dan
    can you share the code you used.



  • @dan
    Google maps on my iPhone shows my location at the same place within few seconds.



  • @abhishek2101 could you check the GPS coverage at your location? I have tested it here at the office and got the coordinates within a few seconds. I don't think it's a software or hardware issue.



  • @dan
    I will try and report back.

    But taking 30 min to lock onto satellites is simply not acceptable. It makes pytrack unusable.



  • @abhishek2101 have you tried what @catalin recommended?

    @catalin said in pytrack sample code:

    hi @abhishek2101, it seems you have a GPS problem. I would recommend:

    • leave the pytrack for 30 mins outside, to pick-up the satellites data, as this is a cold-start, could take a while
    • check, with a mobile app, how many satellites are visible on your exact position, it could be a glitch


  • @dan
    Mine always return none even after initialising for 300 seconds.

    Can you help please ?



  • @abhishek2101 It's just the timeout for locking onto a satellite, so if after 180 seconds it doesn't find one, it returns None. In the example, we have 30.

    It's just for the initialisation. After that, if you have it in a while(True) loop for example, it'll update around every second.



  • @dan
    mine is set for 180 seconds, that should be enough time to lock onto satellites, right ?

    if this time is less, what do you think is the ideal time ?

    does this mean that every update happens after 180 seconds, or it the first one only ?


Log in to reply
 

Pycom on Twitter