Populate the meta in location history API through nRFCloud

Hey everyone!

We're making use of nRFCloud on our nRF9160-based system.
I'm trying to populate the meta in the location history API.

The response is always empty, like this:

{
    "deviceId": "nrf-352656101081837",
    "serviceType": "GPS",
    "insertedAt": "2022-12-06T13:35:20.785Z",
    "uncertainty": "24.000000",
    "lat": "68.000000",
    "lon": "17.000000",
    "meta": {}
}
I'm sending the data like this, as shown by the list messages API
{
    "topic": "prod/XX/XX",
    "deviceId": "nrf-XX",
    "receivedAt": "2022-12-06T09:27:13.804Z",
    "message": {
        "messageType": "DATA",
        "data": {
            "acc": 24.000000,
            "lng": 17.000000,
            "lat": 68.000000,
            "meta": {
                "bat": 4167
            }
        }
        "appId": "GNSS"
    },
    "tenantId": "XX"
}
As you see, I'm trying to pack the battery level in the same message, and I want to retrieve this data along with the location when using the location history API. 
The actual message I encode and send is as such:
{"appId": "GNSS","messageType": "DATA", "data": {"lng": 17.000000.,"lat": 68.000000,"acc": 24.000000, "meta":{"bat":4363}}}
My question is: How can I pack this battery data in the location history meta?
Thank you all for all and any suggestions!
Kind regards,
Torje
Parents
  • Hi, 

    The issue is with the formatting of the message data. Put the "bat" property inline like this:

    {
        "topic": "prod/XX/XX",
        "deviceId": "nrf-XX",
        "receivedAt": "2022-12-06T09:27:13.804Z",
        "message": {
            "messageType": "DATA",
            "data": {
                "acc": 24.000000,
                "lng": 17.000000,
                "lat": 68.000000,
                "bat": 4167
            }
            "appId": "GNSS"
        },
        "tenantId": "XX"
    }

    Regards,
    Amanda H.

  • Hi Torje,

    I have some good news and some bad news. Good news is that you can store extra data in the meta field by including it in the main payload like so:

    "message": {
       "messageType": "DATA",
       "data": {
          "acc": 24.000000,
          "lng": 17.000000,
          "lat": 68.000000,
          "bat": 4167 // this will be stored in the meta field
       }
       "appId": "GNSS"
    }

    Please try this format again. It works for me. 

    Now for the bad news: there is a bug in our API that prevents you from getting the meta for a specific device. The meta will always be set to {} when querying for a device. However, you can get around this by not specifying a device id and setting 'latest=true' ( ie https://api.nrfcloud.com/v1/location/history?latest=true ). This will bypass the bug and return the true meta field. You will get all devices returned and have to filter for the device you're interested in. 

    I am filing a ticket for the bug now. Thank you for bringing this to our atttention.

    Cole

  • Hey again Cole,

    My results were from polling one device only. I can confirm that it works as you've specified.
    I would also like to mention that the meta-field appears empty when querying with no params. It works with 'latest=true', but seemingly not for anything else (of the ones I've tested at least)

    Thank you for looking into this and clarifying how I can use it for now.

    Kind regards,

    Torje 

Reply
  • Hey again Cole,

    My results were from polling one device only. I can confirm that it works as you've specified.
    I would also like to mention that the meta-field appears empty when querying with no params. It works with 'latest=true', but seemingly not for anything else (of the ones I've tested at least)

    Thank you for looking into this and clarifying how I can use it for now.

    Kind regards,

    Torje 

Children
No Data
Related