Process sensor data

Create an event rule for a sensor

Cloud API supports different types of sensors such as battery, temperature, acceleration, and tamper sensors. In this example we create a "Low battery" rule to notify the owner when the battery level of a tracker goes below 20%.

curl -X POST \
  'https://tracking.api.here.com/sensors/v3' \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json' \
  -d '{
  "type": "battery",
  "range":  {
    "begin": 0,
    "end": 20
  },
  "name": "Low Battery"
}'

This will create a low battery rule and return the unique rule ID. At this point, the rule isn't associated with any device but it will be visible on the web dashboard.

You can also get a list of rules you previously created.

curl -X GET \
  'https://tracking.api.here.com/sensors/v3' \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

Associate rule and device

Now that we have a device sending its sensor data and a rule for the battery level, we can associate one to the other. This will cause a notification to be sent whenever the battery voltage of the device goes in the range or outside of it.

curl -X PUT \
  https://tracking.api.here.com/associations/v3/{trackingId}/sensors/{ruleId} \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

Send telemetry including battery information outside the range then inside the range. Note that timestamps are in milliseconds since Unix epoch timestamp.

curl -X POST \
  https://tracking.api.here.com/v2/ \
  -H 'authorization: Bearer {deviceToken}' \
  -H 'content-type: application/json' \
  -d '[{
      "timestamp": 1569300623010,
      "position": {
        "alt": 107,
        "accuracy": 13,
        "lat": 52.520806,
        "lng": 13.410514,
        "altaccuracy": 14
      },
      "system": {
        "reportedSensorData": {
          "batteryLevel": 21
        }
      }
}]'
curl -X POST \
  https://tracking.api.here.com/v2/ \
  -H 'authorization: Bearer {deviceToken}' \
  -H 'content-type: application/json' \
  -d '[{
      "timestamp": 1569300814020,
      "position": {
        "alt": 107,
        "accuracy": 10,
        "lat": 52.521880,
        "lng": 13.412724,
        "altaccuracy": 15
      },
      "system": {
        "reportedSensorData": {
          "batteryLevel": 19
        }
      }
}]'

See an event was recorded

All sensor events are recorded in the events history. You will see two different events: an event "above range" triggered by the first telemetry, and an event "in range" by the second one. Events are generated whenever the reported sensor state will cross the threshold of a rule.

curl -X GET \
  https://tracking.api.here.com/events/v3/{trackingId} \
  -H 'authorization: Bearer {userToken}' \
  -H 'content-type: application/json'

results matching ""

    No results matching ""