Difference between revisions of "M2M Bridge"

From AMTech WikiDocs
Jump to: navigation, search
Line 5: Line 5:
 
# [[How to implement a new plugin]]
 
# [[How to implement a new plugin]]
 
# [[How to install]]
 
# [[How to install]]
 
+
# [[HelloWorld plugin]]
== HelloWorld plugin ==
+
=== Create thing type HelloWorld ===
+
*add supported property type string hwgreetingLabel (See [[Activities#Thing types|Thing types]])
+
**string without space validation regexp ^[^\s]+$
+
*add supported property type integer hwSayHelloFrequency
+
 
+
=== Create observation type obsrvHelloWorld ===
+
*add supported property type string hwgreetingLabel (See [[Sensor's network#Observations and observation types|Observations and observation types]])
+
*clone obsrvHelloWorld with name commandHelloWorld
+
 
+
=== Define observation types produce or consume by the Thing ===
+
*add obsrvHelloWorldobservation to Observation Production configuration list (See [[Activities#Thing types|Thing types]])
+
*add commandHelloWorldobservation to Observation Production configuration list
+
*add observationresourcecrud to Observation Production configuration list
+
 
+
=== Implement plugin HelloWorld interface ===
+
*create a directory with the thing type name HelloWorld at (See [https://github.com/AMTechMX/M2MBridge/tree/master/plugins plugin directory] )
+
*at the directory HelloWorld create a javascript file HelloWorld.js
+
*implement the interface (See [[M2MBridge# How to implement a new plugin| How to implement a new plugin]])
+
<syntaxhighlight lang="javascript">
+
    function HelloWorld() {
+
    }
+
 
+
    HelloWorld.prototype.start = function (complete) {
+
        try {
+
            complete(null);
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    HelloWorld.prototype.stop = function (complete) {
+
        try {
+
            complete(null);
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    HelloWorld.prototype.command = function (observation, complete) {
+
        try {
+
            complete(null);
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    module.exports.HelloWorld = HelloWorld;
+
</syntaxhighlight>
+
 
+
=== Functionality ===
+
*send an observation obsrvHelloWorldobservation with the frequency set by the property hwSayHelloFrequency
+
*change hwgreetingLabel value when receive command obsrvHelloWorld observation
+
*implement placeholder #{greetingLabel}
+
*start method
+
**create an observation type obsrvHelloWorld at /amtech/things/observations (See [[Simulator|Simulator]])
+
**copy observation instance jsonld
+
<syntaxhighlight lang="javascript">
+
    var clone = require('clone');
+
    var util = require('util');
+
 
+
    function HelloWorld() {
+
    }
+
 
+
    HelloWorld.prototype.start = function (complete) {
+
        var self = this;
+
        try {       
+
            self.sayHelloInterval = setInterval(function(){
+
                var obsrvHelloWorld = clone({
+
                    "proximityarea": "",
+
                    "topic": "",
+
                    "guestusers": [],
+
                    "targetthings": "[]",
+
                    "location": "",
+
                    "@type": "/amtech/linkeddata/types/composite/observation/obsrvHelloWorld",
+
                    "hwgreetingLabel": "",
+
                    "creationDate": "2016-04-20T03:24:54.099Z",
+
                    "guesttenants": [],
+
                    "description": "",
+
                    "producer": ""
+
                });
+
                obsrvHelloWorld.hwgreetingLabel = self.hwgreetingLabel;
+
                var ph = {'greetingLabel': self.hwgreetingLabel};
+
                self.sendObservation(self,obsrvHelloWorld, ph );           
+
            }, self.hwSayHelloFrequency);
+
            complete(null);
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    HelloWorld.prototype.stop = function (complete) {
+
        try {
+
            if (this.sayHelloInterval) {
+
                clearInterval(this.sayHelloInterval);
+
            }
+
            complete(null);
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    HelloWorld.prototype.command = function (observation, complete) {
+
        try {
+
            if(observation['@type'] === "/amtech/linkeddata/types/composite/observation/commandHelloWorld"){
+
                this.hwgreetingLabel = observation.hwgreetingLabel;
+
                complete(null);
+
            }else{
+
                complete(new Error(util.format("HelloWorld %s support commands of observations type commandHelloWorld", this._name)));
+
            }
+
        } catch (e) {
+
            complete(e);
+
        }
+
    };
+
 
+
    module.exports.HelloWorld = HelloWorld;
+
</syntaxhighlight>
+
 
+
=== Configure amtechM2MBridge template ===
+
*(See [[M2M Bridge#Cloud Configuration|Cloud Configuration]])
+
*create activity helloWorld (See [[Activities|Activities]])
+
*create helloWord notification (See [[Notifications|Notifications]])
+
**add subject with placeholder #{label}
+
**add subject with placeholder #{producer} and #{label}
+
*create helloWorld actor with access polices (See [[Access control#Actors|Actors]])
+
**amtechM2MBridge thing type
+
**HelloWord thing type
+
**helloWord notification
+
**associate helloWorld actor with helloWorld activity
+
*configure observation production (See [[Activities#Observation production configuration|Observation production configuration]])
+
** thing type HelloWorld
+
***observation type obsrvHelloWorld
+
****topic /helloWorld/#{greetingLabel}
+
****producer #{thingId}
+
****guestTeants add m2mcreator to shared the observation
+
***observation type observationresourcecrud
+
****topic /helloWorld/asynch
+
****producer #{thingId}
+
** thing type amtechM2mBridge
+
***observation type observationresourcecrud
+
****topic /helloWorld/asynch
+
****producer #{thingId}
+
*create observation simulation for observation type obsrvHelloWorld (to be used in observers)
+
*create helloWorld observer (See [[Observers|Observers]])
+
**type observation obsrvHelloWorld
+
**test observer
+
*create helloWorld reazoner (See [[Reasoners|Reasoners]])
+
**add action send notification type helloWorld
+
**add action send command
+
**test and validate reasoner
+
*publishing activity (See [[Publishing|Publishing]])
+
**validate activity
+
**deploy activity
+
*invite a user as helloWorld actor (See [[Access control#Actors|Invite user]])
+
**user id smartsensor@amtech.mx
+
*configure helloWorld m2mBridge template
+
** create amtechM2MBridge instance with name helloWorld (See [[IoT Semantics|Instances]])
+
***it will be the value of templateId at bridgeConfig.json (See [[M2M Bridge#Edge Configuration|Edge Configuration]])
+
**create HelloWorld type instace with name helloWorld
+
**associate HelloWorld instance to amtechM2MBridge instance
+
**give guest access to helloWorld M2MBridge instance to tenant m2mfollower and user smartsensor@amtech.mx
+
*add new action send Command to reasoner helloWorld
+
**thing type HelloWorld
+
**observation type commandHelloWorld
+
**set topic to /helloWorld/asynch
+
**set target uri to observation producer (See [[Sensor's network#Observations and observation types|targetthings]])
+
**set hwgreetingLabel holaFromCommand
+
 
+
=== bridgeConfig.json ===
+
*(See [[M2M Bridge#Edge Configuration|Edge Configuration]])
+
<syntaxhighlight lang="jsonld">
+
    {
+
        "description": "AMTech M2M Bridge Helloworld demo",
+
        "description:children" : true,
+
        "dap":{
+
            "dapUrl": "https://dapdev.amtech.mx",
+
            "userId": "smartsensor@amtech.mx",
+
            "tenant" : "m2mfollower",
+
            "password" :"xxxxxxxx"
+
        },
+
        "templateId":"helloWorld",
+
        "bridgeIdPrefix":"helloWorldDemo",
+
        "location:children" : true,
+
        "address" :{
+
            "country" : "USA",
+
            "city": "New York City",
+
            "road" : "97th street transverse"
+
        }   
+
    }
+
</syntaxhighlight>
+
 
+
=== Debug a plugin ===
+
*node-inspector &
+
**[https://greenido.wordpress.com/2013/08/27/debug-nodejs-like-a-pro/ Debug NodeJS Like A Pro]
+
**[https://mattdesl.svbtle.com/debugging-nodejs-in-chrome-devtools Debugging Node.js in Chrome DevTools]
+
*visit http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858
+
  
 
== Example plugins (See [https://github.com/AMTechMX/M2MBridge/tree/master/plugins exiting plugins])==
 
== Example plugins (See [https://github.com/AMTechMX/M2MBridge/tree/master/plugins exiting plugins])==

Revision as of 19:17, 23 April 2016

  1. Functionality
  2. Edge Configuration
  3. Cloud Configuration
  4. Implementation notes
  5. How to implement a new plugin
  6. How to install
  7. HelloWorld plugin

Example plugins (See exiting plugins)

LLRPReader

Bridge EPC Low Level reader protocol to IoT DAP (See LLRPReader) and /amtech/linkeddata/types/composite/entity/LLRPReader

  • Edge Intelligence
    • Implementing smoothing for new and lost tag
    • EPC decoding
    • Groups tags read by antennas groups
    • Groups tags by EPC decoding.
  • Placeholders (See Placeholders)
    • #{antennaId} Llrp protocol antenna Id set at antennas supported property
    • #{smoothingResult} if smoothing has been set to true LLRP reader observations can be sent to a topic depending of the smoothing process result [new|lost]
    • #{llrpReaderProximity} Set the llrp reader proximity area supported property value to targetThing proximity value field
    • #{antennaProximity} Set the llrp antenna proximity area supported property value to targetThing proximity value field
    • #{tagEncoding} EPC encoding name
    • A component of decoded epc tag; helpful to organize epc observations; for example company-prefix to inform companies about products arrival or set access control.
   #{epcUri|companyPrefix|itemReference|serialNumber|
   serialReference|locationReference|extension|assetType|
   individualAssetReference|serviceReference|documentType|
   managerNumber|objectClass|cAGEOrDODAAC}
  • Produced observations (see /amtech/linkeddata/types/composite/observation)
    • /amtech/linkeddata/types/composite/observation/observationresourcecrud
    • /amtech/linkeddata/types/composite/observation/graiEPC
    • /amtech/linkeddata/types/composite/observation/graiEPC
    • /amtech/linkeddata/types/composite/observation/decode96EPC
    • /amtech/linkeddata/types/composite/observation/sgtinEPC
    • /amtech/linkeddata/types/composite/observation/dodEPC
    • /amtech/linkeddata/types/composite/observation/giaiEPC
    • /amtech/linkeddata/types/composite/observation/ssccEPC
    • /amtech/linkeddata/types/composite/observation/gdtiEPC
    • /amtech/linkeddata/types/composite/observation/llrpError
    • /amtech/linkeddata/types/composite/observation/dataEPC
    • /amtech/linkeddata/types/composite/observation/encoded96EPC
    • /amtech/linkeddata/types/composite/observation/gidEPC
  • Commands (see /amtech/linkeddata/types/composite/observation)
    • /amtech/linkeddata/types/composite/observation/gpoWriteDataEPC

BLEbeaconsScanner

Bridge bluetooth low energy apple's ibecon and google's eddystone protocols to IoT DAP (See BLEbeaconsScanner) and /amtech/linkeddata/types/composite/entity/BLEbeaconsScanner

  • Edge Intelligence
    • Implementing smoothing for new, broadcast and lost tag
  • Placeholders (See Placeholders)
    • #{smoothingResult} if smoothing has been set to true EddystoneScan observations can be sent to a topic depending of the smoothing process result [new|lost|broadcast]
    • #{eddystoneType} Eddystone frame types, permissible values are uid, url and tlm
      • uid broadcasts an opaque, unique 16-byte Beacon ID composed of a 10-byte namespace and a 6-byte instance.
      • url broadcasts a URL using a compressed encoding format in order to fit more within the limited advertisement packet.
      • tlm telemetrics
    • #{eddystoneNamespace} 10-byte ID Namespace
    • #{eddystoneInstance} 6-byte ID Instance
    • #{proximityarea} Set the EddystoneHub proximity area supported property value to targetThing proximity value field
    • #{bleProtocol} [eddystone|ibeacon]
    • #{ibeaconUuid'} iBeacon advertised uuid
    • #{'ibeaconMajor'} iBeacon advertised major
    • #{'ibeaconMinor'} iBeacon advertised minor
    • #{'ibeaconProximity} current proximity from sacanner [unknown|immediate|near|far]
  • Produced observations (see /amtech/linkeddata/types/composite/observation)
    • /amtech/linkeddata/types/composite/observation/observationresourcecrud
    • /amtech/linkeddata/types/composite/observation/ibeaconScan
    • /amtech/linkeddata/types/composite/observation/eddystoneBrodcast
    • /amtech/linkeddata/types/composite/observation/eddystoneScan
    • /amtech/linkeddata/types/composite/observation/eddystoneScan

SNMPDevice

Bridge simple network management protocol to IoT DAP (See SNMPDevice) and /amtech/linkeddata/types/composite/entity/SNMPDevice

  • Edge Intelligence
    • Groups multiple snmp reads and writes in a single call
    • Maps snmp oid into human readable names
  • Produced observations (see /amtech/linkeddata/types/composite/observation)
    • /amtech/linkeddata/types/composite/observation/observationresourcecrud
    • /amtech/linkeddata/types/composite/observation/snmpError
    • /amtech/linkeddata/types/composite/observation/snmpTrap
  • Commands (see /amtech/linkeddata/types/composite/observation)
    • /amtech/linkeddata/types/composite/observation/snmpSet