Example #1
0
        private void PingHostOnPingCompleted(object sender, PingCompletedEventArgs e)
        {
            var ip = (string)e.UserState;

            if (e.Reply == null || e.Reply.Status != IPStatus.Success)
            {
                return;
            }
            var tpConnection     = new TPLinkConnection();
            var smartLinkConnect = new TPLinkConnection.SmartLink {
                LinkAddress = ip
            };
            var moduleInformation = tpConnection.GetModuleInformation(smartLinkConnect);

            if (moduleInformation == null)
            {
                return;
            }
            smartLinkConnect.ModuleInformation = moduleInformation;
            var newModule = new Module(smartLinkConnect)
            {
                Dock = DockStyle.Top
            };

            panel_Modules.Invoke((MethodInvoker) delegate { panel_Modules.Controls.Add(newModule); });
            _smartLinks.Add(newModule);
        }
Example #2
0
        private void PingOnPingCompleted(object sender, PingCompletedEventArgs pingCompletedEventArgs)
        {
            var ip = (string)pingCompletedEventArgs.UserState;

            if (pingCompletedEventArgs.Reply != null && pingCompletedEventArgs.Reply.Status == IPStatus.Success)
            {
                // We got a live one here! Check it!
                var tpLinkCommand   = new TPLinkConnection();
                var moduleSmartLink = new TPLinkConnection.SmartLink()
                {
                    LinkPort    = 9999,
                    LinkAddress = ip
                };
                var moduleInformation = tpLinkCommand.GetModuleInformation(moduleSmartLink);

                if (moduleInformation != null)
                {
                    moduleSmartLink.LinkName          = moduleInformation.system.get_sysinfo.alias;
                    moduleSmartLink.ModuleInformation = moduleInformation;
                }
            }
            else if (pingCompletedEventArgs.Reply == null)
            {
            }
            _testedDevices++;
        }
Example #3
0
        private void btn_Module_OnOff_Click(object sender, EventArgs e)
        {
            var connection = new TPLinkConnection();

            moduleLink.ModuleInformation = connection.SetRelayState(moduleLink, btn_Module_OnOff.Checked);
            UpdateModuleInformation();
        }
Example #4
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            var connection = new TPLinkConnection();

            connection.UpdateModuleNameInformation(moduleSmartLink, txt_moduleName.Text);
            connection.UpdateModuleLedState(moduleSmartLink, rd_Status_Light_On.Checked);
            this.Close();
        }
Example #5
0
        public void UpdateModuleInformation()
        {
            var connection = new TPLinkConnection();

            moduleLink.ModuleInformation = connection.GetModuleInformation(moduleLink);

            txt_ModuleName.Text = moduleLink.ModuleInformation.system.get_sysinfo.alias;

            //Remove items that can't be filled.
            if (moduleLink.ModuleInformation.system.get_sysinfo.dev_name == "Wi-Fi Smart Plug")
            {
                lbl_watts.Text = @" - - ";
            }
            else
            {
                // go get the usage information for the first tim
                moduleLink.ModuleInformation = connection.GetRealTimeEnergyUsage(moduleLink);
                if (moduleLink.ModuleInformation.EnergyStats.Any())
                {
                    var firstOrDefault = moduleLink.ModuleInformation.EnergyStats.OrderByDescending(a => a.emeter.timeStamp)
                                         .FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        lbl_watts.Text = Convert.ToString((int)
                                                          firstOrDefault
                                                          .emeter.get_realtime.power);
                    }
                }
            }
            //btn_Module_OnOff.SetPropertyThreadSafe(.Invoke((MethodInvoker)delegate { panel_Modules.Controls.Add(newModule); });

            btn_Module_OnOff.BackgroundImage = moduleLink.ModuleInformation.system.get_sysinfo.relay_state == 1
                ? Resources.led_and_label_on
                : Resources.led_and_label_off;
            btn_Module_OnOff.Checked = moduleLink.ModuleInformation.system.get_sysinfo.relay_state == 1;
        }