New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

m2x

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m2x

AT&T M2X API client for node.js

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

Node.js M2X API Client

The AT&T M2X API provides all the needed operations to connect your device to AT&T's M2X service. This client provides an easy to use interface for node.js.

Installation

m2x-nodejs is available as an npm package. Install the latest version with:

npm install m2x

Getting Started

  1. Signup for an M2X Account.
  2. Obtain your Master Key from the Master Keys tab of your Account Settings screen.
  3. Create your first Data Source Blueprint and copy its Feed ID.
  4. Review the M2X API Documentation.

Please consult the M2X glossary if you have questions about any M2X specific terms.

Example Usage

In order to be able to use this client you will need an AT&T M2X API key and a Data Source ID. If you don't have an API key, create an account and, once registered and with your account activated, create a new Data Source Blueprint, and copy the Feed ID and API Key values. The following script will send your CPU load average to three different streams named load_1m, load_5m and load_15. Check that there's no need to create a stream in order to write values into it:

#!/usr/bin/env node

//
// See https://github.com/attm2x/m2x-nodejs/blob/master/README.md#example-usage
// for instructions
//

var M2X = require("../lib/m2x");
var exec = require("child_process").exec;

var API_KEY = "<YOUR-FEED-API-KEY>";
var FEED    = "<YOUR-FEED-ID>";

// Match `uptime` load averages output for both Linux and OSX
var UPTIME_RE = new RegExp("(\\d+\\.\\d+),? (\\d+\\.\\d+),? (\\d+\\.\\d+)$", "m");


function UptimeDataSource() {
    this.m2xClient = new M2X(API_KEY);

    // Create the streams if they don't exist
    this.loadAvg(function(load_1m, load_5m, load_15m) {
        this.m2xClient.feeds.updateStream(FEED, "load_1m", { value: load_1m });
        this.m2xClient.feeds.updateStream(FEED, "load_5m", { value: load_5m });
        this.m2xClient.feeds.updateStream(FEED, "load_15m", { value: load_15m });
    });

    this.updateInterval = setInterval(this.update.bind(this), 1000);
};

UptimeDataSource.prototype.loadAvg = function(cb) {
    var self = this;

    exec("uptime", function(error, stdout, stderr) {
        var match = stdout.match(UPTIME_RE);

        if (match) {
            cb.call(self, match[1], match[2], match[3]);
        }
    });
};

UptimeDataSource.prototype.update = function() {
    this.loadAvg(function(load_1m, load_5m, load_15m) {
        // Write the different values into AT&T M2X
        var values = {
            load_1m:  [ { value: load_1m } ],
            load_5m:  [ { value: load_5m } ],
            load_15m: [ { value: load_15m } ]
        };

        this.m2xClient.feeds.postMultiple(FEED, values, function(data, error, res) {
            if (res.statusCode !== 204) {
                // abort if something went wrong
                clearInterval(this.updateInterval);
            }
        }.bind(this));
    });
};

var instance = new UptimeDataSource();

You can find the script in examples/m2x-uptime.js.

License

This gem is delivered under the MIT license. See LICENSE for the terms.

Acknowledgements

This client is a direct port of Leandro Lopez' AT&T M2X client for Ruby so all the credit should go to him.

Keywords

FAQs

Package last updated on 14 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc