Giter VIP home page Giter VIP logo

wemo.net's Introduction

Build Status

Wemo.net

.Net Standard 2.0 (C#) library providing easy, multi-platform communications with Wemo devices.

Wemo Communications

Communicate with your locally-accessible Wemo plug - this will not work externally via the internet (of which would require access to the Wemo network).

Usage

Compile the project, or acquire the latest nuget package and reference:

using WemoNet;

Instantiate the class

var wemo = new Wemo();

Turn-on a Wemo Plug

wemo.TurnOnWemoPlugAsync("http://192.168.1.5").GetAwaiter().GetResult();

Turn-off a Wemo Plug

wemo.TurnOffWemoPlugAsync("http://192.168.1.5").GetAwaiter().GetResult();

Toggle on/off a Wemo Plug

wemo.ToggleWemoPlugAsync("http://192.168.1.5").GetAwaiter().GetResult();

Verify communications example

var onSuccess = await wemo.TurnOnWemoPlugAsync("http://192.168.1.5");
var offSuccess = await wemo.TurnOffWemoPlugAsync("http://192.168.1.5");
var success = wemo.TurnOnWemoPlugAsync("http://192.168.1.5").GetAwaiter().GetResult();

Search for Wemo devices within your local network (caution, this will consume 2-3 minutes)

var listOfDevicesFound = await wemo.GetListOfLocalWemoDevicesAsync(192, 168, 10); // First 3 local IP address octets

wemo.net's People

Contributors

azure-pipelines[bot] avatar chuckvanzant avatar deisterhold avatar seanksullivan avatar

Stargazers

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

Watchers

 avatar

wemo.net's Issues

Can this work with the latest smart plug, hardware version v4?

I just got the latest v4 smart plug and it can turn the plug on and off using port number 49152 not 49153. However, the query action gives an unhandled exception:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at WemoNet.Communications.WemoPlug.VerifyWemoDevice(HttpWebRequest request, String reqContentSoap) in D:\Documents\C Sharp Code\Wemo.net-master\WemoCommunications\WemoNet\Communications\WemoPlug.cs:line 297
at WemoNet.Communications.WemoPlug.<>c__DisplayClass30_0.<b__1>d.MoveNext() in D:\Documents\C Sharp Code\Wemo.net-master\WemoCommunications\WemoNet\Communications\WemoPlug.cs:line 170
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.<>c.b__139_1(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Support for Wemo Insights

Hi There,

I was curious to know if it would be possible to implement the insights feature. I'd like to utilize this library in order to measure the wattage of my devices.

Thanks,
Ely Haughie.

Issue with this on a Raspberry Pi and .NET core

For some reason in .NET core on a linux (Stretch Raspbian) system the find devices fails because the timeout is not caught as a webexception. I added a handler for a generic exception and it seems to work fine now

Here is the code

private static bool VerifyWemoDevice(HttpWebRequest request, string reqContentSoap)
    {
        var response = false;
        try
        {
            // Write the Soap Request to the Request Stream
            using (var requestStream = request.GetRequestStream())
            {
                var encoding = new UTF8Encoding();
                requestStream.Write(encoding.GetBytes(reqContentSoap), 0, encoding.GetByteCount(reqContentSoap));

                // Send the Request and acquire the Response
                using (var httpResponse = request.GetResponse() as HttpWebResponse)
                {
                    var headers = httpResponse.Headers;
                    var headerValues = headers.GetValues("X-User-Agent").ToList();

                    if (headerValues.Exists(x => x.Contains("redsonic")))
                    {
                        response = true;
                    }
                }
            }
        }
        catch (WebException ex)
        {
            response = false;
        }
        catch (Exception err)
        {
            //For some reason in .NET core on a linux system this is not caught as a Web Exception
            //This is a catch all for all exceptions that may occur
            response = false;
        }

        return response;
    }

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.