- Your machine has to have Node, you can download from https://nodejs.org/en/
- Clone the project by using command:
git clone https://github.com/anhminh10a2hoa/IoT-Typescript-Client
- After cloning the project, open your terminal and navigate to the root of the project folder location.
- Install all dependencies used:
npm install
- Create a file named app.ts in the /src folder.
- Follow Usage to create your own file before starting the client:
npm start
- The application is using Jest for testing
- NOTE: If you want to run all of the test cases, create a file named .env in root folder and its contents like that:
USERNAME_TICKET=your_username
PASSWORD_TICKET=your_password
- Run testing:
npm test
- If you want to check how many percentages this test cases cover of the application, run:
npm run coverage
- Create your own account at https://my.iot-ticket.com/Dashboard/
const client = new Client("https://my.iot-ticket.com/api/v1/", "username", "password");
const newDevice = new Device();
newDevice.setName("DeviceName");
newDevice.setManufacturer("Manufacturer");
newDevice.setType("DeviceType");
const d1 = new DeviceAttribute();
d1.setKey("OS");
d1.setValue("Windows 7");
const d2 = new DeviceAttribute();
d2.setKey("Screensize");
d2.setValue("1960*1800");
newDevice.setAttributes(d1, d2);
client.registerDevice(newDevice);
const device = await client.getDevice("device_id");
console.log(device.toString());
const listOfDevices = await client.getListDevices(100, 0);
for(let d of listOfDevices.getItems()) {
let deviceCastType = Object.assign(new Device(), d)
console.log(deviceCastType.toString());
}
const listOfDataNodes = await client.getDataNodeList("device_id", 100, 0);
for(let dn of listOfDataNodes.getItems()) {
let dataNodeCastType = Object.assign(new DataNode(), dn)
console.log(dataNodeCastType.toString());
}
const quota = await client.getAllQuota();
console.log(quota.toString());
const deviceQuota = await client.getDeviceQuota("device_id");
console.log(deviceQuota.toString());
client.deleteDevice("device_id");
const criteria = new StatisticalDataQueryCriteria();
criteria.setDeviceId("device_id")
criteria.setFromdate(1383228800000)
criteria.setTodate(1550831791000)
criteria.setGrouping(Grouping.Year);
criteria.setDatanodes(["Temperature","sensor"]);
const statisticalData = await client.readStatisticalData(criteria);
for(let statisticalDataRead of statisticalData.getDatanodeReads()) {
let statisticalDataReadCastType = Object.assign(new StatisticalDataRead(), statisticalDataRead)
console.log(statisticalDataReadCastType.toString());
for(let value of statisticalDataReadCastType.getValues()) {
let valueCastType = Object.assign(new StatisticalDataReadValue(), value)
console.log(valueCastType.toStringSDRV());
}
}
const criteria = new DataQueryCriteria();
criteria.setDeviceId("device_id")
criteria.setFromdate(1383228800000)
criteria.setTodate(1550831791000)
criteria.setDatanodes(["/MainEngine/Core/Temperature"]);
const processData = await client.readProcessData(criteria);
for(let dataNodeRead of processData.getDatanodeReads()) {
let dataNodeReadCastType = Object.assign(new DataNodeRead(), dataNodeRead)
console.log(dataNodeReadCastType.toString());
for(let value of dataNodeReadCastType.getValues()) {
let valueCastType = Object.assign(new DataNodeReadValue(), value)
console.log(valueCastType.toStringDNRV());
}
}
const dataArray = new Array<DataNodeWriteValue>();
const d1 = new DataNodeWriteValue();
d1.setName("Temperature");
d1.setPath("/MainEngine/Core");
d1.setValue(70);
d1.setTimestampMilliseconds(1414488510057);
d1.setUnit("c");
const d2 = new DataNodeWriteValue();
d2.setName("Latitude");
d2.setPath("/MainEngine/Core");
d2.setValue(63);
d2.setDataType(DataType.LongType);
dataArray.push(d1);
dataArray.push(d2);
client.writeProcessData("device_id", dataArray)