npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

edimax-smartplug

v0.0.24

Published

Node module to communicate with Edimax Smart Plugs

Downloads

29

Readme

edimax-smartplug

Greenkeeper badge Build Status

Node module to communicate with Edimax Smart Plugs. The library utilizes Bluebird promises - https://github.com/petkaantonov/bluebird. Device requests will be executed sequentially. This is useful as the Smart Plug REST service does not properly chain incoming requests. It provides the following features:

  • Device Discovery - Smart Plugs can be automatically discovered on a given network (see section "Device Discovery" below for details)
  • Switching - Apart from switching Smart Plugs on and off, it is possible to read the current switch state
  • Schedule - It is not possible to set the schedule for the Smart Plugs, but the current schedule is readable
  • Usage Metering - For 'SP2101W' Smart Plugs it is possible to access the current, accumulated, and historical energy usage metering data
  • Support for digest authentication required with firmware versions SP-2101W v2.08 and SP-1101W v2.04

| Important Notice | |------------------| The recent firmware versions published for EdiSmart/Amazon Alexa Integration are currently not supported by edimax-smartplug:

  • SP2101W: v2.09 and higher
  • SP1101W: v1.05 and higher

Moreover, please note, the SP-2101W V2 plug is currently not supported. Issue #14 contains a link thread with untested and unsupported downgrade instructions. Use at your own risk!

If you have installed the new version and wish to downgrade you can use the downgrade guide provided as part of the project.

Usage Examples

var smartplug = require('./index');
var options = {
    timeout: 10000,
    name:'edimax',
    host:'192.168.178.65',
    username: 'admin',
    password: '1234'
};


smartplug.getDeviceInfo(options).then(function (info) {
    console.log(info);
}).catch(function(e) {console.log("Request failed: ", e)});

smartplug.getSchedule(options).then(function (schedule) {
    console.log(schedule);
}).catch(function(e) {console.log("Request failed: ", e)});

// set switch ON
smartplug.setSwitchState(true, options).catch(function(e) {console.log("Request failed: ", e)});

smartplug.getSwitchPower(options).then(function (power) {
    console.log("Current switch power", power, "Watts");
}).catch(function(e) {console.log("Request failed: ", e)});

smartplug.getSwitchEnergy(options).then(function (energy) {
    console.log("getSwitchEnergy result:", energy);
}).catch(function(e) {console.log("Request failed: ", e)});

smartplug.getStatusValues(true, options).then(function (all) {
    console.log("getStatusValues result:", all);
}).catch(function(e) {console.log("Request failed: ", e)});

// set switch OFF
smartplug.setSwitchState(false, options).catch(function(e) {console.log("Request failed: ", e)});

// get switch status
smartplug.getSwitchState(options).then(function (state) {
    console.log("Switch status is", state?"ON":"OFF");
}).catch(function(e) {console.log("Request failed: ", e)});

// get schedule status
smartplug.getScheduleState(options).then(function (state) {
    console.log("Schedule status is", state?"ON":"OFF");
}).catch(function(e) {console.log("Request failed: ", e)});

// get the daily history of power measured consumption for the given date range
smartplug.getHistory('DAY', '20160825', '20160830', options).then(function (results) {
    console.log("getHistory result", results);
}).catch(function(e) {console.log("Request failed: ", e)});

// discover devices
smartplug.discoverDevices({
    timeout: 3000,
    address: "192.168.178.255"
}).then(function (results) {
    console.log("Discovery Result:", results);
}).catch(function(e) {console.log("Request failed: ", e)});

Device Discovery

The device discovery implementation is based on the findings summarized in a blog post (thanks, Guntram). As the discovery mechanism may also be used for other Edimax products, e.g. IP cameras, you should filter by model name to make sure the found device is a smart plug ('SP1101W' and 'SP2101W'). The method discoverDevices() accepts the following options:

| Property | Default | Type | Description | |:----------|:------------------|:--------|:--------------------------------------------| | address | "255.255.255.255" | String | The broadcast address | | timeout | 3000 | Integer | The timeout in milliseconds for discovery |

Note: Using the global broadcast address on Windows may yield unexpected results. On Windows, global broadcast packets will only be routed via the first network adapter which may cause problems with multi-homed setups and virtual network adapters. If you want to use a broadcast address though, use a network-specific address, e.g. for 192.168.0.1/24 use 192.168.0.255.

A discovery request returns a promise which yields an array with the discovery items on completion. An item is an object with the following properties:

| Property | Type | Example | Description | |:--------------|:--------|:-----------------|:-------------------------------| | manufacturer | String | 'EDIMAX' | The manufacturer of the device | | model | String | 'SP2101W' | The model name | | version | String | '2.03' | The firmware version | | displayName | String | 'edimax' | The assigned device name | | addr | String | '192.168.178.65' | The IP address of the device | | dstAddr | String | '192.168.178.1' | The IP address of the gateway |

TODO

  • More Documentation
  • Make request chaining optional. In some cases, request/response interleaving does not matter
  • Add tests

History

See Release History.

License

Copyright (c) 2015-2019, Marcus Wittig and contributors. All rights reserved.

MIT License