Skip to content

Commit

Permalink
fix: remove Wirepas support
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jan 6, 2025
1 parent c8d1dcf commit d1bdf39
Show file tree
Hide file tree
Showing 38 changed files with 6 additions and 11,379 deletions.
13 changes: 4 additions & 9 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
export AWS_REGION=... # AWS region to use, e.g. eu-west-1
export AWS_DEFAULT_REGION=$AWS_REGION
export AWS_ACCESS_KEY_ID= ... # Your AWS Access Key ID
export AWS_SECRET_ACCESS_KEY=... # Your AWS Secret Acces Key
export AWS_REGION=... # AWS region to use, e.g. eu-west-2
export AWS_PROFILE=...

# Gateway settings
export GATEWAY_MQTT_ENDPOINT=... # e.g. mqtts://<user>:<password>@wirepas.com:8883
export GATEWAY_REGION=... # AWS region to use, e.g. eu-west-1
export GATEWAY_AWS_ACCESS_KEY_ID=... # Value of thingy-rocks-backend.wirepasGatewayUserAccessKeyId
export GATEWAY_AWS_SECRET_ACCESS_KEY=... # Value of thingy-rocks-backend.wirepasGatewayUserSecretAccessKey
# Silence Warnings
export JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION=1
27 changes: 0 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,12 @@ Install the dependencies:
npm ci
```

### Configure

Set the Wirepas 5G Mesh Gateway endpoint:

```bash
aws ssm put-parameter --name thingy-rocks-backend-Wirepas5GMeshGatewayEndpoint --type String --value $GATEWAY_MQTT_ENDPOINT
```

### Deploy

```bash
npx cdk deploy
```

### Running the Wirepas 5G Mesh Gateway

Create a thing type `wirepas-5g-mesh-gateway`.

Configure the gateway settings using the `.envrc` (see
[the example](./envrc.example)).

Run:

```bash
npx tsx wirepas-5g-mesh-gateway/gateway.ts
```

Run as a service using systemd:

```bash
systemd-run -E GATEWAY_MQTT_ENDPOINT=${GATEWAY_MQTT_ENDPOINT} -E GATEWAY_AWS_ACCESS_KEY_ID=${GATEWAY_AWS_ACCESS_KEY_ID} -E GATEWAY_REGION=${GATEWAY_REGION} -E GATEWAY_AWS_SECRET_ACCESS_KEY=${GATEWAY_AWS_SECRET_ACCESS_KEY} --working-directory ${PWD} npx tsx wirepas-5g-mesh-gateway/gateway.ts
```

### Memfault integration

Configure these SSM parameters:
Expand Down
1 change: 0 additions & 1 deletion cdk/BackendLambdas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type BackendLambdas = {
publishSummaries: PackedLambda
onNewNetworkSurvey: PackedLambda
onNetworkSurveyLocated: PackedLambda
parseSinkMessages: PackedLambda
updatesToLwM2M: PackedLambda
memfaultPublishReboots: PackedLambda
memfaultPollForReboots: PackedLambda
Expand Down
1 change: 0 additions & 1 deletion cdk/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ new BackendApp({
publishSummaries: await pack('publishSummaries'),
onNewNetworkSurvey: await pack('onNewNetworkSurvey'),
onNetworkSurveyLocated: await pack('onNetworkSurveyLocated'),
parseSinkMessages: await pack('parseSinkMessages'),
updatesToLwM2M: await pack('updatesToLwM2M'),
memfaultPublishReboots: await pack('memfaultPublishReboots'),
memfaultPollForReboots: await pack('memfaultPollForReboots'),
Expand Down
108 changes: 0 additions & 108 deletions cdk/resources/NRPlusGateway.ts

This file was deleted.

13 changes: 0 additions & 13 deletions cdk/resources/WebsocketAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
aws_iam as IAM,
aws_iot as IoT,
aws_lambda as Lambda,
aws_ssm as SSM,
Duration,
RemovalPolicy,
Stack,
Expand Down Expand Up @@ -130,22 +129,10 @@ export class WebsocketAPI extends Construct {
VERSION: this.node.tryGetContext('version'),
CONNECTIONS_TABLE_NAME: this.connectionsTable.tableName,
WEBSOCKET_MANAGEMENT_API_URL: this.websocketManagementAPIURL,
GATEWAY_MQTT_ENDPOINT: SSM.StringParameter.valueForStringParameter(
this,
`${Stack.of(parent).stackName}-Wirepas5GMeshGatewayEndpoint`,
),
},
layers: [baseLayer],
...new LambdaLogGroup(this, 'onMessageLogs'),
initialPolicy: [
new IAM.PolicyStatement({
actions: ['iot:Publish'],
resources: [
`arn:aws:iot:${Stack.of(parent).region}:${
Stack.of(parent).account
}:topic/*/nrplus-ctrl`,
],
}),
new IAM.PolicyStatement({
actions: ['execute-api:ManageConnections'],
resources: [this.websocketAPIArn],
Expand Down
27 changes: 0 additions & 27 deletions cdk/resources/Wirepas5GMeshGateway.ts

This file was deleted.

25 changes: 1 addition & 24 deletions cdk/stacks/BackendStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { ResolveCellLocation } from '../resources/ResolveCellLocation.js'
import { ResolveNetworkSurveyGeoLocation } from '../resources/ResolveNetworkSurveyGeoLocation.js'
import { UserAuthentication } from '../resources/UserAuthentication.js'
import { WebsocketAPI } from '../resources/WebsocketAPI.js'
import { Wirepas5GMeshGateway } from '../resources/Wirepas5GMeshGateway.js'
import { STACK_NAME } from './stackName.js'
import { NRPlusGateway } from '../resources/NRPlusGateway.js'
import { LwM2M } from '../resources/LwM2M.js'
import { Memfault } from '../resources/Memfault.js'

Expand Down Expand Up @@ -96,18 +94,12 @@ export class BackendStack extends Stack {
),
})

new NRPlusGateway(this, {
lambdaSources,
})

new LwM2M(this, {
lambdaSources,
baseLayer,
})

const wirepasGateway = new Wirepas5GMeshGateway(this)

const memfault = new Memfault(this, {
new Memfault(this, {
assetTrackerStackName,
baseLayer,
lambdaSources,
Expand Down Expand Up @@ -140,21 +132,6 @@ export class BackendStack extends Stack {
value: userAuthentication.identityPool.ref,
exportName: `${this.stackName}:identityPoolId`,
})

new CfnOutput(this, 'wirepasGatewayUserAccessKeyId', {
value: wirepasGateway.accessKey.ref,
exportName: `${this.stackName}:wirepasGatewayUserAccessKeyId`,
})

new CfnOutput(this, 'wirepasGatewayUserSecretAccessKey', {
value: wirepasGateway.accessKey.attrSecretAccessKey,
exportName: `${this.stackName}:wirepasGatewayUserSecretAccessKey`,
})

new CfnOutput(this, 'memfaultBucketURL', {
value: `https://${memfault.bucket.bucketDomainName}/`,
exportName: `${this.stackName}:memfaultBucketURL`,
})
}
}

Expand Down
59 changes: 1 addition & 58 deletions lambda/onMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import type {
APIGatewayProxyWebsocketEventV2,
} from 'aws-lambda'
import { validateWithTypeBox } from './validateWithTypeBox.js'
import {
IoTDataPlaneClient,
PublishCommand,
} from '@aws-sdk/client-iot-data-plane'
import { DescribeThingCommand, IoTClient } from '@aws-sdk/client-iot'
import {
UpdateThingShadowCommand,
type UpdateThingShadowCommandInput,
} from '@aws-sdk/client-iot-data-plane'
import { ApiGatewayManagementApi } from '@aws-sdk/client-apigatewaymanagementapi'
import { sendEvent } from './notifyClients.js'
import { fetchLwM2MShadows } from '../lwm2m/fetchLwM2MShadows.js'
Expand All @@ -31,37 +23,10 @@ const deviceControl = Type.Object({

const message = Type.Object({
message: Type.Literal('sendmessage'),
data: Type.Union([
Type.Intersect([
deviceControl,
Type.Object({
nrplusCtrl: Type.String({ minLength: 1 }),
}),
]),
Type.Intersect([
deviceControl,
Type.Object({
wirepasCtrl: Type.Object({
nodes: Type.Record(
Type.String({ minLength: 1 }),
Type.Object({
payload: Type.Object({
led: Type.Object({
r: Type.Boolean(),
g: Type.Boolean(),
b: Type.Boolean(),
}),
}),
}),
),
}),
}),
]),
]),
data: deviceControl,
})
const validateMessage = validateWithTypeBox(message)

const iotData = new IoTDataPlaneClient({})
const iot = new IoTClient({})
const db = new DynamoDBClient({})

Expand Down Expand Up @@ -162,28 +127,6 @@ export const handler = async (
body: `Code ${code} not valid for device ${deviceId}!`,
}
}
if ('nrplusCtrl' in msg) {
await iotData.send(
new PublishCommand({
topic: `${deviceId}/nrplus-ctrl`,
payload: Buffer.from(msg.nrplusCtrl, 'utf-8'),
qos: 1,
}),
)
console.log(`>`, `${deviceId}/nrplus-ctrl`, msg.nrplusCtrl)
}
if ('wirepasCtrl' in msg) {
const update: UpdateThingShadowCommandInput = {
thingName: deviceId,
payload: JSON.stringify({
state: {
desired: msg.wirepasCtrl,
},
}),
}
await iotData.send(new UpdateThingShadowCommand(update))
console.log(JSON.stringify({ update }))
}
return {
statusCode: 202,
}
Expand Down
Loading

0 comments on commit d1bdf39

Please sign in to comment.