private void btnConnect_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtNodeId.Text))
            {
                MessageBox.Show("Node ID can not be null !");
                return;
            }

            if (_edgeAgent == null)
            {
                EdgeAgentOptions options = new EdgeAgentOptions()
                {
                    DCCS = new DCCSOptions()
                    {
                        CredentialKey = txtDCCSKey.Text.Trim(),
                        APIUrl        = txtDCCSAPIUrl.Text.Trim()
                    },

                    AutoReconnect     = true,
                    ReconnectInterval = 1000,
                    NodeId            = txtNodeId.Text.Trim(),
                    Heartbeat         = 60000, // default is 60 seconds
                    DataRecover       = true,
                    UseSecure         = ckbSecure.Checked
                };

                _edgeAgent = new EdgeAgent(options);

                _edgeAgent.Connected       += _edgeAgent_Connected;
                _edgeAgent.Disconnected    += _edgeAgent_Disconnected;
                _edgeAgent.MessageReceived += _edgeAgent_MessageReceived;
            }
            else
            {
                _edgeAgent.Options.NodeId    = txtNodeId.Text.Trim();
                _edgeAgent.Options.UseSecure = ckbSecure.Checked;

                _edgeAgent.Options.DCCS = new DCCSOptions()
                {
                    CredentialKey = txtDCCSKey.Text.Trim(),
                    APIUrl        = txtDCCSAPIUrl.Text.Trim()
                };
            }

            _edgeAgent.Connect();
        }
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                EdgeAgentOptions options = new EdgeAgentOptions()
                {
                    AutoReconnect = true,

                    ReconnectInterval = 1000,

                    ScadaId = textBoxGroupId.Text,

                    Type = EdgeType.Gateway,

                    Heartbeat = 60000,   // default is 60 seconds,

                    DataRecover = true,

                    ConnectType = ConnectType.MQTT,

                    UseSecure = checkBoxSSL.Checked
                };

                switch (options.ConnectType)
                {
                case ConnectType.MQTT:
                    options.MQTT = new MQTTOptions()
                    {
                        HostName     = textBoxIp.Text,
                        Port         = Convert.ToInt32(textBoxPort.Text),
                        Username     = textBoxUser.Text,
                        Password     = textBoxPwd.Text,
                        ProtocolType = Protocol.TCP
                    };
                    break;
                }

                _edgeAgent = new EdgeAgent(options);

                _edgeAgent.Connected       += _edgeAgent_Connected;
                _edgeAgent.Disconnected    += _edgeAgent_Disconnected;
                _edgeAgent.MessageReceived += _edgeAgent_MessageReceived;
            }
            _edgeAgent.Connect();
        }