@corvina/device-example 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +96 -0
- package/README.md +56 -0
- package/bin/corvina-device-example.js +3 -0
- package/dist/app.module.js +31 -0
- package/dist/app.module.js.map +1 -0
- package/dist/controllers/app.controller.js +28 -0
- package/dist/controllers/app.controller.js.map +1 -0
- package/dist/controllers/device/config.controller.js +79 -0
- package/dist/controllers/device/config.controller.js.map +1 -0
- package/dist/controllers/device/dice.controller.js +65 -0
- package/dist/controllers/device/dice.controller.js.map +1 -0
- package/dist/controllers/device/dto/datapoint.dto.js +14 -0
- package/dist/controllers/device/dto/datapoint.dto.js.map +1 -0
- package/dist/controllers/device/dto/deviceconfig.dto.js +120 -0
- package/dist/controllers/device/dto/deviceconfig.dto.js.map +1 -0
- package/dist/controllers/device/dto/licensedata.dto.js +16 -0
- package/dist/controllers/device/dto/licensedata.dto.js.map +1 -0
- package/dist/controllers/device/json.controller.js +137 -0
- package/dist/controllers/device/json.controller.js.map +1 -0
- package/dist/controllers/device/sine.controller.js +81 -0
- package/dist/controllers/device/sine.controller.js.map +1 -0
- package/dist/controllers/health.controller.js +41 -0
- package/dist/controllers/health.controller.js.map +1 -0
- package/dist/main.js +36 -0
- package/dist/main.js.map +1 -0
- package/dist/services/device.health.js +37 -0
- package/dist/services/device.health.js.map +1 -0
- package/nest-cli.json +17 -0
- package/package.json +47 -0
- package/src/.env +130 -0
- package/src/app.module.ts +19 -0
- package/src/controllers/app.controller.ts +7 -0
- package/src/controllers/device/config.controller.ts +42 -0
- package/src/controllers/device/dice.controller.ts +38 -0
- package/src/controllers/device/dto/datapoint.dto.ts +7 -0
- package/src/controllers/device/dto/deviceconfig.dto.ts +110 -0
- package/src/controllers/device/dto/licensedata.dto.ts +9 -0
- package/src/controllers/device/json.controller.ts +111 -0
- package/src/controllers/device/sine.controller.ts +56 -0
- package/src/controllers/health.controller.ts +14 -0
- package/src/main.ts +33 -0
- package/src/services/device.health.ts +20 -0
- package/tsconfig.app.json +9 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var Json_1, _a;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.Json = void 0;
|
|
20
|
+
const openapi = require("@nestjs/swagger");
|
|
21
|
+
const common_1 = require("@nestjs/common");
|
|
22
|
+
const corvina_device_sdk_1 = require("@corvina/corvina-device-sdk");
|
|
23
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
24
|
+
const axios_1 = __importDefault(require("axios"));
|
|
25
|
+
let Json = Json_1 = class Json {
|
|
26
|
+
l = new common_1.Logger(Json_1.name);
|
|
27
|
+
deviceService;
|
|
28
|
+
async post(tagName = undefined, timestamp = undefined, qos = undefined, postCallback = undefined, v) {
|
|
29
|
+
const t = timestamp || Date.now();
|
|
30
|
+
const dataPoints = new Array();
|
|
31
|
+
const dp = {
|
|
32
|
+
tagName,
|
|
33
|
+
value: v,
|
|
34
|
+
timestamp: t,
|
|
35
|
+
};
|
|
36
|
+
dataPoints.push(dp);
|
|
37
|
+
await this.deviceService.post(dataPoints, {
|
|
38
|
+
qos: qos || 0,
|
|
39
|
+
cb: postCallback
|
|
40
|
+
? (error, tagName, modelPath) => {
|
|
41
|
+
axios_1.default.post(postCallback, { error: { message: error.message }, tagName, modelPath });
|
|
42
|
+
}
|
|
43
|
+
: undefined,
|
|
44
|
+
});
|
|
45
|
+
return dataPoints;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, common_1.Inject)(),
|
|
50
|
+
__metadata("design:type", typeof (_a = typeof corvina_device_sdk_1.DeviceService !== "undefined" && corvina_device_sdk_1.DeviceService) === "function" ? _a : Object)
|
|
51
|
+
], Json.prototype, "deviceService", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, swagger_1.ApiOperation)({
|
|
54
|
+
summary: "Post a new JSON value",
|
|
55
|
+
callbacks: {
|
|
56
|
+
result: {
|
|
57
|
+
"{$request.query#/callback}": {
|
|
58
|
+
post: {
|
|
59
|
+
requestBody: {
|
|
60
|
+
required: true,
|
|
61
|
+
content: {
|
|
62
|
+
"application/json": {
|
|
63
|
+
schema: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
error: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: {
|
|
69
|
+
message: {
|
|
70
|
+
type: "string",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
tagName: {
|
|
75
|
+
type: "string",
|
|
76
|
+
},
|
|
77
|
+
modelPath: {
|
|
78
|
+
type: "string",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
responses: {
|
|
86
|
+
"200": { description: "The server acknowledged the request" },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
(0, swagger_1.ApiQuery)({
|
|
94
|
+
name: "tagName",
|
|
95
|
+
description: "Prefix of device identifier (name) of data source. The actual tag names advertised to the cloud are automatically generated as this prefix plus each property JSON path. The prefix can be undefined, so that only JSON paths are used",
|
|
96
|
+
schema: { default: undefined, example: "temperature" },
|
|
97
|
+
required: false,
|
|
98
|
+
}),
|
|
99
|
+
(0, swagger_1.ApiQuery)({
|
|
100
|
+
name: "timestamp",
|
|
101
|
+
description: "Specify a timestamp (if omitted the request timestamp is used) ",
|
|
102
|
+
required: false,
|
|
103
|
+
}),
|
|
104
|
+
(0, swagger_1.ApiQuery)({
|
|
105
|
+
name: "callback",
|
|
106
|
+
description: "Specify an optional callback to be invoked when the message has been delivered",
|
|
107
|
+
schema: { type: "string", format: "uri", example: "http://localhost:30001" },
|
|
108
|
+
required: false,
|
|
109
|
+
}),
|
|
110
|
+
(0, swagger_1.ApiQuery)({
|
|
111
|
+
name: "qos",
|
|
112
|
+
description: "Specify an optional qos (by default is zeo)",
|
|
113
|
+
schema: { type: "number", minimum: 0, maximum: 2, default: 0, example: 1 },
|
|
114
|
+
required: false,
|
|
115
|
+
}),
|
|
116
|
+
(0, swagger_1.ApiBody)({
|
|
117
|
+
description: "The json value to set. Each property in the json is assigned as full tag name advertised to the cloud as ```availableTags``` the corresponding json path prefixed by ```tagName```. For instance, if ```tagName=\"tag\"``` and value is ```{ a: {b : 1 } }``` the advertised list of available tags is ```['tag.a.b']```. If ```tagName``` is undefined the advertised list of available tags is simply ```['a.b']```",
|
|
118
|
+
schema: { default: "{}", example: { Tag1: 1 } },
|
|
119
|
+
}),
|
|
120
|
+
(0, common_1.Post)(),
|
|
121
|
+
openapi.ApiResponse({ status: 201, type: [require("./dto/datapoint.dto").DataPointDTO] }),
|
|
122
|
+
__param(0, (0, common_1.Query)("tagName")),
|
|
123
|
+
__param(1, (0, common_1.Query)("timestamp")),
|
|
124
|
+
__param(2, (0, common_1.Query)("qos")),
|
|
125
|
+
__param(3, (0, common_1.Query)("callback")),
|
|
126
|
+
__param(4, (0, common_1.Body)()),
|
|
127
|
+
__metadata("design:type", Function),
|
|
128
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object, Object]),
|
|
129
|
+
__metadata("design:returntype", Promise)
|
|
130
|
+
], Json.prototype, "post", null);
|
|
131
|
+
Json = Json_1 = __decorate([
|
|
132
|
+
(0, swagger_1.ApiTags)("device"),
|
|
133
|
+
(0, common_1.Controller)("/device/json/"),
|
|
134
|
+
(0, common_1.Injectable)()
|
|
135
|
+
], Json);
|
|
136
|
+
exports.Json = Json;
|
|
137
|
+
//# sourceMappingURL=json.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.controller.js","sourceRoot":"","sources":["../../../src/controllers/device/json.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,2CAAkG;AAClG,oEAA4D;AAE5D,6CAA2E;AAE3E,kDAA0B;AAM1B,IAAa,IAAI,YAAjB,MAAa,IAAI;IACI,CAAC,GAAG,IAAI,eAAM,CAAC,MAAI,CAAC,IAAI,CAAC,CAAC;IAChB,aAAa,CAAgB;IAwExD,KAAK,CAAC,IAAI,CACY,UAAU,SAAS,EACjB,YAAY,SAAS,EAC3B,MAAM,SAAS,EACV,eAAe,SAAS,EACnC,CAAM;QAEd,MAAM,CAAC,GAAG,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,IAAI,KAAK,EAAa,CAAC;QAC1C,MAAM,EAAE,GAAc;YAClB,OAAO;YACP,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,CAAC;SACf,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,IAAI,CAAC,aAAa,CAAC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AI"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var Sine_1, _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.Sine = void 0;
|
|
17
|
+
const openapi = require("@nestjs/swagger");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const corvina_device_sdk_1 = require("@corvina/corvina-device-sdk");
|
|
20
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
21
|
+
let Sine = Sine_1 = class Sine {
|
|
22
|
+
l = new common_1.Logger(Sine_1.name);
|
|
23
|
+
deviceService;
|
|
24
|
+
async post(tagName = "Tag", period = 1000, amplitude = 1000, phase = 0) {
|
|
25
|
+
const t = Date.now();
|
|
26
|
+
const v = amplitude * Math.sin(phase + (Date.now() / period) * 2 * Math.PI);
|
|
27
|
+
const dataPoints = new Array();
|
|
28
|
+
const dp = {
|
|
29
|
+
tagName,
|
|
30
|
+
value: v,
|
|
31
|
+
timestamp: t,
|
|
32
|
+
};
|
|
33
|
+
dataPoints.push(dp);
|
|
34
|
+
await this.deviceService.post(dataPoints);
|
|
35
|
+
return dataPoints;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, common_1.Inject)(),
|
|
40
|
+
__metadata("design:type", typeof (_a = typeof corvina_device_sdk_1.DeviceService !== "undefined" && corvina_device_sdk_1.DeviceService) === "function" ? _a : Object)
|
|
41
|
+
], Sine.prototype, "deviceService", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, swagger_1.ApiOperation)({
|
|
44
|
+
summary: "Post a new value sampled from a sine wave with the given parameters, using wall clock as time base",
|
|
45
|
+
}),
|
|
46
|
+
(0, swagger_1.ApiQuery)({
|
|
47
|
+
name: "tagName",
|
|
48
|
+
description: "device identifier (name) of data source",
|
|
49
|
+
schema: { default: "Tag" },
|
|
50
|
+
required: false,
|
|
51
|
+
}),
|
|
52
|
+
(0, swagger_1.ApiQuery)({
|
|
53
|
+
name: "period",
|
|
54
|
+
description: "period in ms of the sine wave",
|
|
55
|
+
required: false,
|
|
56
|
+
schema: { default: 1000 },
|
|
57
|
+
}),
|
|
58
|
+
(0, swagger_1.ApiQuery)({
|
|
59
|
+
name: "amplitude",
|
|
60
|
+
description: "amplitude of the sine wave",
|
|
61
|
+
required: false,
|
|
62
|
+
schema: { default: 1000 },
|
|
63
|
+
}),
|
|
64
|
+
(0, swagger_1.ApiQuery)({ name: "phase", description: "phase of the sine wave", required: false, schema: { default: 0 } }),
|
|
65
|
+
(0, common_1.Post)(),
|
|
66
|
+
openapi.ApiResponse({ status: 201, type: [require("./dto/datapoint.dto").DataPointDTO] }),
|
|
67
|
+
__param(0, (0, common_1.Query)("tagName")),
|
|
68
|
+
__param(1, (0, common_1.Query)("period")),
|
|
69
|
+
__param(2, (0, common_1.Query)("amplitude")),
|
|
70
|
+
__param(3, (0, common_1.Query)("phase")),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], Sine.prototype, "post", null);
|
|
75
|
+
Sine = Sine_1 = __decorate([
|
|
76
|
+
(0, swagger_1.ApiTags)("device"),
|
|
77
|
+
(0, common_1.Controller)("/device/sine"),
|
|
78
|
+
(0, common_1.Injectable)()
|
|
79
|
+
], Sine);
|
|
80
|
+
exports.Sine = Sine;
|
|
81
|
+
//# sourceMappingURL=sine.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sine.controller.js","sourceRoot":"","sources":["../../../src/controllers/device/sine.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAqF;AACrF,oEAA4D;AAE5D,6CAAkE;AAOlE,IAAa,IAAI,YAAjB,MAAa,IAAI;IACI,CAAC,GAAG,IAAI,eAAM,CAAC,MAAI,CAAC,IAAI,CAAC,CAAC;IAChB,aAAa,CAAgB;IAyBxD,KAAK,CAAC,IAAI,CACY,UAAU,KAAK,EAChB,SAAS,IAAI,EACV,YAAY,IAAI,EACpB,QAAQ,CAAC;QAEzB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,IAAI,KAAK,EAAa,CAAC;QAC1C,MAAM,EAAE,GAAc;YAClB,OAAO;YACP,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,CAAC;SACf,CAAC;QACF,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ,CAAA;AA3Ca;IAA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ators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthController = void 0;
|
|
13
|
+
const openapi = require("@nestjs/swagger");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const device_health_1 = require("../services/device.health");
|
|
16
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
17
|
+
let HealthController = class HealthController {
|
|
18
|
+
health;
|
|
19
|
+
deviceHealthIndicator;
|
|
20
|
+
constructor(health, deviceHealthIndicator) {
|
|
21
|
+
this.health = health;
|
|
22
|
+
this.deviceHealthIndicator = deviceHealthIndicator;
|
|
23
|
+
}
|
|
24
|
+
check() {
|
|
25
|
+
return this.health.check([async () => this.deviceHealthIndicator.isHealthy("device")]);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, common_1.Get)(),
|
|
30
|
+
(0, terminus_1.HealthCheck)(),
|
|
31
|
+
openapi.ApiResponse({ status: 200, type: Object }),
|
|
32
|
+
__metadata("design:type", Function),
|
|
33
|
+
__metadata("design:paramtypes", []),
|
|
34
|
+
__metadata("design:returntype", void 0)
|
|
35
|
+
], HealthController.prototype, "check", null);
|
|
36
|
+
HealthController = __decorate([
|
|
37
|
+
(0, common_1.Controller)("health"),
|
|
38
|
+
__metadata("design:paramtypes", [terminus_1.HealthCheckService, device_health_1.DeviceHealthIndicator])
|
|
39
|
+
], HealthController);
|
|
40
|
+
exports.HealthController = HealthController;
|
|
41
|
+
//# sourceMappingURL=health.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../src/controllers/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAiD;AACjD,6DAAkE;AAClE,+CAAmE;AAGnE,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IACL;IAAoC;IAAxD,YAAoB,MAA0B,EAAU,qBAA4C;QAAhF,WAAM,GAAN,MAAM,CAAoB;QAAU,0BAAqB,GAArB,qBAAqB,CAAuB;IAAG,CAAC;IAIxG,KAAK;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;CACJ,CAAA;;IALI,IAAA,YAAG,GAAE;IACL,IAAA,sBAAW,GAAE;;;;;6CAGb;AAPQ,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAEW,6BAAkB,EAAiC,qCAAqB;GAD3F,gBAAgB,CAQ5B;AARY,4CAAgB"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const corvina_device_sdk_1 = require("@corvina/corvina-device-sdk");
|
|
7
|
+
const core_1 = require("@nestjs/core");
|
|
8
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const app_module_1 = require("./app.module");
|
|
11
|
+
async function bootstrap() {
|
|
12
|
+
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
|
13
|
+
try {
|
|
14
|
+
const config = new swagger_1.DocumentBuilder()
|
|
15
|
+
.setTitle("Corvina NodeJS device API")
|
|
16
|
+
.setDescription("")
|
|
17
|
+
.setVersion("1.0")
|
|
18
|
+
.addTag("device")
|
|
19
|
+
.build();
|
|
20
|
+
const document = swagger_1.SwaggerModule.createDocument(app, config);
|
|
21
|
+
swagger_1.SwaggerModule.setup("swagger-ui", app, document);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error("Error caught: ", e);
|
|
25
|
+
}
|
|
26
|
+
await app.listen(3000);
|
|
27
|
+
app.get(corvina_device_sdk_1.DeviceRunnerService).run();
|
|
28
|
+
app.get(corvina_device_sdk_1.DeviceService).on("write", (event) => {
|
|
29
|
+
console.log("Write event received", event);
|
|
30
|
+
if (process.env["WRITE_CALLBACK"]) {
|
|
31
|
+
axios_1.default.post(process.env["WRITE_CALLBACK"], event);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
bootstrap();
|
|
36
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;AAAA,oEAAiF;AACjF,uCAA2C;AAC3C,6CAAiE;AACjE,kDAA0B;AAC1B,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACpB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAEhD,IAAI;QACA,MAAM,MAAM,GAAG,IAAI,yBAAe,EAAE;aAC/B,QAAQ,CAAC,2BAA2B,CAAC;aACrC,cAAc,CAAC,EAAE,CAAC;aAClB,UAAU,CAAC,KAAK,CAAC;aACjB,MAAM,CAAC,QAAQ,CAAC;aAChB,KAAK,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,uBAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC3D,uBAAa,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;KACpD;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;KACtC;IAED,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEvB,GAAG,CAAC,GAAG,CAAC,wCAAmB,CAAC,CAAC,GAAG,EAAE,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,kCAAa,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACzC,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;YAC/B,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,CAAC;SACpD;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AACD,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var _a;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.DeviceHealthIndicator = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const terminus_1 = require("@nestjs/terminus");
|
|
16
|
+
const corvina_device_sdk_1 = require("@corvina/corvina-device-sdk");
|
|
17
|
+
let DeviceHealthIndicator = class DeviceHealthIndicator extends terminus_1.HealthIndicator {
|
|
18
|
+
deviceService;
|
|
19
|
+
constructor(deviceService) {
|
|
20
|
+
super();
|
|
21
|
+
this.deviceService = deviceService;
|
|
22
|
+
}
|
|
23
|
+
async isHealthy(key) {
|
|
24
|
+
const isHealthy = this.deviceService.status.ready == true;
|
|
25
|
+
const result = this.getStatus(key, isHealthy, this.deviceService.status);
|
|
26
|
+
if (this.deviceService.isReady) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
throw new terminus_1.HealthCheckError("Device not ready", result);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
DeviceHealthIndicator = __decorate([
|
|
33
|
+
(0, common_1.Injectable)(),
|
|
34
|
+
__metadata("design:paramtypes", [typeof (_a = typeof corvina_device_sdk_1.DeviceService !== "undefined" && corvina_device_sdk_1.DeviceService) === "function" ? _a : Object])
|
|
35
|
+
], DeviceHealthIndicator);
|
|
36
|
+
exports.DeviceHealthIndicator = DeviceHealthIndicator;
|
|
37
|
+
//# sourceMappingURL=device.health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.health.js","sourceRoot":"","sources":["../../src/services/device.health.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAA4F;AAC5F,oEAA4D;AAG5D,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,0BAAe;IACzB;IAA7B,YAA6B,aAA4B;QACrD,KAAK,EAAE,CAAC;QADiB,kBAAa,GAAb,aAAa,CAAe;IAEzD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC;QAC1D,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAEzE,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE;YAC5B,OAAO,MAAM,CAAC;SACjB;QACD,MAAM,IAAI,2BAAgB,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AAdY,qBAAqB;IADjC,IAAA,mBAAU,GAAE;yDAEmC,kCAAa,oBAAb,kCAAa;GADhD,qBAAqB,CAcjC;AAdY,sDAAqB"}
|
package/nest-cli.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"collection": "@nestjs/schematics",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"plugins": [
|
|
5
|
+
{
|
|
6
|
+
"name": "@nestjs/swagger",
|
|
7
|
+
"options": {
|
|
8
|
+
"introspectComments": true
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"tsConfigPath": "tsconfig.app.json",
|
|
13
|
+
"webpack": false
|
|
14
|
+
},
|
|
15
|
+
"entryFile": "main",
|
|
16
|
+
"sourceRoot": "src"
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@corvina/device-example",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Corvina Device Example base on corvina-device-sdk",
|
|
5
|
+
"author": "arrigo.zanette@corvina.io",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/main.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"default": "./dist/main.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
"./bin/corvina-device-example": "./bin/corvina-device-example.js"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "nest build",
|
|
20
|
+
"prebuild": "rimraf dist",
|
|
21
|
+
"start": "nest start",
|
|
22
|
+
"start:dev": "nest start --watch",
|
|
23
|
+
"start:debug": "nest start --debug --watch",
|
|
24
|
+
"start:prod": "node dist/main",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"test:watch": "jest --watch",
|
|
27
|
+
"test:cov": "jest --coverage"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@corvina/corvina-device-sdk": "^1.0.9",
|
|
31
|
+
"@nestjs/common": "^9.0.3",
|
|
32
|
+
"@nestjs/config": "^2.2.0",
|
|
33
|
+
"@nestjs/core": "^9.0.3",
|
|
34
|
+
"@nestjs/platform-express": "^9.0.3",
|
|
35
|
+
"@nestjs/swagger": "^6.0.3",
|
|
36
|
+
"@nestjs/terminus": "^9.0.0",
|
|
37
|
+
"@nestjs/testing": "^9.0.3",
|
|
38
|
+
"axios": "^0.27.2",
|
|
39
|
+
"supertest": "^6.2.4"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"corvina",
|
|
43
|
+
"iot"
|
|
44
|
+
],
|
|
45
|
+
"bin": "./bin/corvina-device-example.js",
|
|
46
|
+
"gitHead": "8d851e3b311edd9e1a3ac3007ea84747f8fc229c"
|
|
47
|
+
}
|
package/src/.env
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
APP_ID=app
|
|
2
|
+
PORT=3000
|
|
3
|
+
LOG_LEVEL=trace
|
|
4
|
+
REQUEST_LIMIT=100kb
|
|
5
|
+
SESSION_SECRET=mySecret
|
|
6
|
+
|
|
7
|
+
# fog
|
|
8
|
+
# ACTIVATION_KEY=B3ED-48CF-A9DD-6971
|
|
9
|
+
# PAIRING_ENDPOINT=https://pairing.corvina.fog:10443/api/v1/
|
|
10
|
+
|
|
11
|
+
# my pc
|
|
12
|
+
ACTIVATION_KEY=4D05-4037-974E-9482
|
|
13
|
+
PAIRING_ENDPOINT=https://pairing.corvina.fog:10443/api/v1/
|
|
14
|
+
|
|
15
|
+
# abb ac500
|
|
16
|
+
# ACTIVATION_KEY=B2A0-45AC-ABFE-D25F
|
|
17
|
+
# PAIRING_ENDPOINT=https://pairing.dev.corvina.cloud/api/v1/
|
|
18
|
+
|
|
19
|
+
AVAILABLE_TAGS=[{"name":"Tag1","type":"integer"},{"name":"Tag2","type":"integer"},{"name":"Tag3","type":"integer"}]
|
|
20
|
+
AVAILABLE_ALARMS=[{"name": "Alarm1", "severity" : 1, "source" : "Tag1", "desc" : { "en" : "Tag above normal : [Tag1]"} , "ack_required": true, "reset_required" : true, "simulation" : { "f" : "{ console.log('current tag value is ', $('Tag1')); return $('Tag1') > 100 }" } }, {"name" : "Alarm2"} ]
|
|
21
|
+
SIMULATE_TAGS=1
|
|
22
|
+
SIMULATE_ALARMS=0
|
|
23
|
+
SIMULATION_MS=1000
|
|
24
|
+
PACKET_FORMAT=bson
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# don't bother about certificates
|
|
28
|
+
NODE_TLS_REJECT_UNAUTHORIZED=0
|
|
29
|
+
|
|
30
|
+
#Swagger
|
|
31
|
+
SWAGGER_API_SPEC=/spec
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# AVAILABLE_TAGS=[{"name":"struct.a","type":"integer"},{"name":"struct.b","type":"integer"},{"name":"Tag1","type":"integer"},{"name":"Tag2","type":"integer"},{"name":"Tag3","type":"integer"},{"name":"PositionNow","type":"integer"}]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
### LAST-ENV ###
|
|
122
|
+
# don't write below this line!!
|
|
123
|
+
ACTIVATION_KEY=undefined
|
|
124
|
+
PAIRING_ENDPOINT=undefined
|
|
125
|
+
AVAILABLE_TAGS_FILE=
|
|
126
|
+
AVAILABLE_TAGS=[]
|
|
127
|
+
SIMULATE_TAGS=0
|
|
128
|
+
AVAILABLE_ALARMS=[]
|
|
129
|
+
SIMULATE_ALARMS=0
|
|
130
|
+
PACKET_FORMAT=bson
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TerminusModule } from "@nestjs/terminus";
|
|
2
|
+
import { HealthController } from "./controllers/health.controller";
|
|
3
|
+
import { Module } from "@nestjs/common";
|
|
4
|
+
import { ConfigModule } from "@nestjs/config";
|
|
5
|
+
import { DeviceClientModule } from "@corvina/corvina-device-sdk/device.module";
|
|
6
|
+
import { DeviceHealthIndicator } from "./services/device.health";
|
|
7
|
+
import { Config } from "./controllers/device/config.controller";
|
|
8
|
+
import { Dice } from "./controllers/device/dice.controller";
|
|
9
|
+
import { Sine } from "./controllers/device/sine.controller";
|
|
10
|
+
import { Json } from "./controllers/device/json.controller";
|
|
11
|
+
|
|
12
|
+
// TODO: device factory
|
|
13
|
+
@Module({
|
|
14
|
+
imports: [TerminusModule, ConfigModule.forRoot(), DeviceClientModule],
|
|
15
|
+
controllers: [Config, Dice, Sine, Json, HealthController],
|
|
16
|
+
providers: [DeviceHealthIndicator],
|
|
17
|
+
exports: [],
|
|
18
|
+
})
|
|
19
|
+
export class AppModule {}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Logger, Controller, Injectable, Body, Post, Get } from "@nestjs/common";
|
|
2
|
+
import { DeviceConfig, DeviceService } from "@corvina/corvina-device-sdk";
|
|
3
|
+
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
4
|
+
import { DeviceConfigDTO } from "./dto/deviceconfig.dto";
|
|
5
|
+
import { LicenseDataDTO } from "./dto/licensedata.dto";
|
|
6
|
+
|
|
7
|
+
/** Handles reconfiguration requests */
|
|
8
|
+
@ApiTags("device")
|
|
9
|
+
@Controller("/device")
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class Config {
|
|
12
|
+
private readonly l = new Logger(Config.name);
|
|
13
|
+
//@Inject() private readonly deviceService: DeviceService;
|
|
14
|
+
constructor(private readonly deviceService: DeviceService) {}
|
|
15
|
+
|
|
16
|
+
@ApiOperation({
|
|
17
|
+
summary: "Applied a new device configuration",
|
|
18
|
+
})
|
|
19
|
+
@Post("/config")
|
|
20
|
+
config(@Body("newConfig") newConfig: DeviceConfigDTO): DeviceConfigDTO {
|
|
21
|
+
this.l.log("apply new config");
|
|
22
|
+
//this.deviceService.reinit(newConfig);
|
|
23
|
+
return new DeviceConfigDTO(this.deviceService.getDeviceConfig());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@ApiOperation({
|
|
27
|
+
summary: "Get current applied device configuration",
|
|
28
|
+
})
|
|
29
|
+
@Get("/config")
|
|
30
|
+
get(): DeviceConfig {
|
|
31
|
+
const config = this.deviceService.getAppliedConfig();
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@ApiOperation({
|
|
36
|
+
summary: "Get current device license data",
|
|
37
|
+
})
|
|
38
|
+
@Get("/licenseData")
|
|
39
|
+
getLicenseData(): LicenseDataDTO {
|
|
40
|
+
return this.deviceService.getLicenseData();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Logger, Controller, Injectable, Post, Query, Inject } from "@nestjs/common";
|
|
2
|
+
import { DeviceService } from "@corvina/corvina-device-sdk";
|
|
3
|
+
import { DataPoint } from "@corvina/corvina-device-sdk";
|
|
4
|
+
import { ApiOperation, ApiQuery, ApiTags } from "@nestjs/swagger";
|
|
5
|
+
import { DataPointDTO } from "./dto/datapoint.dto";
|
|
6
|
+
|
|
7
|
+
/** Handles requests from Nebbiolo FOG CEP */
|
|
8
|
+
@ApiTags("device")
|
|
9
|
+
@Controller("/device/dice")
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class Dice {
|
|
12
|
+
private readonly l = new Logger(Dice.name);
|
|
13
|
+
@Inject() private readonly deviceService: DeviceService;
|
|
14
|
+
|
|
15
|
+
@ApiOperation({
|
|
16
|
+
summary: "Post binary (0/1) values sampled from a uniform random number distribution",
|
|
17
|
+
})
|
|
18
|
+
@ApiQuery({
|
|
19
|
+
name: "tagName",
|
|
20
|
+
description: "device identifier (name) of data source",
|
|
21
|
+
schema: { default: "Tag" },
|
|
22
|
+
required: false,
|
|
23
|
+
})
|
|
24
|
+
@Post()
|
|
25
|
+
async post(@Query("tagName") tagName: string): Promise<DataPointDTO[]> {
|
|
26
|
+
const t = Date.now();
|
|
27
|
+
const v = Math.random() > 0.5;
|
|
28
|
+
const dataPoints = new Array<DataPoint>();
|
|
29
|
+
const dp: DataPoint = {
|
|
30
|
+
tagName,
|
|
31
|
+
value: v,
|
|
32
|
+
timestamp: t,
|
|
33
|
+
};
|
|
34
|
+
dataPoints.push(dp);
|
|
35
|
+
await this.deviceService.post(dataPoints);
|
|
36
|
+
return dataPoints;
|
|
37
|
+
}
|
|
38
|
+
}
|