Skip to content

GPS Example

The GPS Device Service contains a pre-defined device that is registered with Edge Xpert when the service initializes. The GPS device is defined by a built-in device profile that ships with the GPS Device Service.

This example demonstrates how to use the GPS Device Service to connect to a GPS sensor. In this example, a GPS simulator is used.

Run the GPS simulator

To start the GPS simulator, enter the following command:

docker run --rm -d --name gps-sim -p 2947:2947 knowhowlab/gpsd-nmea-simulator
podman run --rm -d --name gps-sim -p 2947:2947 knowhowlab/gpsd-nmea-simulator

Note

You can run the real GPS device by setting up GPS Daemon. See GPS Daemon for more information.

Start the GPS Device Service

To start the GPS Device Service, enter the following command:

edgexpert up device-gps

Device Onboarding

The GPS Device Service initializes with a pre-configured device. This is a connection to the GPS daemon which acts as a bridge between the device service and GPS devices.

As the GPS Device Service does not connect to devices directly, device onboarding is not required with this Device Service. However, the device configuration properties are defined below for reference purposes.

Device Configuration Properties

The pre-defined device has the following properties:

Field Example Value Description Required
Name GPS The unique name used to identify the device Required
Description Global Positioning System Any additional information to help identify the device Optional
Labels GPS Coordinates Any additonal information to help identify the device Optional

Managing Auto Events with Edge Xpert Manager UI

Warning

The onboarded GPS device should not be modified for anything other than auto event management and protocol property settings. Changing other configuration values could cause adverse effects.

Although the device is pre-configured, it is possible to modify the GPS device to manage auto events to issue automated commands. The Edge Xpert GPS device can be modified to add, edit, and delete auto events. To manage auto events in Edge Xpert Manager UI, follow the below steps:

Note

Please refer to the Edge Xpert Manager UI Device Management capability for full details.

  1. Ensure the Edge Xpert Manager UI is started, for example:

    edgexpert up xpert-manager
    
  2. Open a browser and go to localhost:9090. The default username and password is admin.

  3. Navigate to Devices, and locate the GPS entry. Select the pencil icon to edit the device.

  4. Scroll down until you find Auto Events. Select the plus button and use the following to create an auto event:

    • Interval: 1s
    • On Change: false/unchecked
    • Resource Name: Latitude

    Create another with the following:

    • Interval: 1s
    • On Change: false/unchecked
    • Resource Name: Longitude

    This will create an auto event each for Latitude and Longitude. These will issue the relevant commands every second, regardless of whether the values have changed. To only receive auto events if data has changed within your specified interval, select the check box for On Change.

Managing Auto Events with Edge Xpert REST API

Warning

The onboarded GPS device should not be modified for anything other than auto event management and protocol property settings. Changing other configuration values could cause adverse effects.

The Edge Xpert GPS device can be modified to add, edit, and delete auto events. To manage auto events with Edge Xpert REST API commands, follow the steps below:

  • Retrieve the device ID with the following command:

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

curl http://localhost:59881/api/v2/device/name/GPS
  • Use the following cURL command to set up two auto events. Ensure you replace <device-id> with the ID retrieved in step one
curl -X 'PATCH' \
  'http://localhost:59881/api/v2/device' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '[
 {
    "apiVersion": "v2",
    "device": {
      "id": "<device-id>",
      "name": "GPS",
      "autoEvents": [
        {
          "interval": "1s",
          "onChange": false,
          "sourceName": "Latitude"
        },
        {
          "interval": "1s",
          "onChange": false,
          "sourceName": "Longitude"
        }
      ]
    }
  }
]'

This will create an auto event each for Latitude and Longitude. These will issue the relevant commands every second, regardless of whether the values have changed. To only receive auto events if data has changed within your specified interval, set OnChange to true.

  • Onboard the device by using the predefined device profile:

Note

If Edge Xpert is running in secure mode, you will need to pull the curlimages/curl and replace the localhost in the URL with the hostname for the service, see CLI service port for more information.

curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \
-d '[ {
        "apiVersion": "v2",
         "device": {
           "name" :"gps-sim",
           "description":"GPS simulator",
           "serviceName": "device-gps",
           "profileName": "GPS",
           "protocols":{
              "GPS":{
                  "GpsdConnTimeout": "2500",
                  "GpsdHostname": "<your_host_network_ip_address>",
                  "GpsdMode": "poll",
                  "GpsdPort": "2947",
                  "GpsdRequestTimeout": "5000",
                  "GpsdRetries": "5"
              }
           },
           "adminState":"UNLOCKED",
           "operatingState":"UP"
        }
    }
]'

Device Data Flow

Data flow between the Device Service and the connected device can be verified in a number of ways.

The Edge Xpert Manager UI supports Read and Write functionality for each device. Readings can also be viewed and queried within the Edge Xpert Manager UI Data Center.

Alternatively, you can read and write data with cURL commands or through REST API applications, such as Postman.

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

Both the GET and PUT requests can be made to the following address:

http://localhost:59882/api/v2/device/name/{deviceName}/{commandName}

Using the example above, a GET request to this device service could be:

curl http://localhost:59882/api/v2/device/name/GPS/Climb

This command retrieves the vertical speed in meters per second from the Climb sensor. The commands available for use with the GPS Device Service can be found at /usr/share/edgexpert/examples/device-services/gps/GPS.yaml.

Note

The profile is already included in the container but is supplied locally for inspection.

For more information on using API commands, see the API.

Any data collected by the Device Service can then be processed like all other Edge Xpert sensor data. The data readings can be exported for data processing in a number of other applications and services. See the Supporting Services and Application Services documentation for more details.