1.2.1 • Published 4 years ago
kocdigital-platform360-nodejs-sdk v1.2.1
tsconfig.json example
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"importHelpers": true,
"jsx": "react",
"alwaysStrict": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"experimentalDecorators":true
},
"include": [
"src/**/*",
"__tests__/**/*"
]
}
Mqtt Client – Hello World
import { EnrollmentService, DeviceService, DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceBatteryCreateData, BatteryStatus, DeviceRebootCreateData } from 'kocdigital-platform360-sdk';
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
// Mqtt Client Options
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Creating Registration Service to Register Device
var enrollmentService = new EnrollmentService(options);
// Creating Device Service to Use Device Functionalities
var deviceService = new DeviceService(options);
// Creating Device Management Service to Use Device Management Objects
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// It creates a device on the platform.
await enrollmentService.enroll("TestDevice1231");
// Here the related resources and properties are loaded to device service objects
await deviceService.connectToPlatform();
// Here the related resources and properties are loaded to device management objects
await deviceManagementService.connectToPlatform();
// Sensor Creation
// Parameters: Sensor Name and isBidirectional
var result = await deviceService.createSensor("SensorName1231", true);
console.log(result);
let existedSensors = await deviceService.getSensors();
// Notification event when any sensor value change request is handled by device.
await deviceService.setSensorValueChangeRequestNotificationEventHandler((sensorId, value) => {
console.log(sensorId);
console.log(value);
});
// It sends the request to platform to save sensor data.
await deviceService.pushSensorDataToPlatform(existedSensors[0].Id, "OFF");
await deviceService.pushSensorDataToPlatform(existedSensors[0].Id, "ON");
let battery = new DeviceBatteryCreateData();
battery.BatteryLevel = 10;
battery.BatteryStatus = BatteryStatus.LowBattery
battery.Name = "DeviceBattery";
let batteryBackup = new DeviceBatteryCreateData();
batteryBackup.BatteryLevel = 100;
batteryBackup.BatteryStatus = BatteryStatus.Normal
batteryBackup.Name = "DeviceSecondBattery";
let reboot = new DeviceRebootCreateData();
reboot.Name = "DeviceReboot/FactoryResetFunction";
// Notification event when reboot update request is handled to process.
await deviceManagementService.setRebootRequestNotificationEventHandler((isRebootRequest, isFactoryResetRequest) => {
console.log(isRebootRequest);
console.log(isFactoryResetRequest);
})
let batteryResult = await deviceManagementService.createBattery(battery);
let batteryBackupResult = await deviceManagementService.createBattery(batteryBackup);
let rebootResult = await deviceManagementService.createReboot(reboot);
let batteries = await deviceManagementService.getBatteries();
let reboots = await deviceManagementService.getReboot();
console.log(batteryResult);
console.log(batteryBackupResult);
console.log(rebootResult);
console.log(batteries);
console.log(memories);
})();
1.1. Device Registration Method
import { EnrollmentService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Creating Registration Service to Register Device to the System
var enrollmentService = new EnrollmentService(options);
(async () => {
// Device Registration to the System
let result = await enrollmentService.enroll('deviceName');
console.log(result);
})();
1.2. Multiple Device Functionality
import { EnrollmentService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options2 = mqttOptionsBuilder
.withCSEId(#CSEId2)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Creating Registration Service to Register Device to the System
var enrollmentService = new EnrollmentService(options);
var enrollmentService2 = new EnrollmentService(options2);
(async () => {
// Device Registration to the System
let result = await enrollmentService.enroll('deviceName');
let result2 = await enrollmentService2.enroll('deviceName2');
console.log(result);
console.log(result2);
})();
2.1. Connect to Platform Method
import { DeviceService, DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
var deviceManagementService = new DeviceManagementService(options);
// Create Device Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// The service that its functions will be used has to be connected to platform first
// In this connection process, related resources and properties are loaded to service objects
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Device Service Connection to Platform
// Here related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
})();
2.2. Sensor Creation Method
import { DeviceService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// Device Service Connection to Platform
// Here related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
// Create Bidirectional Sensor
var bidirectionalSensor = await deviceService.createSensor("SensorName", true);
console.log(bidirectionalSensor);
})();
2.3. Sensor Notification Event Handler Method
import { DeviceService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
// Mqtt Client Options
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// Device Service Connection to Platform
// Here Related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
// Notification event when any sensor value change request is sent.
deviceService.setSensorValueChangeRequestNotificationEventHandler(async(e) => {
console.log(e.SensorId);
console.log("pushed new data to sensor id = " + e.SensorId);
});
})();
2.4. Push Sensor Data to Platform Method
import { DeviceService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Sensor Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// Device Service Connection to Platform
// Here related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
// Create Sensor
var sensor = await deviceService.createSensor("SensorName", false);
console.log(sensor);
// Push Sensor Data to Platform
await deviceService.pushSensorDataToPlatform(sensor.SensorId,"SensorValue");
})();
Yukardaki basligin 2. ornegi
import { DeviceService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// Device Service Connection to Platform
// Here related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
// Get All Sensors
let sensors = await deviceService.getSensors();
if(sensors && sensors.length > 0){
// Push sensor data with formatted data as unit, extracted data and raw data to platform
await deviceService.pushSensorFormattedDataToPlatform(sensors[0].Id, "raw data", "data unit (ex: Celsius)","extracted value (ex: 25)");
}
})();
2.5. Sensor Deletion Method
import { DeviceService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Service with Mqtt Options
var deviceService = new DeviceService(options);
(async () => {
// Device Service Connection to Platform
// Here related resources and properties are loaded to deviceService objects
await deviceService.connectToPlatform();
// Delete Sensor
let deletedSensor = await deviceService.deleteSensor("sensorId");
console.log(deletedSensor);
})();
3.1. Battery Related Methods
Create Battery Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceBatteryCreateData, BatteryStatus } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Data Settings Belongs to Creating Battery
var deviceBatteryCreateData = new DeviceBatteryCreateData;
deviceBatteryCreateData.Name = "BatteryName";
deviceBatteryCreateData.BatteryStatus = BatteryStatus.Charging;
deviceBatteryCreateData.BatteryLevel = 2;
// Create Battery Request
var battery = await deviceManagementService.createBattery(deviceBatteryCreateData);
console.log(battery);
})();
Retrieve Battery Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve the Batteries of the Device Request
let batteries = await deviceManagementService.getBatteries();
})();
Update Battery Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, BatteryStatus, DeviceBatteryUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
var updateBatteryData = new DeviceBatteryUpdateData();
updateBatteryData.BatteryId = "batteryId";
updateBatteryData.BatteryLevel = 100;
updateBatteryData.BatteryStatus = BatteryStatus.ChargingComplete;
// Update battery request that belongs to given battery id with new data
var battery = await deviceManagementService.updateBattery(updateBatteryData);
console.log(battery);
})();
Delete Battery Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// delete battery request that belongs to given battery id
var battery = await deviceManagementService.deleteBattery("batteryId");
console.log(battery);
})();
3.2. Memory Related Methods
Create Memory Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceMemoryCreateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Update Memory Data
var memoryCreateData = new DeviceMemoryCreateData();
memoryCreateData.Name = "MemoryName";
memoryCreateData.TotalMemory = 8589934592 ; // bytes - 1 GB
memoryCreateData.AvailableMemory = 4194304000; // bytes - 500 MB
// Create Memory Request
var memory = await deviceManagementService.createMemory(memoryCreateData);
console.log(memory);
})();
Retrieve Memory Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve the Memories of the Device Request
let memories = await deviceManagementService.getMemories();
})();
Update Memory Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceMemoryUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Update Memory Data
var memoryUpdateData = new DeviceMemoryUpdateData();
memoryUpdateData.MemoryId = "memoryId";
memoryUpdateData.AvailableMemory = 4194304000; // bytes - 500 MB
// Update memory request that belongs to given memory id with new data
var memory = await deviceManagementService.updateMemory(memoryUpdateData);
console.log(memory);
})();
Delete Memory Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve Memory Request
var memory = await deviceManagementService.deleteMemory("memoryId");
console.log(memory);
})();
3.3. Physical Device Info Related Methods
Create Physical Device Info Method
import { DevicePhysicalDeviceCreateData, DeviceManagementService, DeviceClientMqttOptionsBuilder} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Create Physical Device with Mandatory Fields
var physicalDeviceCreateData = new DevicePhysicalDeviceCreateData();
physicalDeviceCreateData.Name = "PhysicalDeviceName";
physicalDeviceCreateData.DeviceLabel = "Device Label";
physicalDeviceCreateData.Manufacturer = "Manufacturer";
physicalDeviceCreateData.Model = "Model";
physicalDeviceCreateData.DeviceType = "Device Type";
// Create Physical Device Info Request
var physicalDeviceInfo = await deviceManagementService.createPhysicalDeviceInfo(physicalDeviceCreateData);
console.log(physicalDeviceInfo);
})();
Retrieve Physical Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve Physical Device Info Request
let physicalDeviceInfo = await deviceManagementService.getPhysicalDeviceInfo();
})();
Update Physical Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DevicePhysicalDeviceUpdateData} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Update Physical Device
var physicalDeviceUpdateData = new DevicePhysicalDeviceUpdateData();
physicalDeviceUpdateData.PhysicalDeviceInfoId = "PhysicalDeviceInfoId";
physicalDeviceUpdateData.OsVersion = "OsVersion";
// Update Physical Device Info Request
var physicalDeviceInfo = await deviceManagementService.updatePhysicalDeviceInfo(physicalDeviceUpdateData);
console.log(physicalDeviceInfo);
})();
Delete Physical Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Delete Physical Device Info Request
var physicalDeviceInfo = await deviceManagementService.deletePhysicalDeviceInfo("physicalDeviceInfoId");
console.log(physicalDeviceInfo);
})();
3.4. Area Network Info Related Methods
Create Area Network Info Method
import { AreaNetworkInfoCreateData, DeviceManagementService, DeviceClientMqttOptionsBuilder} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Create Area Network Info
var areaNetworkInfoCreate = new AreaNetworkInfoCreateData();
areaNetworkInfoCreate.Name = "AreaNetworkInfoName";
areaNetworkInfoCreate.AreaNetworkType = "Area Network Type";
areaNetworkInfoCreate.ListOfDevices = ["CreatedBeforeAreaNetworkDeviceInfoResourceId"];
// Create Area Network Info Request
var areaNetworkInfo = await deviceManagementService.createAreaNetworkInfo(areaNetworkInfoCreate);
console.log(areaNetworkInfo);
})();
Retrieve Area Network Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve Area Network Info Request
let areaNetworkInfo = await deviceManagementService.getAreaNetworkInfo();
})();
Update Area Network Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, AreaNetworkInfoUpdateData} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Update Area Network Info
var areaNetworkInfoUpdateData = new AreaNetworkInfoUpdateData();
areaNetworkInfoUpdateData.AreaNetworkInfoId = "AreaNetworkInfoId"
areaNetworkInfoUpdateData.AreaNetworkType = "Area Network Type";
areaNetworkInfoUpdateData.ListOfDevices = ["CreatedBeforeAreaNetworkDeviceInfoResourceId","CreatedBeforeAreaNetworkDeviceInfoResourceId2"];
// Update Area Network Info Request
var areaNetworkInfo = await deviceManagementService.updateAreaNetworkInfo(areaNetworkInfoUpdateData);
console.log(areaNetworkInfo);
})();
Delete Area Network Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Delete Area Network Info by Id
var areaNetworkInfo = await deviceManagementService.deleteAreaNetworkInfo("AreaNetworkInfoId");
console.log(areaNetworkInfo);
})();
3.5. Area Network Device Info Related Methods
Create Area Network Device Info Method
import { AreaNetworkDeviceInfoCreateData, DeviceManagementService, DeviceClientMqttOptionsBuilder} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Create Area Network Device Info
var areaNetworkDeviceInfoCreateData = new AreaNetworkDeviceInfoCreateData();
areaNetworkDeviceInfoCreateData.Name = "AreaNetworkDeviceInfoName";
areaNetworkDeviceInfoCreateData.DevID = "DevID";
areaNetworkDeviceInfoCreateData.DevType = "DevType";
areaNetworkDeviceInfoCreateData.AreaNetworkId = "AreaNetworkId";
areaNetworkDeviceInfoCreateData.ListOfNeighbors = ["Neighbor1"];
// Create Area Network Device Info Request
var areaNetworkDeviceInfo = await deviceManagementService.createAreaNetworkDeviceInfo(areaNetworkDeviceInfoCreateData);
console.log(areaNetworkDeviceInfo);
})();
Retrieve Area Network Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve Area Network Device Info Request
let areaNetworkDeviceInfo = await deviceManagementService.getAreaNetworkDeviceInfo();
})();
Update Area Network Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, AreaNetworkDeviceInfoUpdateData} from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Update Area Network Device Info
var areaNetworkDeviceInfoUpdateData = new AreaNetworkDeviceInfoUpdateData();
areaNetworkDeviceInfoUpdateData.AreaNetworkDeviceInfoId = "AreaNetworkDeviceInfoId";
areaNetworkDeviceInfoUpdateData.DevStatus = "Sleeping";
// Update Area Network Device Info Request
var areaNetworkDeviceInfo = await deviceManagementService.updateAreaNetworkDeviceInfo(areaNetworkDeviceInfoUpdateData);
console.log(areaNetworkDeviceInfo);
})();
Delete Area Network Device Info Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Delete Area Network Device Info Request
var areaNetworkDeviceInfo = await deviceManagementService.deleteAreaNetworkDeviceInfo("AreaNetworkDeviceInfoId");
console.log(areaNetworkDeviceInfo);
})();
3.6. Reboot Related Methods
Create Reboot Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceRebootCreateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Create Reboot
var rebootCreateData = new DeviceRebootCreateData();
rebootCreateData.Name = "RebootName";
// Create Reboot Request
var reboot = await deviceManagementService.createReboot(rebootCreateData);
console.log(reboot);
})();
Reboot Notification Event Handler Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceRebootUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Notification event when new reboot update request is processed.
deviceManagementService.setRebootRequestNotificationEventHandler(async(e) => {
console.log("updated reboot id = " + e.DeviceRebootId);
});
// Set Data to Update Reboot
var rebootUpdateData = new DeviceRebootUpdateData();
rebootUpdateData.DeviceRebootId = "DeviceRebootId";
rebootUpdateData.IsFactoryReset = true;
// Update Reboot Request
var reboot = await deviceManagementService.updateReboot(rebootUpdateData);
console.log(reboot);
})();
Retrieve Reboot Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Retrieve Reboots Request
let reboots = await deviceManagementService.getReboot();
})();
Update Reboot Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceRebootUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Update Reboot
var rebootUpdateData = new DeviceRebootUpdateData();
rebootUpdateData.DeviceRebootId = "DeviceRebootId";
rebootUpdateData.IsFactoryReset = true;
// Update Reboot Request
var reboot = await deviceManagementService.updateReboot(rebootUpdateData);
console.log(reboot);
})();
Delete Reboot Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Delete Reboot Request
var reboot = await deviceManagementService.deleteReboot("DeviceRebootId");
console.log(reboot);
})();
3.7. Firmware Related Methods
Create Firmware Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceFirmwareCreateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Create Firmware
var firmwareCreateData = new DeviceFirmwareCreateData();
firmwareCreateData.Name = "FirmwareName";
firmwareCreateData.Version = "Version";
firmwareCreateData.URL = "URL";
// Create Firmware Request
var firmware = await deviceManagementService.createFirmware(firmwareCreateData);
console.log(firmware);
})();
Firmware Notification Event Handler Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceFirmwareUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Notification event when new firmware upgrade request is processed.
deviceManagementService.setFirmwareRequestNotificationEventHandler(async(e) => {
console.log("updated firmware id = " + e.DeviceFirmwareId);
});
// Set Data to Update Firmware
var firmwareUpdateData = new DeviceFirmwareUpdateData();
firmwareUpdateData.DeviceFirmwareId = "DeviceFirmwareId";
firmwareUpdateData.Version = "Version2";
firmwareUpdateData.Update = false;
// Update Firmware Request
var firmware = await deviceManagementService.updateFirmware(firmwareUpdateData);
console.log(firmware);
})();
Retrieve Firmware Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatformAsync();
// Retrieve Firmware Request
let firmware = await deviceManagementService.getFirmware();
})();
Update Firmware Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder, DeviceFirmwareUpdateData } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Set Data to Update Firmware
var firmwareUpdateData = new DeviceFirmwareUpdateData();
firmwareUpdateData.DeviceFirmwareId = "DeviceFirmwareId";
firmwareUpdateData.Version = "Version2";
firmwareUpdateData.Update = false;
// Update Firmware Request
var firmware = await deviceManagementService.updateFirmware(firmwareUpdateData);
console.log(firmware);
})();
Delete Firmware Method
import { DeviceManagementService, DeviceClientMqttOptionsBuilder } from 'kocdigital-platform360-sdk';
// Mqtt Client Options
var mqttOptionsBuilder = new DeviceClientMqttOptionsBuilder();
var options = mqttOptionsBuilder
.withCSEId(#CSEId)
.withClientId(#ClientId)
.withMqttOptions(#MqttPointOfAccess, #MqttPort, 300000)
.build();
// Create Device Management Service with Mqtt Options
var deviceManagementService = new DeviceManagementService(options);
(async () => {
// Device Management Service Connection to Platform
await deviceManagementService.connectToPlatform();
// Delete Firmaware Request
var firmware = await deviceManagementService.deleteFirmware("FirmwareId");
console.log(firmware);
})();