Difference between revisions of "Device-Node.js SDK"

From ESS-WIKI
Jump to: navigation, search
 
(14 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
== Pre-Requirement ==
 
== Pre-Requirement ==
  
*MQTT Broker ( [[MQTT_Broker|Download]] ) : Please install the MQTT Broker on target platform.
+
*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.
 
*[https://nodejs.org/en/ Node.js] >= 5.x: Please install above 5.x Nodejs on target platform.
  
 
= How To =
 
= How To =
  
== Demo  1, 2, 3 ==
+
== How To Run - SamplePlugin  Setp: 1 -> 2 -> 3 ==
 
<pre>1. == Download ==
 
<pre>1. == Download ==
$git clone git@advgitlab.eastasia.cloudapp.azure.com:EdgeSense-Open/device-template-node.js.git sdk-sample
+
$git clone git@gitlab.edgecenter.io:edgesense-open/device-template-node.js.git sdk-sample
$cd <project name>
+
$cd sdk-sample
  
 
2. == Install packages ==
 
2. == Install packages ==
Line 21: Line 21:
  
 
3. == Run ==
 
3. == Run ==
$node index.js</pre>
+
$node plugin_index.js</pre>
  
 
== 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
&nbsp; - ServiceType: <xxx> Category of application
+
  - ServiceType: <xxx> Category of application
&nbsp; - Description: A brief description  
+
  - 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
+
&nbsp; &nbsp; 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
  
[http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense-Open/advlog-node.js http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense-Open/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&nbsp;: 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 '''Simple-plugin_temp.js''' by your applicaton name
+
#Rename the '''[https://gitlab.edgecenter.io/edgesense-open/device-template-node.js/-/blob/master/module/pluginClassTemp.js pluginClassTemp.js]&nbsp;''' by your applicaton name
#Chang the plugin path in '''config/agent_config.json :&nbsp;''''''<span style="color:#0000FF;">plugin</span>'''
+
#Chang the plugin path in index_plugin.js'''&nbsp;:&nbsp;'''var&nbsp;agentplugin&nbsp;=&nbsp;require('./module/pluginClassTest.js');
#<span style="color:#0000FF;">'''InitPlugin'''</span>: InitPlugin&nbsp; => Refer &lt; InitTest &gt; in '''Simple-plugin_test.js'''
+
#<span style="color:#0000FF;">'''InitPlugin'''</span>: InitPlugin&nbsp; => Refer &lt; InitTest &gt; in '''pluginClassTest.js'''
#<span style="color:#0000FF;">'''AutoReport'''</span>: start auto report interval callback function; Implement to call send data in this=> Refer &lt; AutoUpdateTest &gt; in&nbsp;&nbsp;Simple-plugin_test.js
+
#<span style="color:#0000FF;">'''AutoReport'''</span>: start auto report callback function by interval; To implement send data in this function=> Refer &lt; AutoUpdateTest &gt; in&nbsp;&nbsp;Simple-plugin_test.js
#<span style="color:#0000FF;">'''setSenseData'''</span>: DeviceOn server or others 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.
+
#<span style="color:#0000FF;">'''setSenseData'''</span>: DeviceOn server or other apps&nbsp;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.
#<span style="color:#0000FF;">'''sendEventTest'''</span>: You can refer to "sendEventTest" to trigger a event alarm to local MQTT Broker and transfer to DeviceOn server.
+
#<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.
 +
 
 +
= Note =
 +
 
 +
*If the plugin needs to send&nbsp;OPTS to DeviceOn, OPTS can not be assigned to 0 in plugin's&nbsp;capability. OPTS must&nbsp;set timestamps according to your application.

Latest revision as of 04:36, 5 February 2021

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

  1. Rename the pluginClassTemp.js  by your applicaton name
  2. Chang the plugin path in index_plugin.js : var agentplugin = require('./module/pluginClassTest.js');
  3. InitPlugin: InitPlugin  => Refer < InitTest > in pluginClassTest.js
  4. AutoReport: start auto report callback function by interval; To implement send data in this function=> Refer < AutoUpdateTest > in  Simple-plugin_test.js
  5. 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.
  6. 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.