Use Python to access the device location data

The location submodule enables access to the location data for the TX64 device.

The module takes a snapshot of location data stored in the runt database. The location data snapshot can be subsequently updated by using the update method.

Determine if the device's location

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the TX64 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the location submodule:
    >>> from digidevice import location
  4. Use the valid_fix object to determine if the device has a valid fix:
    >>> loc = location.Location()
    >>> loc.valid_fix
    True
    >>>
  5. Use the position object to return the device's position:
    >>> loc.position
    (44.926195299999998, -93.397084499999999, 292.39999399999999)
    >>> 

    The coordinates are returned in the following order:

    latitude, longitude, altitude

    altitude is in meters.

  6. You can also return only one of the coordinate positions:

    • Use the latitude object to return the latitude:
      >>> loc.latitude
      44.926195299999998
      >>>
    • Use the longitude object to return the longitude:
      >>> loc.longitude
      -93.397084499999999
      >>>
    • Use the altitude object to return the altitude, in meters:
      >>> loc.altitude
      292.39999399999999
      >>>

  7. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().

Update the location data

The location submodule takes a snapshot of the current location and stores it in the runtime database. You can update this snapsot:

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the TX64 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the location submodule:
    >>> from digidevice import location
  4. Update the location object with the latest location data:
    >>> loc = location.Location()
    >>> loc.position
    >>> (44.926195299999998, -93.397084499999999, 292.39999399999999)
    >>> loc.update()
    >>> loc.position
    44.926231, -93.397923, 289.439229
    >>>
  5. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().

Output location data in json format

The location submodule takes a snapshot of the current location and stores it in the runtime database. You can update this snapsot

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the TX64 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the json submodule:
    >>> import json
  4. Import the location submodule:
    >>> from digidevice import location
  5. Print the location data in json format:

    >>> geojson_data = location.Location().geojson
    >>> print(json.dumps(geojson_data, indent=4))
    {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates" [
                44.926195299999998,
                -93.397084499999999,
                273.20001200000002
            ]
        },
        "properties": {
            "direction": "None",
            "horizontal_velocity": "0.0",
            "latitude.deg_min_sec": "44* 54' 45.586\" N",
            "longitude.deg_min_sec": "93* 33' 52.334\" W",
            "num_satellites": "12",
            "quality": "Standard GNSS (2D/3D)",
            "selected_source_idx": "0",
            "source": "USB (/dev/ttyACM0)",
            "source_idx.0.altitude": "273.200012",
            "source_idx.0.direction": "None",
            "source_idx.0.horizontal_velocity": "0.195489",
            "source_idx.0.label": "usb",
            "source_idx.0.latitude": "44.902662",
            "source_idx.0.latitude.deg_min_sec": "44* 55' 45.065\" N",
            "source_idx.0.longitude": "-93.560648",
            "source_idx.0.longitude.deg_min_sec": "93* 16' 52.966\" W",
            "source_idx.0.num_satellites": "12",
            "source_idx.0.quality": "Standard GNSS (2D/3D)",
            "source_idx.0.utc_date_time": "Sept-29-2023 12:10:00",
            "source_idx.0.vertical_velocity": "0.0",
            "source_idx.1.label": "gnss",
            "source_idx.1.quality": "No Fix / Invalid",
            "state": "Enabled, signal",
            "utc_date_time": "Sept-29-2023 12:10:00",
            "vertical_velocity": "0.0"
        }
    }
    >>>

  6. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().