Example #1
0
        private void dowork(object o, DoWorkEventArgs args)
        {
            try
            {
                var client = new WeMoService.BasicServicePortTypeClient();
                client.Endpoint.Address = new EndpointAddress(string.Format("http://{0}:{1}/upnp/control/basicevent1", ip, port));

                var state = client.GetBinaryState(new WeMoService.GetBinaryState());
                Console.WriteLine("Switch is current set to: {0}", state.BinaryState);

                if (state.BinaryState == "0")
                {
                    state.BinaryState = "1";
                }
                else
                {
                    state.BinaryState = "0";
                }

                var msg = new WeMoService.SetBinaryState {
                    BinaryState = state.BinaryState
                };
                client.SetBinaryState(msg);
            }
            catch (Exception ex)
            {
                WebPage.DisplayWebPage("Wemo Command Error", ex.Message);
            }
        }
Example #2
0
        private void doworkNotWorking(object o, DoWorkEventArgs args)
        {
            BackgroundWorker b  = o as BackgroundWorker;
            string           ip = "192.168.86.177";

            Console.WriteLine(string.Format("Wemo Address: http://{0}:{1}/upnp/control/basicevent1", ip, port));

            WSHttpBinding binding = new WSHttpBinding();

            binding.OpenTimeout    = new TimeSpan(0, 0, 20);
            binding.CloseTimeout   = new TimeSpan(0, 1, 0);
            binding.SendTimeout    = new TimeSpan(0, 1, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 1, 0);

            var client = new WeMoService.BasicServicePortTypeClient(binding, new EndpointAddress(string.Format("http://{0}:{1}/upnp/control/basicevent1", ip, port)));
            GetBinaryStateResponse state = null;

            try
            {
                state = client.GetBinaryState(new WeMoService.GetBinaryState());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (port == 49154)
                {
                    port = 49153;
                }
                else
                {
                    port = 49154;
                }
                try
                {
                    Console.WriteLine(string.Format("Wemo Address: http://{0}:{1}/upnp/control/basicevent1", ip, port));
                    client = new WeMoService.BasicServicePortTypeClient(binding, new EndpointAddress(string.Format("http://{0}:{1}/upnp/control/basicevent1", ip, port)));
                    state  = client.GetBinaryState(new WeMoService.GetBinaryState());
                }
                catch (Exception ex2) { Console.WriteLine(ex2.Message); }
            }

            try
            {
                Console.WriteLine("Switch is current set to: {0}", state.BinaryState);
                if (state != null)
                {
                    if (state.BinaryState == "0")
                    {
                        state.BinaryState = "1";
                    }
                    else
                    {
                        state.BinaryState = "0";
                    }

                    var msg = new WeMoService.SetBinaryState {
                        BinaryState = state.BinaryState
                    };
                    client.SetBinaryState(msg);
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }