GithubHelp home page GithubHelp logo

mwittig / edimax-smartplug Goto Github PK

View Code? Open in Web Editor NEW
29.0 6.0 11.0 70 KB

Unofficial Edimax Smartplug Libary. Control SP-1101W and SP-2101W from Node.js.

License: MIT License

JavaScript 100.00%
smartplug edimax smarthome energy-consumption energy-monitor edimax-smartplug schedule

edimax-smartplug's Introduction

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

edimax-smartplug's People

Contributors

domir avatar greenkeeper[bot] avatar mattjgalloway avatar mplessing avatar mwittig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

edimax-smartplug's Issues

No way to authenticate with v2.09?

I have accidentally upgraded my SP-2101W to firmware v2.09. I don't seem to be able to connect to it anymore. Has the digest authentication disappeared for it?

All available CMD payloads

Firstly, all XML must contain the SMARTPLUG tag with attribute id = edimax or there will be an "XML Header error". These are the possible tags for CMD tag with attribute id = get.

  • SSID_LIST => SSID_DATA contains fields SSID, BSSID, CHANNEL, SIGNAL, MODE, ENCRYPTION, AUTHENTICATION
  • INTERNET => (online status, checks against one of yahoo, ibm or google)
  • SYSTEM_INFO (mail, smtp pass, timezone, ntp servers, daylight, system name)
  • SCHEDULE
  • TEST_MAIL
  • Device.System.Time => contains %Y%m%d%H%M%S
  • Device.System.Power.State
  • Device.System.Power.NextToggle
  • NOW_POWER (elecc get_now)
  • POWER_USAGE
  • POWER_HISTORY
  • some flag check for overcurrent output
  • some flag check for overpower output

A small teaser for you - all configurable variables and their defaults

As of 2.08 FW

EDMX
"Device.System.RemoteManagement.Enable=ON",
"Device.WAN.Mode=DHCP",
"Device.LAN.2G.CTS=Auto",
"Device.WAN.Static.MTU=1454",
"Device.System.RemoteManagement.IPAddress=",
"Device.System.TimeZone.City=Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London",
"Device.System.Power.Budget.Week.Notify=OFF",
"Device.System.SMTP.0.Mail.Action.Notify.Enable=OFF",
"Device.System.FwUpgrade.Enable=ON",
"Device.Firewall.Enable=OFF",
"Device.System.Power.Budget.Month.UpperLimit=0",
"Device.WAN.IPV6.Enable=ON",
"Device.System.TimeZone.Daylight.Enable=OFF",
"Device.LAN.2G.NFixRate=Auto",
"Device.System.Password.Name=admin",
"Device.WAN.DHCPClient.MTU=1454",
"Device.LAN.2G.NChannelWidth=20",
"Device.System.FwUpgrade.Notification.Enable=ON",
"Device.LAN.NetMask=255.255.255.0",
"Device.LAN.2G.0.Security.WPAPSK.Key=11111111",
"Device.WAN.Static.DNS1=",
"Device.Configuration.HW.ModelName=SP2101W",
"Device.WAN.Static.DNS2=",
"Device.LAN.2G.0.MACAC.Num=0",
"Device.System.Push.Enable=ON",
"Device.System.Power.Budget.Day.UpperLimit=0",
"Device.LAN.2G.APMode=AccessPoint",
"Device.NAT.UPNP.Enable=ON",
"Device.System.Power.Budget.Week.Push=OFF",
"Device.System.TimeZone.Server.Address.0=pool.ntp.org",
"Device.LAN.2G.WPS.ConfigType=Configured",
"Device.System.TimeZone.Server.Address.1=europe.pool.ntp.org",
"Device.System.TimeZone.Server.Address.2=oceania.pool.ntp.org",
"Device.System.TimeZone.Server.Address.3=north-america.pool.ntp.org",
"Device.System.TimeZone.Server.Address.4=south-america.pool.ntp.org",
"Device.System.Power.Report.Energy.Month.Notify=OFF",
"Device.System.Internet.Check.Port=80",
"Device.LAN.DHCPServer.Start=192.168.20.100",
"Device.LAN.2G.FragThreshold=2346",
"Device.NAT.VirtualServer.Enable=OFF",
"Device.System.Power.OverTime.Push=OFF",
"Device.LAN.DHCPServer.End=192.168.20.200",
"Device.System.RemoteManagement.Port=",
"Device.LAN.2G.0.Security.WPAPSK.PSKFormat=Passphrase",
"Device.System.Power.Budget.Month.Enable=OFF",
"Device.System.Power.Report.Energy.Day.Notify=OFF",
"Device.System.HiddenPage.Enable=ON",
"Device.System.Power.Toggle.Notify=OFF",
"Device.System.FwUpgrade.Time=Auto",
"Device.System.Internet.Check.Address=www.google.com",
"Device.LAN.2G.0.Security.WPAPSK.CipherSuite=WPA2AES",
"Device.System.Power.Budget.Mode=ENERGY",
"Device.LAN.2G.Enable=ON",
"Device.LAN.DHCPClient.Enable=OFF",
"Device.NAT.PortForward.Enable=OFF",
"Device.Configuration.SW.APRTSwitch=AP",
"Device.LAN.2G.Coexist.Enable=ON",
"Device.System.Power.Budget.UnitPrice=0",
"Device.System.Power.Budget.Day.Enable=OFF",
"Device.WAN.Static.IPAddress=172.1.1.1",
"Device.LAN.DHCPServer.Enable=ON",
"Device.WAN.DHCPClient.DNS.Enable=Auto",
"Device.WAN.Ping.Enable=OFF",
"Device.LAN.2G.0.Security.Mode=Disable",
"Device.System.Power.Toggle.Push=ON",
"Device.System.Power.Budget.Month.Notify=OFF",
"Device.LAN.2G.WPS.Enable=OFF",
"Device.WAN.DynIP.HostName=",
"Device.LAN.2G.Band=BGN",
"Device.LAN.2G.0.HideSSID.Enable=OFF",
"Device.System.Internet.Online.Notify=OFF",
"Device.System.Power.Budget.Week.UpperLimit=0",
"Device.System.Power.Budget.Day.Notify=OFF",
"Device.QoS.Download.Bandwidth=",
"Device.LAN.2G.BeaconInterval=100",
"Device.LAN.2G.0.MACAC.Enabled=OFF",
"Device.System.Cloud.Server.Address=www.myedimax.com",
"Device.System.Power.OverTime.Limit=0",
"Device.LAN.2G.DTIMPeriod=3",
"Device.LAN.DHCPServer.LeaseTime=31536000",
"Device.LAN.2G.0.SSID=EdiPlug.Setup",
"Device.System.Power.Budget.Month.Push=OFF",
"Device.LAN.2G.RTSThreshold=2347",
"Device.LAN.2G.0.Enable=ON",
"Device.LAN.2G.1.Enable=OFF",
"Device.System.Internet.Online.Push=OFF",
"Device.LAN.5G.0.Enable=OFF",
"Device.System.Power.Report.Energy.Week.Notify=OFF",
"Device.NAT.Enable=OFF",
"Device.WAN.Static.NetMask=255.255.255.0",
"Device.System.Power.Budget.Day.Push=OFF",
"Device.LAN.2G.FixRate=Auto",
"Device.QoS.Upload.Bandwidth=",
"Device.LAN.IPAddress=192.168.20.3",
"Device.QOS.Enable=OFF",
"Device.LAN.2G.TXPower=100",
"Device.LAN.2G.Channel=Auto",
"Device.System.Power.Budget.Week.Enable=OFF",
"Device.LAN.2G.0.WMM.Enable=ON",
"Device.LAN.2G.PreambleType=Short",
"Device.WAN.Static.Gateway=172.1.1.254",
"Device.System.TimeZone.Minute=0",
"Device.Configuration.KernelMessage.Enabled=ON",
"Device.LAN.DHCPServer.NetMask=255.255.255.0",
"Device.System.Password.Password=1234"

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Edimax SP2101W V2 with firmware 3.00c works fine. See instructions on how to obtain the password.

Hi!

I was able to successfully run the example code from the README without any exceptions thrown using an SP2101W V2 with firmware 3.00c.

So, I have an Edimax SP2101W V2 and made the mistake of clicking "yes" when I was asked to upgrade the firmware before doing my research. And boom, I was fucked. People suggested downgrading the firmware but I don't have a Window PC.

However, I found a solution in the NodeRED forum. The problem with most integrations and libraries that don't work with the new FW is that the password is no longer "1234" and it's no longer changeable by the user in the app, or even visible to the user. It's randomly generated during setup right after entering a name for the plug (before entering the name it's actually "1234") and then it's stored hidden inside the app.

Sucks that the setup is now so cumbersome, but the good news is that there is no need to downgrade the firmware.

Please check out Harpau's post from Oct. 2019 under this link:
https://discourse.nodered.org/t/searching-for-help-to-read-status-of-edimax-smartplug/15789/6

I followed the instructions step by step and have successfully obtained the password.

You have to do a factory reset (hold both "power" and "reset" buttons for 10+ seconds) until the LEDs turn red, then release and wait for reboot until the LEDs blink slowly in red. See Edimax FAQ

Here's a copy of the post:

  1. Find out the IP your Smartplug is actually using (you will need this in step 9).
  2. Delete the Smartplug from the EdiSmart App
  3. Perform a factory reset on the Smartplug
  4. As soon as the Smartplug is in "Installation Mode", connect your Smartphone with the "EdiPlug.Setup xx" WLAN as well as your PC.
  5. In the browser on your PC enter "http://192.168.20.3:10000/tnb2". The response should be "OK".
  6. On your Smartphone open the EdiSmart App
  7. On your PC connect again to your "normal" WLAN
  8. On your Smartphone select the WLAN and password for your Smartplug
  9. As soon as you are requested to enter a new name for your Smartplug, start Telnet with the IP from step 1 and Port 1355 on your PC
  10. On your Smartphone type in the new name for your Smartplug and press OK
  11. Now immediately, and while your Smartphone is still configuring your Smartplug, type in "nvc all" in the Telnet session on your PC. At the end of the list a password different than "1234" should be shown. If not, again type in "nvc all" until the newly generated password is displayed.

Note for Step 5: Use username "admin" and password "1234" to log in if prompted.

Note for step 11: You may have to run nvc all multiple times until you see the password change from "1234" to something else. The password is in the last line of the command output. Make sure you also follow the timing in the instructions above as the telnet server will shut down shortly after the setup.
Write the password down because this is the last time you'll see it.

Related issues: #14 #8

An in-range update of bluebird is breaking the build 🚨

The dependency bluebird was updated from 3.5.3 to 3.5.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

bluebird is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v3.5.4
  • Proper version check supporting VSCode(#1576)
Commits

The new version differs by 6 commits.

  • e0222e3 Release v3.5.4
  • 4b9fa33 missing --expose-gc flag (#1586)
  • 63b15da docs: improve and compare Promise.each and Promise.mapSeries (#1565)
  • 9dcefe2 .md syntax fix for coming-from-other-languages.md (#1584)
  • b97c0d2 added proper version check supporting VSCode (#1576)
  • 499cf8e Update jsdelivr url in docs (#1571)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

SP-2101W V2

Is the SP-2101W V2 supported? Did someone test against V2?
It seems to be impossible to buy "V1" anymore.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.