Difference between revisions of "AgentLite-Node.js"

From ESS-WIKI
Jump to: navigation, search
Line 156: Line 156:
 
|}
 
|}
 
</div>
 
</div>
 
 
== AdvDataMgt ==
 
== AdvDataMgt ==
  
Line 201: Line 200:
 
<span style="font-size:large;">Template Code: ./module/plugin_temp.js</span>
 
<span style="font-size:large;">Template Code: ./module/plugin_temp.js</span>
  
== Plugin with&nbsp;AdvDataMgt ==
+
== Plugin with&nbsp;AdvDataMgt ==
  
 
<span style="font-size:large;">Sample Code: ./module/Simple-plugin_test.js</span>
 
<span style="font-size:large;">Sample Code: ./module/Simple-plugin_test.js</span>
Line 210: Line 209:
  
 
gitlab [http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense/AgentLite-Node.js http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense/AgentLite-Node.js]
 
gitlab [http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense/AgentLite-Node.js http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense/AgentLite-Node.js]
 +
 +
[[Category:Editor]]

Revision as of 18:55, 18 December 2018

Introduction

 AgentLite-Node.js is a light weight south-bound agent in Node.js. There are 3 main components of "1. Net-Protocol ( ./lib/WISECore3.3.js)", 2. main program ( AgentLite3.3.js) and 3. plugin module ( ./module/plugin_temp.js). Develop need to develop a plugin.js.

AgentLite-Node.js

Configure

./config/agent_config.json    : in JSON Format

<code>{         
  "ServerIP":"127.0.0.1",    
  "ServerPort": 1883,    
  "DeviceName": "SNMP_Handler",    
  "DevType": "Service",    
  "version": "v1.0.1"
}</code>

Plugin

   A plugin.js with common interfaces. A main program can load a plugin to send and control its sensor data.

Define and Callback functions

global variable Description
g_strPluginName
Name of plugin
g_jsCapability
Capability of this plugin
g_sendcbf reply action function point
g_sendreportcbf auto report function point
g_sendcapabilitycbf send capability function point
g_sendeventcbf send event message function point
g_sendreplytopiccbf send update data by reply action topic ( Monitor page ) function point


Internal Function

Developer needs to implement these functions.

var InitPlugin()

  • Description: To initialize process of your plugin.

var UnInitPlugin()

  • Description: ​To uninitialize process of your plugin. 

var AutoReport()

  • Description: ​system will call this "AutoReport"  after trigging auto report. To send auto report data by "g_sendreportcbf".

var getSenseData( iCmd, strSessionid, jsRequest )

  • Description: ​To receive a get control command and call this function to query sensor data in capability cach.

var StartMonitorData(iCmd, strSessionid, jsMsg )

  • Description: ​To receive a get monitor command and register a timer envet to call "MonitorUpdate" function.

var MonitorStop( )

  • Description: ​To stop a timer event of Monitor sensor data.

var MonitorUpdate()

  • Description: ​To upload sensor data by g_sendreplytopiccbf

Export Interfaces of Plugin

Developers generally do not need to modify

var Handler_Initialize( param )

  • Description: ​Main program calls "Handler_Initialize" to initialize this module.           


Parameter Description
param.sendcbf reply action function point
param.sendreportcbf auto report function point
param.sendcapabilitycbf send capability function point
param.sendeventcbf send event message function point
param.sendreplytopiccbf send update data by reply action topic ( Monitor page ) function point

var Handler_Uninitialize( )

  • Description: ​Main program calls "Handler_Uninitialize" to uninitialize this module.     

void Handler_AutoReportStart( interval )

  • Description: ​Main program calls the "Handler_AutoReportStart" to start auto report.    
Parameter Description
interval report interval in second

var Handler_AutoReportStop()

  • Description: ​Main program calls "'Handler_AutoReportStop'" to stop auto report.    

var Handler_Get_Capability()

  • Description: ​Main program calls "'Handler_AutoReportStop'" to get plugin's capability.

var Handler_Recv( strTopic, strMsg )

  • Description: ​Main program calls "'Handler_Recv'" if receive a control message from others.
Parameter Description
strTopic received mqtt topic 
strMsg received message

AdvDataMgt

 It is a librarie help that makes it easy to compose plugin's capability in the Advantech IPSO-like JSON format.

int initialize ( strName, jInfo )

  • Description: To initialize the AdvDataMgt.

var getCapability ()

  • Description: Get capability.​

int addSensor( strPath, jsSensor, strKey )

  • Description: To add a sensor data by path.

int updatebyPath( strPath, value )

  • Description: To update value by path

int updatebyKey( strKey, value )

  • Description: To update value by key

var queryKeybyPath( strPath )

  • Description: To query key by path

var getAllKey()  

  • Description: To get all keys

var getAllPath()

  • Description: To get all paths

How To - Sample Code

Plugin

Sample Code: ./module/plugin_test.js

Template Code: ./module/plugin_temp.js

Plugin with AdvDataMgt

Sample Code: ./module/Simple-plugin_test.js

Template Code: ./module/Simple-plugin_temp.js

Release

gitlab http://advgitlab.eastasia.cloudapp.azure.com/EdgeSense/AgentLite-Node.js