@kocdigital/kocdigital-platform360-service-sdk-nodejs
v1.9.3
Published
KocDigital platform360 node.js software development kit for services which manages multiple devices, instead of single device
Downloads
7
Readme
Platform360
Service SDK for Node.js
Version 1.9.1
24.06.2021
Glossary
Platform360: Platform360 is a highly scalable IoT platform built on top of the OneM2M standard. It enables vertical solutions to be built on top of it using APIs.
OneM2M: It is an open standard with a transparent development process & an open access to all deliverables. The new standard oneM2M (one machine-to-machine) aims to standardize the architecture and protocols of Internet of Things (IoT) middleware for better interoperability.
Resource: A resource is a uniquely addressable entity in oneM2M architecture. It is transferred and manipulated using CRUD operations.
Device: It represents the asset that publishes data into the Platform360, it can be a gateway or any sensor.
Sensor: A sensor is a device, module, machine, or subsystem whose purpose is to detect events or changes in its environment and send the information to the platform. (E.g. light, temperature, magnetic fields, gravity, humidity, vibration, pressure, electrical fields, sound, etc.)
Device Management Objects
Battery: Information related to a battery within the device.
Memory: Information associated with the memory in use by a device.
Device Info: General information that identifies a device and its model and manufacturer.
Area Network: Information about network type and devices in the M2M Area Network that consists of heterogeneous endpoint devices, such as sensors and actuators, connected through a sensor network based on various technologies, for example, ZigBee, M-Bus, and Bluetooth.
Reboot: The action that allows rebooting the device.
Firmware: Information for the firmware installed on the device.
Mqtt Client Options
CSEId: It is used to identify a customer on the platform. This CSEId will be given by KoçDigital before your implementation starts.
ClientId: It is used to identify a customer application on the platform. This ClientId will be given by KoçDigital before your implementation starts.
MqttPointOfAccess: It is the IP of Mqtt Broker. It will be provided by KoçDigital.
MqttPort: It is the Port of Mqtt Broker. It will be provided by KoçDigital.
TimeOut: It is the time out info to get response by service. You must set time out parameter as second (e.g. 20).
MqttUserName: It is the User Name of Mqtt Broker. It will be provided by KoçDigital.
MqttPassword: It is the Password of Mqtt Broker. It will be provided by KoçDigital.
PLATFORM360 SERVICE SDK
The Platform360 Service SDK is fully functional implementation of the OneM2M standardization. It is designed to minimize memory footprint while making it easy to integrate applications into the Platform360 distributed computing view of the Internet of Things. The goal of the Service SDK is to make creating applications that use it simple, but to also give the developer enough flexibility to create very sophisticated applications.
Overview
In the first section, you can find Hello World example and in the later sections, you will see all Service SDK functionalities for Node.js supported by Platform360.
Please look for details about each method classified as below under related topics.
- Enrollment Functionalities
- Automatic Empty Device Id Retrieval
- Enroll Device Method
- Disenroll Device Method
- Multiple Device Functionality
- Device Functionalities
- Connect to Platform Method
- Create Sensor Method
- Sensor Notification Event Handler Method
- Push Sensor Data to Platform Method
- Delete Sensor Method
- Retrieve Sensor By Name Method
- Device Enrolment Event Handler
- Sensor CRUD Operations Event Handler
- Get All Devices Method
- Get Devices By Label Method
- Device Management Functionalities
- Battery Related Methods
- Memory Related Methods
- Physical Device Info Related Methods
- Area Network Info Related Methods
- Area Network Device Info Related Methods
- Reboot Related Methods
- Firmware Related Methods
- SDK Management Functionalities
- Restart Event Handler
- Pause Event Handler
- Continue Event Handler
- Health Check Event Handler
If you have questions about the Platform360 Service SDK, please contact us at [email protected].
Service SDK for Node.js
You can see Service SDK - Hello World example and all functionalities and methods in detail below to be able to create your application.
Mqtt Client – Hello World
Platform360 Service SDK is implemented by MQTT. To develop a very simple "Hello, world!" MQTT client for Platform360, you need to follow these steps:
Please look for details about Mqtt Client Options classified below: Mqtt Client Options.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
// Build-in Logger's configurations
sdk.Logger.Enabled = true;//Default
sdk.Logger.Sources = [sdk.LogSource.Console];
sdk.Logger.Level = sdk.LogLevel.Warn;//Default = LogLevel.Info
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut),"#MqttUserName", "#MqttPassword")
.Build();
// Create Enrollment Service to Enroll Device
var enrollmentService = sdk.Factories.EnrollmentServiceFactory.CreateEnrollmentService(options);
// Create Device Service to Use Device Functionalities
var deviceService = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
// Create Device Management Service to Use Device Management Objects
var deviceManagementService = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
(async () => {
// It's important to cach all rejectsions within a async request, otherwise app can crash.
//Enables create event notifications for all device enrollment operations
//Uses enrollment service, calling this method one time is enough for lifetime
//When you want to disable notifications, use DisableDeviceEnrollmentNotifications() method
//await service.DisableDeviceEnrollmentNotifications();
await service.EnableDeviceEnrollmentNotifications({
NotificationUris: []//If you want to notify external apis
}).catch(reason => { console.log(reason) });
//Event handler for enrollment events
/*
operation types:
Update = 1,
DirectDelete = 2,
Create = 3,
ChildDelete = 4
*/
deviceService.UseDeviceModificationNotificationHandler(x => {
console.log(`New device enrolled with
deviceId: ${x.DeviceId},
deviceResourceId: ${x.DeviceResourceId},
DeviceName: ${x.DeviceName},
Operation: ${sdk.Service.Contracts.NotificationType[x.Operation]},
Attributes: ${JSON.stringify(Array.from(x.Attributes))}`);
});
// Get a empty device Id from platform. Use this id for enrollment operation
// For a successfull request you can get Id with deviceIdResult.DeviceId property
let deviceIdResult = await enrollmentService.GetAvailableDeviceId();
if (!deviceIdResult.IsSuccess) {
Logger.Danger("Cannot Get Empty Id From Platform!");
return;
}
let userDefinedAttributes = new Map();
userDefinedAttributes.set("TestKey","TestValue");
// It creates a device on the platform.
// You can add Attributes as Key, Value pairs like MyId: 123 as ["MyId", "123"]
let enrolmentResult = await enrollmentService.EnrollDeviceAsync({
DeviceName: "test-device-1",
DeviceId: deviceIdResult.DeviceId,
Attributes: userDefinedAttributes
}).catch(reason => { console.log(reason) });
// Get Devices with Labels/Attributes
var deviceResult = await deviceService.GetDevicesByLabel({Labels : [
{ Key: "TestKey", Values: ["TestValue"]}
]})
.catch((reason) => { console.log(reason) });
// Get All Registered Devices
var allDevicesResult = await deviceService.GetAllDevices()
.catch((reason) => { console.log(reason) });
//For sending notifications related to sensor crud operations
//use EnableSensorModificationNotifications method.
//Enabling it once for a sensor enough.
//When you want to disable sensor crud notifications for a device
//use DisableSensorModificationNotifications({DeviceResourceId: deviceResourceId})
await service.EnableSensorModificationNotifications({
DeviceResourceId: enrolmentResult.DeviceResourceId,
NotificationUris: []//If you want to notify external apis
}).catch(reason => { console.log(reason) });
//Event handler for sensor crud events
//Triggers when a new sensor created or deleted or updated
/*
operation types:
Update = 1,
DirectDelete = 2,
Create = 3,
ChildDelete = 4
*/
service.UseSensorModificationNotificationHandler(x => {
console.log(`Sensor based operation occured for device
DeviceResourceId: ${x.DeviceResourceId}, with
SensorResourceId: ${x.SensorResourceId},
SensorName: ${x.SensorName},
IsBidirectional: ${x.IsBidirectional},
Operation: ${sdk.Service.Contracts.NotificationType[x.Operation]}`);
});
// Sensor Creation
// Parameters: DeviceResourceId, Sensor Name and isBidirectional as an object parameneter and
// another object with a function named GetPoA for notifications. When a command received there will be post request to this url
let sensorResult = await deviceService.CreateSensorAsync({
DeviceResourceId: enrolmentResult.DeviceResourceId,
IsBidirectional: true,
SensorName: "BidirectionalSensor---1"
}, { GetPoA: () => "http://example.com/api/postme" }).catch(reason => { console.log(reason) });
// Sensors retrieval by name
// Parameters: DeviceResourceId, List of Sensor Names.
// Retrieves sensors with given exact names for a given device
let sensors = await deviceService.GetSensorsByName(
enrolmentResult.DeviceResourceId,
["BidirectionalSensor---1"]
)
.catch(reason => { console.log(reason) });
// Device Service Connection to Platform
// Here related resources and properties are loaded to device service objects
await deviceService.ConnectToPlatformAsync([enrolmentResult.DeviceId]);
deviceService.UseSensorValueChangeRequestHandler(x => {
//You can ack or nack a message
x.Ack();
//x.Nack();
console.log(`Value comes from device: ${x.DeviceId}, sensor: ${x.SensorId}, from topic: ${x.Topic}, which Created at: ${x.CreationTime}, with value ${JSON.stringify(x.Message)}`);
});
// It sends the request to platform to save sensor data. Note that: this methot is a fire and forget type method, this means there will be no response
deviceService.PushAndForgetSensorActualDataToPlatformAsync({
DeviceId: enrolmentResult.DeviceResourceId,
SensorId: sensorResult.SensorId,
CreationTime: new Date(),
DataUnit: "Celcius",
ExtractedData: "25"
});
// It sends the request to platform to save sensor data as a command, like changing sensor's value. We can handle this request at above, in UseSensorValueChangeRequestHandler event.
await deviceService.PushAndForgetSensorDesiredDataToPlatformAsync({
DeviceId: enrolmentResult.DeviceResourceId,
SensorId: sensorResult.SensorId,
CreationTime: new Date(),
DataUnit: "Celcius",
ExtractedData: "27"
}).catch((a) => console.log(a.message));
//Normaly with PushSensorDesiredDataToPlatformAsync method we send request
//and when platform handles request, it sends a response
//But with PushSensorDesiredDataAndWaitAckAsync method we wait ack or nack from
//a sdk. When a sdk handles a message with UseSensorValueChangeRequestHandler
//please use Ack or Nack method for returning response, otherwise waiting part throws timeout error
var serviceResult = await service.PushSensorDesiredDataAndWaitAckAsync({
DeviceId: enrolmentResult.DeviceResourceId,
SensorId: sensorResult.SensorId,
CreationTime: new Date(),
DataUnit: "Celcius",
ExtractedData: "25"
});
let battery = new sdk.Service.Contracts.DeviceManagement.DeviceBatteryCreateRequest();
battery.DeviceId = enrolmentResult.DeviceId;
battery.BatteryLevel = 10;
battery.BatteryStatus = sdk.OneM2M.Constants.Management.BatteryStatus.LowBattery
battery.Name = "DeviceBattery";
let batteryBackup = new sdk.Service.Contracts.DeviceManagement.DeviceBatteryCreateRequest();
batteryBackup.DeviceId = enrolmentResult.DeviceId;
batteryBackup.BatteryLevel = 100;
batteryBackup.BatteryStatus = sdk.OneM2M.Constants.Management.BatteryStatus.Normal;
batteryBackup.Name = "DeviceSecondBattery";
// Device Management Service Connection to Platform
// Here related resources and properties are loaded to device management service object
await deviceManagementService.ConnectToPlatformAsync([enrolmentResult.DeviceId]);
let batteryResult = await deviceManagementService.CreateBatteryAsync(battery);
let batteryBackupResult = await deviceManagementService.CreateBatteryAsync(batteryBackup);
let batteries = await deviceManagementService.GetBatteriesAsync(enrolmentResult.DeviceId);
console.log(batteryResult);
console.log(batteryBackupResult);
console.log(batteries);
})();
Service SDK Functionalities
In this field, you can see Service SDK functionalities for Node.js and methods in detail below to be able to create your application.
1. Enrollment Functionalities
You have to be enrolled to the system as customer. Then, you will have ClientId that is created for applications that are allowed to access the platform. You can enroll your device to the system by using ClientId. For detail you can see EnrollDevice method below.
GetEmptyDeviceId Method
You can retrieve a empty deiceId for enrollment operation.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.EnrollmentServiceFactory.CreateEnrollmentService(options);
let deviceIdResult = await service.GetAvailableDeviceId();
})();
Response Structure
class AvaibleDeviceIdResult
{
IsSuccess: boolean;
Messages: Array<string>;
DeviceId: string;
}
Enroll Device Method
You can enroll your device to the system by deviceName**.**
| Field | Data type | Description | | --- | --- | --- | | DeviceName | string | Mandatory. The name of the device. | | DeviceId | string | Mandatory. The given CAE Id of the device. | | Attributes | Map<string, string> | Optional. The user defined attributes of the device. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.EnrollmentServiceFactory.CreateEnrollmentService(options);
let attributes = new Map();
attributes.set("TestKey","TestValue");
await service.EnrollDeviceAsync({
DeviceName: "test-device-1",
DeviceId: "CAE---1",
Attributes: attributes
}).catch(reason => { console.log(reason) });
})();
Response Structure
class DeviceEnrollmentResult
{
IsSuccess: boolean;
Messages: Array<string>;
DeviceResourceId: string;
DeviceId: string;
DeviceName: string;
}
Related Error Codes
- 10001 Parameters are invalid!
- 10002 Device name is already in use||Device is already enrolled!
- 10003, 10004, 10005 Enrollment cannot be completed!
- 10006 Device cannot be enrolled! Operation not allowed!
Disenroll Device Method
You can disenroll your device to the system by DeviceDisenrollmentRequest**.**
| Field | Data type | Description | | --- | --- | --- | | DeviceResourceId | string | Mandatory. resource Id which returns when enroll. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.EnrollmentServiceFactory.CreateEnrollmentService(options);
await service.DisenrollDeviceAsync({
DeviceResourceId: "DeviceResourceId---1",
}).catch(reason => { console.log(reason) });
})();
Response Structure
class DeviceDisenrollmentResult
{
IsSuccess: boolean;
Messages: Array<string>;
DeviceResourceId: string;
DeviceId: string;
DeviceName: string;
}
Multiple Device Functionality
Platform360 Service SDK allows you to enroll or disenroll more than one device to the system by multiple device functionality and manage them. You can see following example for detail.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.EnrollmentServiceFactory.CreateEnrollmentService(options);
//Create list of devices which going to be enroll
var bulklist = [
{ DeviceName: "test-device-1", DeviceId: "CAE---1" },
{ DeviceName: "test-device-2", DeviceId: "CAE---2" }
];
// Returns list of PromiseSettledResult; this means all requests are handled but there can be some rejections.
// With that, rejections can be handled.
await service.EnrollDeviceBulkAsync(bulklist)
.catch(reason => { console.log(reason) });
//Create list of devices which going to be disenroll
var bulklist = [
{ DeviceResourceId: "DeviceResourceId---1" },
{ DeviceResourceId: "DeviceResourceId---2" }
];
// Returns list of PromiseSettledResult; this means all requests are handled but there can be some rejections.
// With that, rejections can be handled.
await service.DisenrollDeviceBulkAsync(bulklist)
.catch(reason => { console.log(reason) });
})();
2. Device Functionalities
In this field, you can see device functionalities supported by Platform360 Service SDK. You need to enroll your device to the system by EnrollDevice method before using device functionalities. For more detail, you can see methods below.
Connect to Platform Method
ConnectToPlatform method is required for getting bidirectional sensor's messages. Normally after creation of a bidirectional sensor, sdk starts to listen notifications automatically. But when you want to listen devices (note that you need to attach a event handles for handle messages) which created before or you restart the your application; "UseSensorValueChangeRequestHandler"is not enough.
Further, ConnectToPlatform method must be called once when the connection is down because of any reason. When the device is connected to platform again, you can continue the flow.
You can use ConnectToPlatform for listen notifications for a device or devices anytime, anywhere.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
// Device Service Connection to Platform
// Here related resources and properties for given CAE ıds are loaded to device service objects
let result = await service.ConnectToPlatformAsync(["CAE---1", "CAE---2"]);
})();
Response Structure
class DeviceInitializationResponse
{
IsSuccess: boolean;
Messages: string[];
DeviceId: string;
DeviceResourceId: string;
DeviceName: string;
Sensors: Array<SimpleSensorDto>;
}
class SimpleSensorDto
{
SensorResourceId: string;
DeviceResourceId: string;
SensorName: string;
IsBiDirectional: boolean;
}
Related Error Codes
- 11003, 12003 Device not found!
- 12001, 12002 Device cannot be initialized!
GetAllDevices Method
You can retrieve all registered devices with GetAllDevices method
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
var serviceResult = await service.GetAllDevices()
.catch((reason) => { console.log(reason) });
})();
Response Structure
class GetDevicesResult
{
IsSuccess: boolean;
Messages: string[];
Devices: Array<DeviceDto>;
}
class DeviceDto
{
DeviceId: string;
ResourceId: string;
Name: string;
NodeResourceId: string;
PoA: Array<string>;
}
GetDevicesByLabel Method
You can filter devices with GetDevicesByLabel method. This method takes a Label and multiple values for tihs label and searches registered devices with given values.
| Field | Data type | Description | | --- | --- | --- | | request | GetDevicesByLabelRequest | Mandatory. request object | | --- | --- | --- | | Labels | Object[] | Mandatory. Labels for the search. | | --- | --- | --- | | Key |string | Mandatory. Label Name. | | Values |string[] | Mandatory. Label Values. |
Request Structure
class GetDevicesByLabelRequest
{
Labels: [{
Key: string;
Values: Array<string>;
}];
}
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
var serviceResult = await service.GetDevicesByLabel({Labels : [
{ Key: "name", Values: ["test"]}
]})
.catch((reason) => { console.log(reason) });
})();
Response Structure
class GetDevicesResult
{
IsSuccess: boolean;
Messages: string[];
Devices: Array<DeviceDto>;
}
class DeviceDto
{
DeviceId: string;
ResourceId: string;
Name: string;
NodeResourceId: string;
PoA: Array<string>;
}
Create Sensor Method
You can create any sensor if the device is enrolled to the system and connected to the platform.
You need name and is bidirectional parameters to create sensor.
isBiDirectional parameter is used to manage sensor remotely. If the sensor is bidirectional, you can intervene your sensor.
If the sensor is not bidirectional, you can just read sensor value and send it to platform.
| Field | Data type | Description | | --- | --- | --- | | name | string | Mandatory. The name of the sensor. | | --- | --- | --- | | isBiDirectional | boolean | Mandatory. Must be set to "true" or "false" depending on whether the sensor is able to receive the notification. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
await service.CreateSensorAsync({
DeviceResourceId: "DeviceResourceId---1",
IsBidirectional: true,
SensorName: "BidirectionalSensor---1"
}, { GetPoA = () => "http://example.com/api/postme" });
})();
Response Structure
class SensorCreationResult
{
IsSuccess: boolean;
Messages: Array<string>;
SensorId: string;
Name: string;
}
Related Error Codes
- 12011, 12012, 12013 Sensor cannot be created!
- 12014 Sensor cannot be created! Sensor name already exists!
Sensor Notification Event Handler Method
If the sensor is bidirectional, when you change sensor value on your remote application, SensorNotificationEventHandler method handles this command on device side.
If the sensor is not bidirectional, you do not need to use this method.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
// Device Service Connection to Platform
// Here related resources and properties are loaded to device service objects
await service.ConnectToPlatformAsync(["CAE---1", "CAE---2"]);
service.UseSensorValueChangeRequestHandler(x => {
console.log(`Value comes from device: ${x.DeviceId}, sensor: ${x.SensorId}, from topic: ${x.Topic}, which Created at: ${x.CreationTime}, with value ${JSON.stringify(x.Message)}`);
});
})();
Push Sensor Data to Platform Method
This method is used to keep sensor data in the platform. There are four methods for sending data to platform.
- PushSensorActualDataToPlatformAsync: Used for sending sensor's actual data. Waits for acknowledge.
- PushSensorDesiredDataToPlatformAsync: Used for setting sensor data as desired. Waits for acknowledge. Can handle with "Sensor Notification Event Handler Method"
- PushAndForgetSensorActualDataToPlatformAsync: Used for sending sensor's actual data.
- PushAndForgetSensorDesiredDataToPlatformAsync: Used for setting sensor data as desired. Can handle with "Sensor Notification Event Handler Method"
Note that; if you use "Desired" methods for a sensor which is not a bidirectional, you get a error.
In addition to sensorId and data parameters, the unit of the sent data (e.g. if the sensor measures temperature, it sends the unit parameter that it is measured in celcius.) and the digital data of sensor are sent by extractedData parameter.
Ex: data: 25 celcius degree,
unit: celcius,
extractedData: 25
| Field | Data type | Description | | --- | --- | --- | | sensorId | string | Mandatory. The sensor identifier. | | --- | --- | --- | | data | string | Mandatory. Raw data of the sensor. | | unit | string | Mandatory. The unit of the data. | | extractedData | string | Mandatory. The extracted data of the sensor. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
var serviceResult = await service.PushSensorActualDataToPlatformAsync({
SensorId: "SensorId---1",
CreationTime: new Date(),
DataUnit: "Celcius",
ExtractedData: "27",
RawData: "27 Celcius"
});
})();
Push Sensor Data to Platform and Wait for Acknowledge Method
This method is used to send data to platform and waits for acknowledge from sensor's listeners (other sdk users or 3rd parties).
- PushSensorActualDataAndWaitAckAsync: Used for sending sensor's actual data. Waits for acknowledge.
- PushSensorDesiredDataAndWaitAckAsync: Used for setting sensor data as desired. Waits for acknowledge. Can handle with "Sensor Notification Event Handler Method". This handler method's notification object contains additional data like sensorId etc and 2 parameterless methods; Ack and Nack. Use those methods for accepting messages. Otherwise waiting part throws timeout error.
Note that; if you use "Desired" methods for a sensor which is not a bidirectional, you get a error.
In addition to sensorId and data parameters, the unit of the sent data (e.g. if the sensor measures temperature, it sends the unit parameter that it is measured in celcius.) and the digital data of sensor are sent by extractedData parameter.
Ex: data: 25 celcius degree,
unit: celcius,
extractedData: 25
| Field | Data type | Description | | --- | --- | --- | | sensorId | string | Mandatory. The sensor identifier. | | --- | --- | --- | | data | string | Mandatory. Raw data of the sensor. | | unit | string | Mandatory. The unit of the data. | | extractedData | string | Mandatory. The extracted data of the sensor. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
service.UseSensorValueChangeRequestHandler(x => {
//You can ack or nack a message
x.Ack();
//x.Nack();
console.log(`Value comes from device: ${x.DeviceId}, sensor: ${x.SensorId}, from topic: ${x.Topic}, which Created at: ${x.CreationTime}, with value ${JSON.stringify(x.Message)}`);
});
var serviceResult = await service.PushSensorDesiredDataAndWaitAckAsync({
SensorId: "SensorId---1",
CreationTime: new Date(),
DataUnit: "Celcius",
ExtractedData: "27",
RawData: "27 Celcius"
});
})();
Delete Sensor Method
You can delete related sensor by its sensorId.
| Field | Data type | Description | | --- | --- | --- | | sensorId | string | Mandatory. The sensor identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
var serviceResult = await service.DeleteSensorAsync("SensorId---1").catch(reason => { console.log(reason)});
})();
Response Structure
export class SensorDeletionResult
{
public SensorId: string;
public Name: string;
}
Related Error Codes
- 12021, 12022, 12023, 12024 Sensor cannot be deleted!
Get Sensor By Name Method
You can retrieve sensors by their name.
| Field | Data type | Description | | --- | --- | --- | | deviceResourceId | string | Mandatory. The device identifier. | | sensorNames | list | Mandatory. Exact Name of Sensors. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceServiceFactory.CreateDeviceService(options);
let sensors = await deviceService.GetSensorsByName(
"DeviceResourceId---1",
["BidirectionalSensor---1"]
)
.catch(reason => { console.log(reason) });
Response Structure
export class SensorRetrieveResult
{
IsSuccess: boolean;
Messages: Array<string>;
Sensors : Array<SensorDto>;
}
3. Device Management Functionalities
In this section, you can find functionalities of device management objects. You can see informations about device management objects.
Please look for details about related methods below.
- Battery Related Methods
- Memory Related Methods
- Physical Device Info Related Methods
- Area Network Info Related Methods
- Area Network Device Info Related Methods
- Reboot Related Methods
- Firmware Related Methods
Battery Related Methods
The [battery] resource is used to share information regarding the battery. In this field, you can see examples of battery creation, battery retrieve, battery update and battery deletion.
Create Battery Method
You can create the device battery by using following parameters.
| Field | Data type | Description | Default Value and Constraints | | --- | --- | --- | --- | | name | string | Mandatory. The name of the battery. | | batteryStatus | enum | Mandatory. The status of the battery. | Range: 0-100Unit: percent | | batteryLevel | int | Mandatory. The current battery level. |
Table 1 : Interpretation of batteryStatus
| Value | Interpretation | Note | | --- | --- | --- | | 1 | NORMAL | The battery is operating normally and not on power. | | 2 | CHARGING | The battery is currently charging. | | 3 | CHARGING_COMPLETE | The battery is fully charged and still on power. | | 4 | DAMAGED | The battery has some problem. | | 5 | LOW_BATTERY | The battery is low on charge. | | 6 | NOT_INSTALLED | The battery is not installed. | | 7 | UNKNOWN | The battery information is not available. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.CreateBatteryAsync({
DeviceId: "CAE---1",
BatteryLevel: 10,
BatteryStatus: sdk.OneM2M.Constants.Management.BatteryStatus.Normal,
Name: "TestBattery"
}).catch(reason => console.log(reason));
})();
Response Structure
export class DeviceBatteryResult
{
BatteryId: string;
Name: string;
BatteryLevel?: number;
BatteryStatus?: BatteryStatus;
}
Related Error Codes
- 11211, 11212, 11213, 11214 Battery cannot be created!
Retrieve Battery Method
You can retrieve batteries for a device.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.GetBatteriesAsync(deviceId).catch(reason => console.log(reason));
})();
Related Error Codes
- 11231, 11232, 11233, 11234 Batteries cannot be retrieved!
Update Battery Method
You can update related device battery by its batteryId.
| Field | Data type | Description | | --- | --- | --- | | batteryId | string | Mandatory. The battery identifier. | | --- | --- | --- | | batteryStatus | enum | Optional. The status of the battery. | | batteryLevel | int | Optional. The current battery level. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let batteryId "batteryId---1";
var serviceResult = await service.UpdateBatteryAsync({
DeviceId : deviceId,
BatteryId : batteryId,
BatteryLevel : 6,
BatteryStatus : sdk.OneM2M.Constants.Management.BatteryStatus.Charging
})
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11221, 11222, 11223, 11224 Battery cannot be updated!
Delete Battery Method
You can delete related battery by its batteryId.
| Field | Data type | Description | | --- | --- | --- | | batteryId | string | Mandatory. The battery identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let batteryId "batteryId---1";
var serviceResult = await service.DeleteBatteryAsync(batteryId, deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11201, 11202, 11203, 11204 Battery cannot be deleted!
Memory Related Methods
The [memory] resource is used to share information regarding the memory on the device. In this field, you can see examples of memory creation, memory retrieve, memory update and memory deletion.
Create Memory Method
You can create device memory by using following parameters.
| Field | Data type | Description | Default Value and Constraints | | --- | --- | --- | --- | | name | string | Mandatory. The name of the memory. | | totalMemory | long | Mandatory. The total amount of memory. | Unit: byte | | availableMemory | long | Mandatory. The current available amount of memory. | Unit: byte |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.CreateMemoryAsync({
DeviceId: deviceId,
AvailableMemory: 10,
TotalMemory: 32,
Name: "TestMemory"
}).catch(reason => console.log(reason));
})();
Response Structure
export class DeviceMemoryResult
{
MemoryId: string;
Name: string;
TotalMemory?: number;
AvailableMemory?: number;
}
Related Error Codes
- 11311, 11312, 11313, 11314 Memory cannot be created!
Retrieve Memory Method
You can retrieve memories for a device.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.GetMemoriesAsync(deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11331, 11332, 11333, 11334 Memories cannot be retrieved!
Update Memory Method
You can update related memory by its memoryId.
| Field | Data type | Description | | --- | --- | --- | | memoryId | string | Mandatory. The memory identifier. | | totalMemory | long | Optional. The total memory of the device. | | availableMemory | long | Optional. The available memory of the device. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let memoryId = "MemoryId---1&";
var serviceResult = await service.UpdateMemoryAsync({
DeviceId: deviceId,
MemoryId : memoryId,
AvailableMemory : 15,
TotalMemory: 32
})
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11321, 11322, 11323, 11324 Memory cannot be updated!
Delete Memory Method
You can delete related memory by its memoryId.
| Field | Data type | Description | | --- | --- | --- | | memoryId | string | Mandatory. The memory identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let memoryId = "MemoryId---1";
var serviceResult = await service.DeleteMemoryAsync(memoryId, deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11301, 11302, 11303, 11304 Memory cannot be deleted!
Physical Device Info Related Methods
The [deviceInfo] resource is used to share information regarding the device. In this field, you can see examples of physical device info creation, physical device info retrieve, physical device info update and physical device info deletion.
Create Physical Device Info Method
You can create device info by using following parameters.
| Field | Data type | Description | | --- | --- | --- | | name | string | Mandatory. The name of device info. | | deviceLabel | string | Mandatory. Unique device label assigned by the manufacturer. | | manufacturer | string | Mandatory. The name/identifier of the device manufacturer. | | model | string | Mandatory. The name/identifier of the device model assigned by the manufacturer. | | deviceType | string | Mandatory. The type (e.g. cell phone, photo frame, smart meter) or product class (e.g. X-series) of the device. | | deviceGeneralInfoId | string | Mandatory. The device general info identifier. | | firmwareVersion | string | Optional. The firmware version of the device. | | softwareVersion | string | Optional. The software version of the device. | | hardwareVersion | string | Optional. The hardware version of the device. | | manufacturerDetailsLink | string | Optional. URL to manufacturer's website. | | manufacturingDate | string | Optional. Manufacturing date of device. | | subModel | string | Optional. Device sub-model name. | | deviceName | string | Optional. Device name. | | osVersion | string | Optional. Version of the operating system (defined by manufacturer). | | country | string | Optional. Country code of the device. It could be manufacturing country, deployment country or procurement country. | | location | string | Optional. Location where the device is installed. It may be configured via the user interface provided by the 'presentationURL' property or any other means. | | systemTime | string | Optional. Reference time for the device. | | supportURL | list | Optional. URL that points to product support information of the device. | | presentationURL | list | Optional. To quote UPnP: "the control point can retrieve a page from this URL, load the page into a web browser, and depending on the capabilities of the page, allow a user to control the device and/or view device status. The degree to which each of these can be accomplished depends on the specific capabilities of the presentation page and device". | | protocol | list | Optional. A list of MIME types for all supported communication protocol(s) of the device. Example: application/x-alljoin; version=1.0 application/x-echonet-lite; version=1.0 indicates the device supports both AllJoyn v1.0 and Echonet Lite v1.0. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.CreatePhysicalDeviceInfoAsync({
DeviceId: deviceId,
Country: "TR",
DeviceLabel: "DeviceInfoLabel",
DeviceName: "ServiceSDKDevice",
DeviceType: "Edge Computer",
FirmwareVersion: "1.0.0a",
HardwareVersion: "1.0.0b",
Location: "Koc Digital Arge",
Manufacturer: "Manufacturer A",
ManufacturerDetailsLink: "nolink",
ManufacturingDate: moment().utc(),
Model: "SPx-B101",
Name: "KocDigital_Ortam_izleme",
OsVersion: "1.0.1c",
PresentationURL: ["test1", "test2"],
Protocol: ["MQTT", "HTTP"],
SoftwareVersion: "1.0.0d",
SubModel: "Ortam izleme",
SupportURL: ["support", "support2"],
SystemTime: moment().utc()
}).catch(reason => console.log(reason));
})();
Response Structure
export class DevicePhysicalDeviceInfoResult
{
PhysicalDeviceInfoId: string;
Name: string;
DeviceLabel: string;
Manufacturer: string;
Model: string;
DeviceType: string;
FirmwareVersion: string;
SoftwareVersion: string;
HardwareVersion: string;
ManufacturerDetailsLink: string;
ManufacturingDate: string;
SubModel: string;
DeviceName: string;
OsVersion: string;
Country: string;
Location: string;
SystemTime: string;
SupportURL: string[];
PresentationURL: string[];
Protocol: string[];
}
Related Error Codes
- 11411, 11412, 11413, 11414 PhysicalDeviceInfo cannot be created!
Retrieve Physical Device Info Method
You can retrieve the device info without giving any parameter.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.GetPhysicalDeviceInfoAsync(deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11431, 11432, 11433, 11434 PhysicalDeviceInfo cannot be retrieved!
Update Physical Device Info Method
You can update related device info by its deviceGeneralInfoId.
| Field | Data type | Description | | --- | --- | --- | | deviceGeneralInfoId | string | Mandatory. The device general info identifier. | | deviceLabel | string | Optional. Unique device label assigned by the manufacturer. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
const moment = require("moment");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let physicalDeviceInfoId = "DeviceInfoId---1";
var serviceResult = await service.UpdatePhysicalDeviceInfoAsync({
PhysicalDeviceInfoId: physicalDeviceInfoId,
DeviceId: deviceId,
DeviceLabel: "DeviceInfoLabel_Updated",
DeviceName: "ServiceSDKDevice_Updated",
DeviceType: "Edge Computer_Updated",
FirmwareVersion: "1.0.0a_Updated",
Location: "Koc Digital Arge_Updated",
ManufacturerDetailsLink: "nolink_Updated",
OsVersion: "1.0.1c_Updated",
PresentationURL: ["test1_Updated", "test2_Updated"],
Protocol: ["MQTT_Updated", "HTTP_Updated"],
SoftwareVersion: "1.0.0d_Updated",
SupportURL: ["support_Updated", "support2_Updated"],
SystemTime: moment().utc()
}).catch(reason => console.log(reason));
})();
Related Error Codes
- 11421, 11422, 11423, 11424 PhysicalDeviceInfo cannot be updated!
Delete Physical Device Info Method
You can delete related device info by its physicalDeviceInfoId.
| Field | Data type | Description | | --- | --- | --- | | physicalDeviceInfoId | string | Mandatory. The device general info identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
const moment = require("moment");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let physicalDeviceInfoId = "DeviceInfoId---1";
var serviceResult = await service.DeletePhysicalDeviceInfoAsync(physicalDeviceInfoId, deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11401, 11402, 11403, 11404 PhysicalDeviceInfo cannot be deleted!
Area Network Info Related Methods
In this field, you can see examples of area network info creation, area network info retrieve, area network info update and area network info deletion.
Create Area Network Info Method
You can create area network info by using following parameters.
| Field | Data type | Description | | --- | --- | --- | | name | string | Mandatory. The name of area network info. | | areaNetworkType | string | Mandatory. It is an implementation-chosen string that indicates the type of M2M Area Network. | | listOfDevices | list | Mandatory. The list of devices in the M2M Area Network. The attribute contains references to [areaNwkDeviceInfo] resource. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.CreateAreaNetworkInfoAsync({
DeviceId: deviceId,
AreaNetworkType: "AreNetworkType1",
ListOfDevices: ["Device1", "Device2"],
Name: "TestAreaNetworkInfo"
}).catch(reason => console.log(reason));
})();
Response Structure
export class AreaNetworkInfoResult
{
AreaNetworkInfoId: string;
Name: string;
AreaNetworkType: string;
ListOfDevices: string[];
}
Related Error Codes
- 11511, 11512, 11513, 11514 AreaNetworkInfo cannot be created!
Retrieve Area Network Info Method
You can retrieve area network info without giving any parameter.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.GetAreaNetworkInfoAsync(deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11531, 11532, 11533, 11534 AreaNetworkInfo cannot be retrieved!
Update Area Network Info Method
You can update area network info by using following parameters.
| Field | Data type | Description | | --- | --- | --- | | areaNetworkType | string | Optional. It is an implementation-chosen string that indicates the type of M2M Area Network. | | listOfDevices | list | Optional. The list of devices in the M2M Area Network. The attribute contains references to [areaNwkDeviceInfo] resource. | | areaNetworkInfoId | string | Optional. The area network info identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let areaNetworkInfoId = "AreaNetworkInfoId---1";
var serviceResult = await service.UpdateAreaNetworkInfoAsync({
DeviceId: deviceId,
AreaNetworkType: "AreNetworkType1\_Update",
ListOfDevices: ["Device1\_Update", "Device2\_Update"],
AreaNetworkInfoId: areaNetworkInfoId
}).catch(reason => console.log(reason));
})();
Related Error Codes
- 11521, 11522, 11523, 11524 AreaNetworkInfo cannot be updated!
Delete Area Network Info Method
You can delete area network info by its areaNetworkInfoId.
| Field | Data type | Description | | --- | --- | --- | | areaNetworkInfoId | string | Mandatory. The area network info identifier. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let areaNetworkInfoId = "AreaNetworkInfoId---1";
var serviceResult = await service.DeleteAreaNetworkInfoAsync(areaNetworkInfoId, deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11501, 11502, 11503, 11504 AreaNetworkInfo cannot be deleted!
Area Network Device Info Related Methods
In this field, you can see examples of area network device info creation, area network device info retrieve, area network device info update and area network device info deletion.
Create Area Network Device Info Method
First, you must create Area Network Info to create Area Network Device Info. Then, you will have " AreaNetworkInfoId"to use it to createArea Network Device Info.
You can create area network device info by using following parameters.
| Field | Data type | Description | | --- | --- | --- | | name | string | Mandatory. The name of area network device info. | | devId | string | Mandatory. The id of the device. | | devType | string | Mandatory. The type of the device. It indicates the functions or services that are provided by the device. Examples include temperature sensor, actuator, Zigbee coordinator or Zigbee router. | | areaNetworkId | string | Mandatory. The reference to an areaNwkInfo resource which this device associates with. | | listOfNeighbors | list | Mandatory. The neighbour devices of the same area network. When modified, the connection relationship of the devices shall be modified accordingly. | | devStatus | string | Optional. The status of the device (sleeping or waked up). | | sleepDuration | int | Optional. The time duration of each sleep. | | sleepInterval | int | Optional. The interval between two sleeps. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
let areaNetworkInfoId = "AreaNetworkInfoId---1";
var serviceResult = await service.CreateAreaNetworkDeviceInfoAsync({
DeviceId: deviceId,
AreaNetworkId: areNetworkInfoId,
DevID: "DeviceId",
DevStatus: "DeviceStatus",
DevType: "DeviceType",
ListOfNeighbors: ["1", "2"],
SleepDuration: 20,
SleepInterval: 200,
Name: "TestAreaNetworkDeviceInfo"
}).catch(reason => console.log(reason));
})();
Response Structure
export class AreaNetworkDeviceInfoResult
{
AreaNetworkDeviceInfoId: string;
Name: string;
DevID: string;
DevType: string;
DevStatus: string;
AreaNetworkId: string;
SleepInterval?: number;
SleepDuration?: number;
ListOfNeighbors: string[];
}
Related Error Codes
- 11611, 11612, 11613, 11614 AreaNetworkDeviceInfo cannot be created!
Retrieve Area Network Device Info Method
You can retrieve area network device info without giving any parameter.
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#MqttPassword")
.Build();
let service = sdk.Factories.DeviceManagementServiceFactory.CreateDeviceManagementService(options);
let deviceId = "CAE---1";
await service.ConnectToPlatformAsync(deviceId);
var serviceResult = await service.GetAreaNetworkDeviceInfoAsync(deviceId)
.catch(reason => console.log(reason));
})();
Related Error Codes
- 11631, 11632, 11633, 11634 AreaNetworkDeviceInfo cannot be retrieved!
Update Area Network Device Info Method
You can update area network device info by using following parameters.
| Field | Data type | Description | | --- | --- | --- | | areaNetworkDeviceInfoId | string | Mandatory. The area network device info identifier. | | devId | string | Optional. The id of the device. | | devType | string | Optional. The type of the device. It indicates the functions or services that are provided by the device. Examples include temperature sensor, actuator, Zigbee coordinator or Zigbee router. | | areaNetworkId | string | Optional. The reference to an areaNwkInfo resource which this device associates with. | | listOfNeighbors | list | Optional. The neighbour devices of the same area network. When modified, the connection relationship of the devices shall be modified accordingly. |
Node.js Example
var sdk = require("kocdigital-platform360-service-sdk-nodejs");
(async () => {
let options = new sdk.MqttClient.MqttClientOptionsBuilder()
.WithClientId("#CSEId")
.WithCSEId("#ClientId")
.WithOptions("#MqttPointOfAccess", #MqttPort, new TimeSpan(#TimeOut), "#MqttUserName", "#Mqt