Accessing Data using Sofar API

Hi Bristlemouth team,

I’m trying to view the data I am sending over the Sofar API (using tutorial 5’s instructions). I am getting the following error when attempting to view the “{“message”:“Authorization failed”}”

I’m attempting to access the following endpoint URL: https://api.sofarocean.com/api/raw-messages?token=xxx&spotterId=SPOT-31420C

I believe I am using the correct account and the spotter should be registered to it. I also have checked the GO LED and it is red, so I have been using the raw-messages endpoint.

I also attempted to re generate a token but ran into the same issue.

Any advice on how to proceed?

Best,
Aadu

Congratulations on getting to guide 5. I think there’s a forum badge and a physical patch you get after you get through guide 6!

Have you gotten the correct API token from your dashboard?

Also if you want to test out the new API tool from Aqualink?
https://bristlemouth.aqualink.org/

Z

I’ve also just check and can confirm that SPOT-31420C is properly registered.

Hi Zack,

I believe so. I’ve tried generating several new tokens and haven’t seen anything on the other end.

The Aqualink API tool allows me to use the token but is showing no updates from the Spotter.

I may be making a few incorrect assumptions, so here are a few questions:

  1. When should I expect to see the Spotter’s location/status update on https://spotter.sofarocean.com/current/SPOT-31420C ?

  2. Tutorial 3 instructs me to use the command:

“spotter txdata i Hello, Spotter!”

On the Spotter serial port, I see the following:

Current bit offset: 230
Rounded bit offset: 232
New bit offset: 352
1804717t [MS] [INFO] Added message(id: 0 len: 44) to queue MS_Q_LEGACY: (1)!
Message: DE 00 00 00 00 DA 00 B0 12 00 6E D8 00 06 D4 00 00 91 B5 5F A5 B7 D1 84 CE 4B 28 D7 8C 48 65 6C 6C 6F 2C 20 53 70 6F 74 74 65 72 21
1804719t [BM_TX] [INFO] Submitted spotter/transmit-data message to sat/cell queue, Len: 16
1804719t [BM_TX] [DEBUG] Message:
48 65 6c 6c 6f 2c 20 53
70 6f 74 74 65 72 21
1804721t [ERR] [INFO] Cellular SignalErrorState changed from N/A to CONNECTING
1804721t [MS] [DEBUG] Sending legacy messages to Notecard.
1804758t [MS] [DEBUG] Notecard is 6.000000 pct full.
1804759t [MS] [INFO] Queuing message 0 20004558
1805109t [MS] [DEBUG] Attempting to Sync.
1805144t [MS] [DEBUG] Waiting for TX
1830435t [MS] [DEBUG] Notecard is 6.000000 pct full.
1830436t [MS] [INFO] All messages sent successfully!
1830436t [MS] [DEBUG] Checking for Rx Messages
1830476t [ERR] [INFO] Cellular SignalErrorState changed from CONNECTING to OK

Can you confirm that this is what I should expect when sending data from a sensor?

Good to know that I’m almost done with the tutorials. My goal is to integrate an off the shelf temp sensor and send data to the cloud. I think I should be able to figure out the firmware/device side of things, but am having some difficulty with viewing the data online! Sounds like I’m close…

Best,
Aadu

1 Like

Hi @fiestapinguino, good to hear from you.

I see 5 messages at the raw-messages endpoint for SPOT-31420C, using my own token. Those message are all stamped 2024-01-09, UTC.

Regarding the API tokens for the account which owns this Spotter/DevKit: I see a token was invalidated also on 2024-01-09. That one ended in 524. There is a new token available, which can be seen in the Spotter dashboard. When I use that token, I also see 5 messages at the raw-messages endpoint.

Here is a basic Unix shell script which can serve as an example. Note, it requires that the jq tool be in the PATH somewhere. This script is not guaranteed to work on Windows, as Windows default curl uses different syntax from Unix curl.

This script as-is expects there to be a file named sofar_api.env in the user’s HOME directory (~). This file is structured as follows:

WF_API_TOKEN=your_token_here

You can bypass this requirement by just replacing the token="$(...)" line in the script below with your actual token, a’la token=my_token_here.

#!/bin/bash

# pull & display raw messages from the raw messages API
# timjoh 2023-09-07

usage () {
   echo "$(basename $0) [spotid]"
}

token="$(awk -F= '/WF_API_TOKEN/ { print $2 }' $HOME/sofar_api.env)"

case $# in 
   1) spotid=$1;;
   *) usage;  exit 1;
esac

echo "++ pulling messages for ${spotid}"

startDate="2023-07-01"

with_token() {
    # note, startDate is unused here
    url="https://api.sofarocean.com/api/raw-messages?token=${token}&spotterId=${spotid}"

    curl -H "token: ${token}" "${url}" | jq .
}

with_token

Note: that script places the token both in the header of the HTTPS request, as well as in the query parameters in the URL. I believe you can choose to use either/or.

Cheers,
Tim

Hi Tim,

Thanks for this followup. I am confirming that I am using the latest token assigned to my account (ending in 5c19). Both the URL and script you provided (using said token) are returning 0 messages.

bash get_data.sh SPOT-31420C
++ pulling messages for SPOT-31420C
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   250  100   250    0     0    534      0 --:--:-- --:--:-- --:--:--   536
{
  "status": "success",
  "data": {
    "spotterId": "SPOT-31420C",
    "messages": []
  },
  "metadata": {
    "page": {
      "nextPage": "https://api.sofarocean.com/api/raw-messages?cursor=eyJzcG90dGVySWQiOiJTUE9ULTMxNDIwQyIsImN1cnNvcklkIjowfQ%3D%3D",
      "hasMoreData": false,
      "pageSize": 20
    }
  }
}

Is this an issue with my account? I had an account while I worked at sofar that used the username: fiestapinguino (tied to my sofar email). I had to create a new account waltermunksalbatross (tied to aadu@uw.edu). Let me know if I goofed something up and activated the Spotter from the wrong account.

Hi Aadu — I think this is actually good progress. You have access to the device, but there are no messages available after the default startDate (I’m researching exactly how this works).

Try changing the script so there is a startDate, like:

with_token() {
    url="https://api.sofarocean.com/api/raw-messages?token=${token}&spotterId=${spotid}&startDate=2023-01-05"

    curl -H "token: ${token}" "${url}" | jq .
}

When I do this, I see data.

Thanks,
Tim

Hey Tim, that seemed to do it! Thank you for helping me out there.

Are there any tutorials on using the Sofar API and being able to make sense of the data I’m getting back?

{
        "momsn": 0,
        "transmitTime": "2023-09-22T22:06:03.000Z",
        "approxLon": "-122.33",
        "approxLat": "37.83",
        "cep": 3,
        "message": "dc650e0fa59deeba0205b12dc63de96ac003b6675d4019a5c912c320803b0017a1403c000bb99460f032096271000008372d0d2c830655210103a074898864c79664b001e1f424507801f401dbe80000000000000002ff73e9377854ca1c1b060190c70c454000c181d81f401d80e81e03840012c2454040003848221394e108489ce109d5909c63184e10842528ca8b3e",
        "createdAt": "2023-09-22T22:06:07.775Z",
        "messageHeader": 220,
        "counter": null,
        "partNo": null,
        "processed": true,
        "commSource": "iridium",
        "processingSource": "embedded"
      },

...

      {
        "momsn": null,
        "transmitTime": "2023-09-23T01:05:07.000Z",
        "approxLon": "-122.39",
        "approxLat": "37.79",
        "cep": null,
        "message": "f35b313536303433392c313536303434302c313536303434312c313536303434322c313536303434332c313536303730395d",
        "createdAt": "2023-09-23T01:53:33.712Z",
        "messageHeader": 243,
        "counter": null,
        "partNo": null,
        "processed": true,
        "commSource": "cellular",
        "processingSource": "hdr"
      },

Also, I still don’t see any data on the Aqualink UI: Bristlemouth UI

I’ve played around with the start date and API token but nothing seems to be showing up.

Thanks!
Aadu

Hi Aadu,

The messages I see pasted above are a Spotter configuration message (header DC) (which is not shared over normal customer-accessible API endpoints) and a cellular HDR message (F3). I would not expect either of those to show up in the Bristlemouth API.

For normal Spotter API data endpoints, please see docs.sofarocean.com. Please note, the documentation often requires one to click the “>” symbols to expand various sections.

I will reiterate that the purpose of the raw-messages endpoint is to make available those Bristlemouth data packets which are transmitted during indoor testing, when GPS is unlikely to be available. I assume that the Bristlemouth API Explorer site uses official Sofar API endpoints, so messages will only be available there if those messages were transmitted while Spotter had a solid GPS signal.

You can acquire valid GPS reception by transmitting the messages while the Spotter is outdoors, with a clear view of sky/horizon, as close to 360° as possible.

Thanks,
Tim

I have confirmed that the /raw-messages endpoint will only show the last ~day or so of data if no startDate is supplied. It defaults to a startDate of (today - 1 day).

Aqualink built the Bristlemouth Explorer so that you can easily access the data:
https://bristlemouth.aqualink.org/

Hi @peterive — can you tell us whether the Bristlemouth Explorer supports the /raw-messages API endpoint, to retrieve messages that are missing valid GPS locations? Thanks