@corvina/device-example
Version:
Corvina Device Example based on @corvina/device-client
38 lines (35 loc) • 1.24 kB
text/typescript
import { Logger, Controller, Injectable, Post, Query, Inject } from "@nestjs/common";
import { DeviceService } from "@corvina/device-client";
import { DataPoint } from "@corvina/device-client";
import { ApiOperation, ApiQuery, ApiTags } from "@nestjs/swagger";
import { DataPointDTO } from "./dto/datapoint.dto";
("device")
("/device/dice")
()
export class Dice {
private readonly l = new Logger(Dice.name);
() private readonly deviceService: DeviceService;
({
summary: "Post binary (0/1) values sampled from a uniform random number distribution",
})
({
name: "tagName",
description: "device identifier (name) of data source",
schema: { default: "Tag" },
required: false,
})
()
async post(("tagName") tagName: string): Promise<DataPointDTO[]> {
const t = Date.now();
const v = Math.random() > 0.5;
const dataPoints = new Array<DataPoint>();
const dp: DataPoint = {
tagName,
value: v,
timestamp: t,
};
dataPoints.push(dp);
await this.deviceService.post(dataPoints);
return dataPoints;
}
}