Difference between revisions of "Device-Node.js SDK"
From ESS-WIKI
Eric.liang (talk | contribs) |
Eric.liang (talk | contribs) |
||
(24 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
= Device-Node.js SDK = | = Device-Node.js SDK = | ||
− | == Requirement == | + | == Pre-Requirement == |
− | *MQTT | + | *MQTT Broker ( [[MQTT_Broker|Download]] ) : Please install the MQTT Broker on target platform. |
− | *[ | + | *[https://nodejs.org/en/ Node.js] >= 5.x: Please install above 5.x Nodejs on target platform. |
− | |||
+ | = How To = | ||
+ | == How To Run - SamplePlugin Setp: 1 -> 2 -> 3 == | ||
+ | <pre>1. == Download == | ||
+ | $git clone git@gitlab.edgecenter.io:edgesense-open/device-template-node.js.git sdk-sample | ||
+ | $cd sdk-sample | ||
− | = | + | 2. == Install packages == |
+ | $npm install | ||
− | == | + | 3. == Run == |
− | + | $node plugin_index.js</pre> | |
− | |||
− | |||
− | |||
− | |||
− | $node | ||
== Development == | == Development == | ||
Line 27: | Line 27: | ||
=== config === | === config === | ||
− | agent_config.json | + | ==== agent_config.json ==== |
<pre> - DeivceNam: <XXX> Name of application | <pre> - DeivceNam: <XXX> Name of application | ||
+ | - ServiceType: <xxx> Category of application | ||
+ | - Description: A brief description | ||
- version: version of application | - version: version of application | ||
- plugin: path of main entry program => ./module/<xxx>.js | - plugin: path of main entry program => ./module/<xxx>.js | ||
</pre> | </pre> | ||
− | log.json | + | Example: iAlarm |
+ | <pre lang="json">{ | ||
+ | |||
+ | "DeviceName": "<code>OPCUAClient</code>", | ||
+ | "ServiceType": "<code>Protocol-Converter</code>", | ||
+ | "Description": "<code>OPC-UA Client to access OPC-UA Server node</code>", | ||
+ | "version": "v2.0.2", | ||
+ | <code>"plugin": "/module/opcua-client-plugin.js"</code> | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | ==== log.json ==== | ||
confinuration of advlog-node.js | confinuration of advlog-node.js | ||
− | [ | + | [https://gitlab.edgecenter.io/edgesense-open/advlog-node.js https://gitlab.edgecenter.io/edgesense-open/advlog-node.js] |
+ | |||
+ | static: log file | ||
+ | |||
+ | *level: debug level | ||
+ | *information: log format | ||
+ | *path: log folder | ||
+ | *duration: how long to create a new log file ( default : 1 Hr 3600000 ms, Max: 1 day ) | ||
+ | *buffer: how long to write to file ( default: 1 sec, 1000 ms, Max: 1 min ) | ||
+ | *files: Max log file | ||
+ | |||
+ | dynamic: print to console | ||
+ | |||
+ | *level: debug level | ||
+ | *information: log format | ||
+ | *trace: enable(1)/disable(0) consloe trace | ||
+ | |||
+ | '''Debug Level''' | ||
+ | <pre>0: NONE | ||
+ | 2: ERROR - consloe.error | ||
+ | 3: WARN - console.warn | ||
+ | 5: INFO - consloe.log ( Default ) | ||
+ | 7: DEBUG - consloe.debug | ||
+ | 8: TRACE - consloe.trace</pre> | ||
=== Plugin === | === Plugin === | ||
− | #Rename the ''' | + | #Rename the '''[https://gitlab.edgecenter.io/edgesense-open/device-template-node.js/-/blob/master/module/pluginClassTemp.js pluginClassTemp.js] ''' by your applicaton name |
− | #Chang the plugin path in | + | #Chang the plugin path in index_plugin.js''' : '''var agentplugin = require('./module/pluginClassTest.js'); |
− | + | #<span style="color:#0000FF;">'''InitPlugin'''</span>: InitPlugin => Refer < InitTest > in '''pluginClassTest.js''' | |
− | + | #<span style="color:#0000FF;">'''AutoReport'''</span>: start auto report callback function by interval; To implement send data in this function=> Refer < AutoUpdateTest > in Simple-plugin_test.js | |
− | #'''InitPlugin''': InitPlugin => Refer < InitTest > in | + | #<span style="color:#0000FF;">'''setSenseData'''</span>: DeviceOn server or other apps to set sensor value to the service. This callback function will be called and you need to implement a set function with your application at this. |
− | #'''AutoReport''': start auto report | + | #<span style="color:#0000FF;">'''sendEvent'''</span>: You can refer to "sendEventTest" in pluginClassTest.js to trigger an event alarm to the local MQTT Broker and transfer to DeviceOn server. |
− | #'''setSenseData''': DeviceOn server or | + | |
− | #''' | + | = Note = |
+ | |||
+ | *If the plugin needs to send OPTS to DeviceOn, OPTS can not be assigned to 0 in plugin's capability. OPTS must set timestamps according to your application. |
Latest revision as of 04:36, 5 February 2021
Contents
Introduction
This is a EdgeSense southbound device service SDK in node.js. User can use this SDK to easy to develop your application to integrate with EdgeSense Core System.
Device-Node.js SDK
Pre-Requirement
- MQTT Broker ( Download ) : Please install the MQTT Broker on target platform.
- Node.js >= 5.x: Please install above 5.x Nodejs on target platform.
How To
How To Run - SamplePlugin Setp: 1 -> 2 -> 3
1. == Download == $git clone git@gitlab.edgecenter.io:edgesense-open/device-template-node.js.git sdk-sample $cd sdk-sample 2. == Install packages == $npm install 3. == Run == $node plugin_index.js
Development
config
agent_config.json
- DeivceNam: <XXX> Name of application - ServiceType: <xxx> Category of application - Description: A brief description - version: version of application - plugin: path of main entry program => ./module/<xxx>.js
Example: iAlarm
{
"DeviceName": "<code>OPCUAClient</code>",
"ServiceType": "<code>Protocol-Converter</code>",
"Description": "<code>OPC-UA Client to access OPC-UA Server node</code>",
"version": "v2.0.2",
<code>"plugin": "/module/opcua-client-plugin.js"</code>
}
log.json
confinuration of advlog-node.js
https://gitlab.edgecenter.io/edgesense-open/advlog-node.js
static: log file
- level: debug level
- information: log format
- path: log folder
- duration: how long to create a new log file ( default : 1 Hr 3600000 ms, Max: 1 day )
- buffer: how long to write to file ( default: 1 sec, 1000 ms, Max: 1 min )
- files: Max log file
dynamic: print to console
- level: debug level
- information: log format
- trace: enable(1)/disable(0) consloe trace
Debug Level
0: NONE 2: ERROR - consloe.error 3: WARN - console.warn 5: INFO - consloe.log ( Default ) 7: DEBUG - consloe.debug 8: TRACE - consloe.trace
Plugin
- Rename the pluginClassTemp.js by your applicaton name
- Chang the plugin path in index_plugin.js : var agentplugin = require('./module/pluginClassTest.js');
- InitPlugin: InitPlugin => Refer < InitTest > in pluginClassTest.js
- AutoReport: start auto report callback function by interval; To implement send data in this function=> Refer < AutoUpdateTest > in Simple-plugin_test.js
- setSenseData: DeviceOn server or other apps to set sensor value to the service. This callback function will be called and you need to implement a set function with your application at this.
- sendEvent: You can refer to "sendEventTest" in pluginClassTest.js to trigger an event alarm to the local MQTT Broker and transfer to DeviceOn server.
Note
- If the plugin needs to send OPTS to DeviceOn, OPTS can not be assigned to 0 in plugin's capability. OPTS must set timestamps according to your application.