Talk2M API NodeJS

Description

Talk2M offers many APIs to interface with your eWON devices. In an effort to simplify the API integration with many websites, I have written a Node.js library that comes with quite a few functions to interface with the hardware.

DISCLAIMER: This is not an HMS software and is not supported by HMS. For questions or issues, please open an issue on Github.

See the fulll writeup at: https://www.npmjs.com/package/@jj11909/ewonjs



ewonjs Interface Library

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);

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

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



Terminating a session

client.logout();



Retrieving Account Information

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



Retrieve Account Devices

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



Retrieving a Single Device

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


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



Update Tag Data

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

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. 
    */
})


TODO:

  • Add script functionality
  • Add Data Mailbox Functionality
1 Like