示例#1
0
        public EdgeAgent(EdgeAgentOptions options)
        {
            Options     = options;
            _mqttClient = new MqttFactory().CreateManagedMqttClient() as ManagedMqttClient;

            _mqttClient.ApplicationMessageReceived += mqttClient_MessageReceived;
            _mqttClient.Connected    += mqttClient_Connected;
            _mqttClient.Disconnected += mqttClient_Disconnected;

            MqttTcpChannel.CustomCertificateValidationCallback = (x509Certificate, x509Chain, sslPolicyErrors, mqttClientTcpOptions) => { return(true); };
        }
        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();
        }
示例#4
0
        public EdgeAgent(EdgeAgentOptions options)
        {
            Options     = options;
            _mqttClient = new MqttFactory().CreateManagedMqttClient() as ManagedMqttClient;

            _mqttClient.ApplicationMessageReceived += mqttClient_MessageReceived;
            _mqttClient.Connected    += mqttClient_Connected;
            _mqttClient.Disconnected += mqttClient_Disconnected;

            _heartbeatTimer          = new Timer();
            _heartbeatTimer.Interval = _options.Heartbeat;
            _heartbeatTimer.Elapsed += _heartbeatTimer_Elapsed;

            if (options.DataRecover)
            {
                _recoverHelper             = new DataRecoverHelper();
                _dataRecoverTimer          = new Timer();
                _dataRecoverTimer.Interval = DEAFAULT_DATARECOVER_INTERVAL;
                _dataRecoverTimer.Elapsed += _dataRecoverTimer_Elapsed;
                _dataRecoverTimer.Enabled  = true;
            }

            MqttTcpChannel.CustomCertificateValidationCallback = (x509Certificate, x509Chain, sslPolicyErrors, mqttClientTcpOptions) => { return(true); };
        }