Skip to content

Commit b81c755

Browse files
committed
feat: remove ground fix resolution
The nRF Cloud backend actually publishes the location as a message via MQTT: { "appId": "GROUND_FIX", "messageType": "DATA", "data": { "lat": 59.3381238, "lon": 18.00908089, "uncertainty": 883, "fulfilledWith": "MCELL" } } so this can be used directly. See https://docs.nrfcloud.com/APIs/MQTT/Topics/\#c2d-topics-ls
1 parent 239ac32 commit b81c755

File tree

14 files changed

+14
-477
lines changed

14 files changed

+14
-477
lines changed

.github/workflows/test-and-release.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ jobs:
7070
npx cdk --app "npx tsx --no-warnings cdk/test-resources.ts" deploy --require-approval never
7171
MOCK_HTTP_API_ENDPOINT=`aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }}-test | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "apiURL") | .OutputValue' | sed -E 's/\/$//g'`
7272
./cli.sh configure thirdParty nrfcloud apiEndpoint ${MOCK_HTTP_API_ENDPOINT}
73-
openssl ecparam -name prime256v1 -genkey | ./cli.sh configure thirdParty nrfcloud serviceKey
7473
./cli.sh configure thirdParty nrfcloud apiKey apiKey
75-
./cli.sh configure thirdParty nrfcloud teamId `uuidgen`
7674
7775
- name: Deploy solution stack
7876
run: npx cdk deploy --require-approval never
@@ -103,9 +101,7 @@ jobs:
103101
npx cdk --app 'npx tsx --no-warnings cdk/test-resources.ts' destroy -f
104102
./cli.sh fake-nrfcloud-account-device --remove
105103
./cli.sh configure thirdParty nrfcloud apiEndpoint -X
106-
./cli.sh configure thirdParty nrfcloud serviceKey -X
107104
./cli.sh configure thirdParty nrfcloud apiKey -X
108-
./cli.sh configure thirdParty nrfcloud teamId -X
109105
110106
release:
111107
needs:

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,13 @@ npm ci
2828

2929
To setup MQTT bridge, you have to run the below command to generate a
3030
certificate used by MQTT broker to connect nRF Cloud under your account. So, you
31-
need to prepare nRF Cloud API key and service key. The service key is used to
32-
resolve ground fix location.
31+
need to prepare nRF Cloud API key.
3332

3433
```bash
3534
./cli.sh configure thirdParty nrfcloud apiKey <API key>
3635
./cli.sh initialize-nrfcloud-account
3736
```
3837

39-
Finally the Ground Fix Service Key and the team ID that it belongs has to be
40-
configured for resolving device locations:
41-
42-
```bash
43-
cat serviceKeyFile.pem | ./cli.sh configure thirdParty nrfcloud serviceKey
44-
./cli.sh configure thirdParty nrfcloud teamId <team ID>
45-
```
46-
4738
### Deploy
4839

4940
```bash

cdk/backend.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const packagesInLayer: string[] = [
3434
'ajv',
3535
'@hello.nrfcloud.com/proto',
3636
'p-limit',
37-
'jsonwebtoken',
3837
'@aws-lambda-powertools/metrics',
3938
'lodash-es',
4039
'@middy/core',

cdk/resources/ConvertDeviceMessages.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,8 @@ export class ConvertDeviceMessages extends Construct {
4848
DEVICES_TABLE_NAME: deviceStorage.devicesTable.tableName,
4949
DEVICES_INDEX_NAME: deviceStorage.devicesTableFingerprintIndexName,
5050
NODE_NO_WARNINGS: '1',
51-
STACK_NAME: Stack.of(this).stackName,
5251
},
5352
layers,
54-
initialPolicy: [
55-
new IAM.PolicyStatement({
56-
actions: ['ssm:GetParameter'],
57-
resources: [
58-
`arn:aws:ssm:${Stack.of(this).region}:${
59-
Stack.of(this).account
60-
}:parameter/${Stack.of(this).stackName}/thirdParty/nrfcloud/*`,
61-
],
62-
}),
63-
],
6453
})
6554
new LambdaLogGroup(this, 'onDeviceMessageLogs', onDeviceMessage)
6655
websocketAPI.eventBus.grantPutEventsTo(onDeviceMessage)

feature-runner/steps/mocknRFCloud.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -64,51 +64,5 @@ ${data}
6464
)
6565
}
6666

67-
const mockGroundFix = async ({
68-
step,
69-
log: {
70-
step: { progress },
71-
},
72-
context: { responsesTableName },
73-
}: StepRunnerArgs<World>): Promise<StepRunResult> => {
74-
const match = /^there is a ground fix API response as this JSON$/.exec(
75-
step.title,
76-
)
77-
if (match === null) return noMatch
78-
79-
const data = codeBlockOrThrow(step).code
80-
81-
const methodPathQuery = `POST v1/location/ground-fix`
82-
progress(`Mock http url: ${methodPathQuery}`)
83-
await db.send(
84-
new PutItemCommand({
85-
TableName: responsesTableName,
86-
Item: {
87-
methodPathQuery: {
88-
S: methodPathQuery,
89-
},
90-
timestamp: {
91-
S: new Date().toISOString(),
92-
},
93-
statusCode: {
94-
N: `200`,
95-
},
96-
body: {
97-
S: `Content-Type: application/json
98-
99-
${data}
100-
`,
101-
},
102-
ttl: {
103-
N: `${Math.round(Date.now() / 1000) + 5 * 60}`,
104-
},
105-
keep: {
106-
BOOL: false,
107-
},
108-
},
109-
}),
110-
)
111-
}
112-
113-
return [mockShadowData, mockGroundFix]
67+
return [mockShadowData]
11468
}

features/GroundFix.feature.md

Lines changed: 0 additions & 94 deletions
This file was deleted.

lambda/onDeviceMessage.ts

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
22
import { EventBridge } from '@aws-sdk/client-eventbridge'
33
import { proto, type HelloMessage } from '@hello.nrfcloud.com/proto/hello'
4-
import type { GROUND_FIX } from '@hello.nrfcloud.com/proto/nrfCloud/types/types.js'
54
import { fromEnv } from '@nordicsemiconductor/from-env'
65
import type { Static } from '@sinclair/typebox'
76
import { getModelForDevice } from '../devices/getModelForDevice.js'
8-
import { locationServiceAPIClient } from '../nrfcloud/locationServiceAPIClient.js'
9-
import { defaultApiEndpoint } from '../nrfcloud/settings.js'
107
import type { WebsocketPayload } from './publishToWebsocketClients.js'
11-
import { getNRFCloudSSMParameters } from './util/getSSMParameter.js'
128
import { logger } from './util/logger.js'
139

14-
const { EventBusName, DevicesTableName, stackName } = fromEnv({
15-
stackName: 'STACK_NAME',
10+
const { EventBusName, DevicesTableName } = fromEnv({
1611
EventBusName: 'EVENTBUS_NAME',
1712
DevicesTableName: 'DEVICES_TABLE_NAME',
1813
})(process.env)
@@ -25,40 +20,6 @@ const eventBus = new EventBridge({})
2520

2621
const modelFetcher = getModelForDevice({ db, DevicesTableName })
2722

28-
const apiClientPromise = (async () => {
29-
const [apiEndpoint, serviceKey, teamId] = await getNRFCloudSSMParameters(
30-
stackName,
31-
['apiEndpoint', 'serviceKey', 'teamId'],
32-
)
33-
if (serviceKey === undefined)
34-
throw new Error(`nRF Cloud service key for ${stackName} is not configured.`)
35-
if (teamId === undefined)
36-
throw new Error(`nRF Cloud team ID for ${stackName} is not configured.`)
37-
return locationServiceAPIClient({
38-
endpoint:
39-
apiEndpoint !== undefined ? new URL(apiEndpoint) : defaultApiEndpoint,
40-
serviceKey,
41-
teamId,
42-
})
43-
})()
44-
45-
const preprocessMessage =
46-
(apiClient: ReturnType<typeof locationServiceAPIClient>) =>
47-
async (message: unknown, ts: number): Promise<unknown> => {
48-
// If it is nRF Cloud site survey message, we resolve location using ground fix API
49-
if (
50-
typeof message === 'object' &&
51-
message !== null &&
52-
'appId' in message &&
53-
message.appId === 'GROUND_FIX'
54-
) {
55-
return await apiClient.groundFix((message as GROUND_FIX).data, ts)
56-
}
57-
58-
// Otherwise, pass though the message
59-
return message
60-
}
61-
6223
const parseMessage = async (
6324
model: string,
6425
message: unknown,
@@ -82,13 +43,11 @@ export const handler = async (event: {
8243
timestamp: number
8344
}): Promise<void> => {
8445
log.debug('event', { event })
85-
const client = await apiClientPromise
86-
const { deviceId, message, timestamp } = event
46+
const { deviceId, message } = event
8747
const { model } = await modelFetcher(deviceId)
8848
log.debug('model', { model })
8949

90-
const processedMessage = await preprocessMessage(client)(message, timestamp)
91-
const converted = await parseMessage(model, processedMessage)
50+
const converted = await parseMessage(model, message)
9251

9352
for (const message of converted) {
9453
log.debug('websocket message', { payload: message })

nrfcloud/createToken.spec.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

nrfcloud/createToken.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)