1.1.103 • Published 2 months ago

@digicatapult/wasp-payload-processor v1.1.103

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

wasp-payload-processor

Service builder for WASP payload processors. The library provides a simple way of implementing a payload processor for a new thing type in WASP. The intentions of this module is to simplify the development of support for new IoT devices in WASP.

Developing a new WASP payload processor

If developing a new payload parsing service for WASP this could be as simple as:

// server.js

import { buildService } from '@digicatapult/wasp-payload-processor'

buildService({
    sensorType: 'new-sensor-type',
    payloadProcessor: ({ logger }) => ({ thingId, timestamp, payload }) => {
    const asBuffer = Buffer.from(payload, 'base64')
    return {
      readings: [{
        dataset: {
          thingId,
          type: 'temperature',
          label: 'dataset-label-if-any',
          unit: '°C',
        },
        timestamp,
        value: asBuffer[0],
      }]),
      events: [{
        thingId,
        timestamp,
        type: 'SHOCK',
        details: { arbitrary: "details" }
      }]
  },
})

The format of the outgoing message format is described below

Message format

The payloadProcessor function must return an object of type PayloadProcessorResult which contains descriptions of readings and events to be published. The type signatures are as follows:

type Event = {
  thingId: uuid
  type: string
  timestamp: string
  details: Object
}

type Dataset = {
  thingId: uuid
  type: string
  label: string
  unit: string
}

type DatasetPoint = {
  dataset: Dataset
  timestamp: string
  value: number
}

type PayloadProcessorResult = {
  readings: DatasetPoint[]
  events: Event[]
}

Each of the DatasetPoint values represents a single value at a point in time for the dataset defined by the thingId, type, label and unit. Here the thingId is the uuid of the IoT device that generated the reading, type is the type of the dataset e.g. temperature and label is an arbitrary label to distinguish datasets when a thing may generate multiple datasets of the same type e.g. MCU temperature vs external temperature.

Each of the Event values represents an event reported by a thingId, which is then characterised by an event type and a timestamp at which the event occurred. An arbitrary details property allows the event to convey additional information about the event.

Testing

First install required dependencies using npm:

npm install

wasp-payload-processor depends on Kafka which can be brought up locally using docker:

docker-compose up -d

And finally you can run tests with:

npm test

Environment Variables

wasp-payload-processor is configured primarily using environment variables as follows:

variablerequireddefaultdescription
PORTN3000Port on which the service will listen
LOG_LEVELNinfoLogging level. Valid values are trace, debug, info, warn, error, fatal
KAFKA_LOG_LEVELNnothingLogging level for Kafka. Valid values are debug, info, warn, error, nothing
KAFKA_BROKERSNlocalhost:9092List of addresses for the Kafka brokers
KAFKA_READINGS_TOPICNreadingsOutgoing Kafka topic for readings
KAFKA_EVENTS_TOPICNeventsOutgoing Kafka topic for events
KAFKA_PAYLOAD_ROUTING_PREFIXNpayloadsPrefix for incoming Kafka topics for payloads
1.1.103

2 months ago

1.1.102

2 months ago

1.1.101

2 months ago

1.1.100

2 months ago

1.1.99

3 months ago

1.1.96

3 months ago

1.1.98

3 months ago

1.1.97

3 months ago

1.1.95

3 months ago

1.1.94

3 months ago

1.1.93

3 months ago

1.1.92

3 months ago

1.1.91

3 months ago

1.1.90

3 months ago

1.1.89

3 months ago

1.1.88

4 months ago

1.1.87

4 months ago

1.1.86

4 months ago

1.1.85

4 months ago

1.1.84

4 months ago

1.1.83

4 months ago

1.1.81

4 months ago

1.1.82

4 months ago

1.1.80

4 months ago

1.1.78

4 months ago

1.1.79

4 months ago

1.1.77

5 months ago

1.1.76

5 months ago

1.1.75

5 months ago

1.1.74

5 months ago

1.1.73

5 months ago

1.1.72

5 months ago

1.1.29

10 months ago

1.1.28

10 months ago

1.1.70

6 months ago

1.1.30

10 months ago

1.1.71

6 months ago

1.1.34

9 months ago

1.1.33

9 months ago

1.1.32

10 months ago

1.1.31

10 months ago

1.1.38

9 months ago

1.1.37

9 months ago

1.1.36

9 months ago

1.1.35

9 months ago

1.1.39

9 months ago

1.1.41

9 months ago

1.1.40

9 months ago

1.1.45

8 months ago

1.1.44

8 months ago

1.1.43

9 months ago

1.1.42

9 months ago

1.1.49

8 months ago

1.1.48

8 months ago

1.1.47

8 months ago

1.1.46

8 months ago

1.1.52

7 months ago

1.1.51

7 months ago

1.1.50

8 months ago

1.1.56

7 months ago

1.1.55

7 months ago

1.1.54

7 months ago

1.1.53

7 months ago

1.1.59

7 months ago

1.1.58

7 months ago

1.1.57

7 months ago

1.1.63

7 months ago

1.1.62

7 months ago

1.1.61

7 months ago

1.1.60

7 months ago

1.1.67

6 months ago

1.1.66

6 months ago

1.1.65

6 months ago

1.1.64

6 months ago

1.1.69

6 months ago

1.1.68

6 months ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.16

12 months ago

1.1.15

12 months ago

1.1.14

12 months ago

1.1.13

12 months ago

1.1.19

11 months ago

1.1.18

11 months ago

1.1.17

12 months ago

1.1.23

11 months ago

1.1.22

11 months ago

1.1.21

11 months ago

1.1.20

11 months ago

1.1.27

11 months ago

1.1.26

11 months ago

1.1.25

11 months ago

1.1.24

11 months ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.1

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago