private void button3_Click(object sender, EventArgs e) { var Form2 = new Form2(); if (!CheckTradfriAddress(textBox3.Text)) { MessageBox.Show("Could not find Tradfri gateway. Check address/DNS name."); return; } Form2.textBox1.Text = textBox1.Text; if (Form2.ShowDialog().Equals(DialogResult.OK)) { try { if (gatewayConnection == null) { gatewayConnection = new TradFriCoapConnector(textBox1.Text, textBox3.Text, textBox2.Text); } TradFriAuth ConnectionSecret = gatewayConnection.GeneratePSK(Form2.textBox2.Text, Form2.textBox1.Text); // Write the connection settings back to the respective text boxes. textBox1.Text = Form2.textBox1.Text; textBox2.Text = ConnectionSecret.PSK; gatewayConnection = null; } catch (Exception ex) { MessageBox.Show($"Couldn't connect to TradFri gateway with provided settings: {ex.Message}"); gatewayConnection = null; } } }
private void ConnectTradfri() { try { if (gatewayConnection == null) { if (!CheckTradfriAddress(textBox3.Text)) { MessageBox.Show("Could not find Tradfri gateway. Check address/DNS name."); return; } gatewayConnection = new TradFriCoapConnector(textBox1.Text, textBox3.Text, textBox2.Text); gatewayConnection.Connect(); } // Query all devices and list in the comboBox. LoadAllDevices(); } catch (Exception ex) { MessageBox.Show($"Couldn't connect to TradFri gateway with provided settings: {ex.Message}"); gatewayConnection = null; } }
/// <summary> /// Sample Connect Method /// </summary> /// <returns>boolean value indicating if the connection was successful</returns> public bool Connect() { if (!this.IsConnected) { // Log that the interface is loading and display the version being loaded Log.Info("Starting Ikea Tradfri Interface, Version {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); this.devices = new List <TradFriDevice>(); if (string.IsNullOrEmpty(this.GetOption("GatewayName").Value)) { throw new Exception("Gateway name not configured"); } if (string.IsNullOrEmpty(this.GetOption("GatewayAddress").Value)) { throw new Exception("Gateway address not configured"); } if (string.IsNullOrEmpty(this.GetOption("GatewaySecret").Value)) { throw new Exception("Gateway secret not configured"); } this.gatewayConnection = new TradFriCoapConnector( this.GetOption("GatewayName").Value, this.GetOption("GatewayAddress").Value, this.GetOption("GatewaySecret").Value); this.gatewayConnection.Connect(); this.gatewayController = new GatewayController(this.gatewayConnection.Client); Log.Info("Connected"); this.IsConnected = true; // Console.WriteLine("Loading devices"); // LoadAllDevices(); // Console.WriteLine("Loaded devices"); } this.OnInterfaceModulesChanged(this.GetDomain()); return(true); }
private void Main_Load(object sender, EventArgs e) { if (Properties.Settings.Default.GatewayName.Equals("GW-Nickname") && Properties.Settings.Default.GatewayIP.Equals("192.168.1.1") && Properties.Settings.Default.GatewaySecret.Equals("someSecretOnTheBackOfTheGateway")) { MessageBox.Show("Please provide the settings for your Gateway into app.config of 'TradFriGui' project."); Environment.Exit(0); } try { devices = new List <TradFriDevice>(); gatewayConnection = new TradFriCoapConnector(Properties.Settings.Default.GatewayName, Properties.Settings.Default.GatewayIP, Properties.Settings.Default.GatewaySecret); gatewayConnection.Connect(); } catch (Exception) { MessageBox.Show("Couldn't connect to TradFri gateway with provided settings"); Environment.Exit(0); } LoadAllDevices(); ShowDGVData(); }
private void Initialize() { _devices = new List <TradFriDevice>(); _gatewayConnection = new TradFriCoapConnector(Properties.Settings.Default.GatewayName, Properties.Settings.Default.GatewayIP); }