@corvina/device-example 1.0.23 → 1.1.1
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 +15 -11
- package/README.md +3 -3
- package/dist/controllers/device/config.controller.d.ts +1 -1
- package/dist/controllers/device/config.controller.d.ts.map +1 -1
- package/dist/controllers/device/config.controller.js +2 -1
- package/dist/controllers/device/config.controller.js.map +1 -1
- package/dist/main.js +18 -5
- package/dist/main.js.map +1 -1
- package/ignore +0 -0
- package/main-linux +0 -0
- package/main-macos +0 -0
- package/main-win.exe +0 -0
- package/out +6922 -0
- package/package.json +4 -3
- package/src/controllers/device/config.controller.ts +3 -2
- package/src/main.ts +20 -6
- package/tsconfig.app.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corvina/device-example",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Corvina Device Example base on @corvina/device-client",
|
|
5
5
|
"author": "arrigo.zanette@corvina.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test:cov": "jest --coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@corvina/device-client": "^1.0
|
|
38
|
+
"@corvina/device-client": "^1.1.0",
|
|
39
39
|
"@nestjs/common": "^9.0.3",
|
|
40
40
|
"@nestjs/config": "^2.2.0",
|
|
41
41
|
"@nestjs/core": "^9.0.3",
|
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
],
|
|
54
54
|
"bin": "./bin/corvina-device-example.js",
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@nestjs/cli": "^9.2.0",
|
|
56
57
|
"pino-pretty": "^8.1.0",
|
|
57
58
|
"supertest": "^6.2.4",
|
|
58
59
|
"tsc-watch": "^5.0.3",
|
|
59
60
|
"typescript": "^4.7.4"
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "1ff32e216a6425c186a28ec6404dee37c214a40f"
|
|
62
63
|
}
|
|
@@ -17,9 +17,10 @@ export class Config {
|
|
|
17
17
|
summary: "Applied a new device configuration",
|
|
18
18
|
})
|
|
19
19
|
@Post("/config")
|
|
20
|
-
config(@Body("newConfig") newConfig:
|
|
20
|
+
config(@Body("newConfig") newConfig: DeviceConfig): DeviceConfigDTO {
|
|
21
21
|
this.l.log("apply new config");
|
|
22
|
-
//
|
|
22
|
+
// <DeviceConfigDTO>newConfig.toDeviceConfig(); methods are not available ...?
|
|
23
|
+
this.deviceService.reinit(newConfig);
|
|
23
24
|
return new DeviceConfigDTO(this.deviceService.getDeviceConfig());
|
|
24
25
|
}
|
|
25
26
|
|
package/src/main.ts
CHANGED
|
@@ -4,7 +4,7 @@ import axios from "axios";
|
|
|
4
4
|
import { AppModule } from "./app.module";
|
|
5
5
|
import { Logger, LoggerService } from "@nestjs/common";
|
|
6
6
|
import { Logger as NestPinoLogger } from "nestjs-pino";
|
|
7
|
-
import { DeviceService, DeviceRunnerService } from "@corvina/device-client";
|
|
7
|
+
import { DataPoint, DeviceService, DeviceRunnerService } from "@corvina/device-client";
|
|
8
8
|
|
|
9
9
|
async function bootstrap() {
|
|
10
10
|
const app = await NestFactory.create(AppModule, {
|
|
@@ -29,7 +29,7 @@ async function bootstrap() {
|
|
|
29
29
|
l.error(e);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
await app.listen(3000);
|
|
32
|
+
await app.listen(process.env.PORT || 3000);
|
|
33
33
|
|
|
34
34
|
app.get(DeviceRunnerService).run();
|
|
35
35
|
|
|
@@ -44,10 +44,24 @@ async function bootstrap() {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
device.on("write", (event) => {
|
|
47
|
-
l.log(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
l.log(`Write event received ${JSON.stringify(event)}`);
|
|
48
|
+
|
|
49
|
+
const t = Date.now();
|
|
50
|
+
const dataPoints = new Array<DataPoint>();
|
|
51
|
+
const dp: DataPoint = {
|
|
52
|
+
tagName: event.tagName,
|
|
53
|
+
value: event.v,
|
|
54
|
+
timestamp: t,
|
|
55
|
+
};
|
|
56
|
+
dataPoints.push(dp);
|
|
57
|
+
device.post(dataPoints, {
|
|
58
|
+
qos: 0,
|
|
59
|
+
cb: process.env["WRITE_CALLBACK"]
|
|
60
|
+
? (error, tagName, modelPath) => {
|
|
61
|
+
axios.post(process.env["WRITE_CALLBACK"], event).catch((err) => "Error executing write callback");
|
|
62
|
+
}
|
|
63
|
+
: undefined,
|
|
64
|
+
});
|
|
51
65
|
});
|
|
52
66
|
}
|
|
53
67
|
bootstrap();
|