@jj11909/ewonjs

1.5.2 • Public • Published

ewonjs Interface Library

The eWON JS library provides direct and proxied access to your eWON devices
via both stateful and stateless sessions.

A few things you can do with this library:

  • Access account information
  • Access device information
  • Retrieve live tag data from your devices
  • Retrieve historical data directly from your eWON
    • Relative time
    • Absolute time
  • Execute BASIC scripts directly on your eWON

Getting Started

Add ewonjs to your library by running:

    npm install --save jj11909/ewonjs

Initializing a client

This library supports both stateful and stateless API sessions.

Creating a session

var ewon = require('@jj11909/ewonjs');

var client = new ewon.EwonClient(account, username, password, developerid);

After creating a client, if you would like to create a stateful session
you must first login to the API.

Login to account

/*
Sample Response:
Valid - 
    {t2msession: 'sessionid', success: true}

Invalid - 
    { message: 'Invalid credentials', code: 403, success: false }
*/
client.login().then((response) => {
    if(response.success) {
        // Login was valid
    }
})

Creating a STATEFUL session

After logging into the account you can now create a stateful session. This will negate the need to use your username and password the entire duration of the session. This will also give you login/logout capabilities.

client.login().then((response) => {
    if(response.success) {
        //Important Line
        client.updateSession(response.t2msession)
    }
})



Terminating a session

You can end a session at any time by simply calling logout.

client.logout();



Retrieving Account Information

To access account information (company info, account type, pools, etc)
call to account. A JSON Object of your account information will be returned.

client.account().then((response) => {
    //Handle response
})



Retrieve Account Devices

Retrieve all eWONs in your account including their LAN properties. Request returns a JSON array of devices

client.getDevices().then((response) => {
    for(var ewon in response.ewons) {
        console.log(ewon.name)
    }
})



Retrieving a Single Device

To retrieve a single device you must pass the name of the desired device to the getDevice request.

var mydevicename = "myewon";
client.getDevice(mydevicename).then((response) => {
    console.log(response);
})



Interfacing Directly with Device

In order to interface directly with the device, you must instantiate an
eWON object.

Required Parameters:

  • Device name
  • Talk2M Client
  • Device Username
  • Device Password
var ewon = new ewon.Ewon(devicename, client, deviceusername, devicepassword);



Retrieving Live Tag Data

By interfacing directly with the eWON we are able to retrieve
live tag data from your systems.In order to simplify usage, the
semi-colon delimited data will automatically be converted to a JSON array
for you.

ewon.getLiveTags().then((response) => {
    for(var tag in response) {
        console.log(response[tag].tagvalue)
    }
})



Update Tag Data

You also have the ability to update your tag data. The updateTags option
will accept either a single tag (JSON Object) or a JSONArray of tags.

var tags = [
    {"tagname": "tagname", "tagvalue": 0},
    {"tagname": "othertagname", "tagvalue": 20}
]

ewon.updateTags(tags);

// OR

var tag = {"tagname" : "mytag", "tagvalue" : 100}
ewon.updateTags(tag)



Historical Data

If you are not using the Data Mailbox, you still have access to the historical data
stored on your unit. You can request the relative historical endpoint to retrieve
the historical data relative to a timeframe.

NOTE: This is read directly from the eWON and can easily result in increased data costs
and can take a while to parse. It is recommended to use the Data Mailbox for your historical
data.

var interval = 10; 
/*
  This requests takes in 4 parameters. 
  A start interval and unit (seconds, hours, minutes, days)
  An end interval and unit
*/
ewon.getHistoricalRelative(interval, ewon.relative_units.hours, 0, ewon.relative_units.seconds).then((response) => {
    /*
        By default, the data is exported from the eWON in a CSV (semicolon) however in 
        order to make it easier to use, ewonjs will convert this data to a JSON array. 
    */
})



Execute BASIC Script

Executing a basic script can be done using one of two formats. Either a simple array or a JSONArray of objects can be used here.

var script = [
    'Print "This is line one"',
    'x = .23 * 6',
    'PRINT STR$ x'
]

// OR

var script = [
    {'command': 'PRINT "This is line one"'},
    {'command': 'x = .23 * 6'},
    {'command': 'PRINT STR$ x'}
]

ewon.runBasicScript(script).then((response) => {
    if(response.success) {
        // Winner!
    }
})



Generic Export

The eWON devices support dozens of exports. It is not
possible, with my limited bandwidth, to support each and
and every function with a custom call. This can be used as
a catch-all for each export.

See: Export Block Descriptor Builder

var eventLogs = '$dtEV$ftT';

ewon.genericExport(eventLogs).then((response) => {
    // handle response
})

Package Sidebar

Install

npm i @jj11909/ewonjs

Weekly Downloads

0

Version

1.5.2

License

ISC

Unpacked Size

16.9 kB

Total Files

4

Last publish

Collaborators

  • jj11909