Beispiel #1
0
 public bool Connect(string connString, string clientId, ushort keepAlive,
                     string username          = null, string password = null,
                     IPersistence persistence = null)
 {
     try
     {
         mqtt = MqttClientFactory.CreateClient(connString, clientId,
                                               username, password, persistence);
         mqtt.KeepAliveInterval = keepAlive;
         if (withWill)
         {
             mqtt.Connect(willTopic, willQos,
                          new MqttPayload(willMessage), willRetained, cleanSession);
         }
         else
         {
             mqtt.Connect(cleanSession);
         }
         mqtt.Connected      += Mqtt_Connected;
         mqtt.PublishArrived += Mqtt_PublishArrived;
         mqtt.Published      += Mqtt_Published;
         mqtt.Subscribed     += Mqtt_Subscribed;
         mqtt.Unsubscribed   += Mqtt_Unsubscribed;
         mqtt.ConnectionLost += Mqtt_ConnectionLost;
         return(true);
     }
     catch (Exception m_ex)
     {
         return(false);
     }
 }
Beispiel #2
0
        void Run()
        {
            ColetorTopicoLog ctlm = new ColetorTopicoLog();

            ctlm.Id_ColetorTopico = 1;
            ctlm.DataHora         = getData();
            ctlm.Valor            = "RunInicio";
            db.ColetorTopicoLog.Add(ctlm);
            db.SaveChanges();

            /*
             * client.username_pw_set("","ESQXpO-H7-1y")
             * client.connect("m14.cloudmqtt.com", 11718, 60)
             *
             */
            // string connectionString = "mqtt://m13.cloudmqtt.com:12644";
            string connectionString = "tcp://m14.cloudmqtt.com:11718";

            // Instantiate client using MqttClientFactory
            //_client = MqttClientFactory.CreateClient(connectionString, "aneuk", "clpfcosb", "ILo_4ucaK3P_");
            _client = MqttClientFactory.CreateClient(connectionString, "aneuk", "fgwuwgpw", "ESQXpO-H7-1y");
            // Setup some useful client delegate callbacks
            _client.Connected      += new ConnectionDelegate(client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
            //
            ColetorTopicoLog ctlm2 = new ColetorTopicoLog();

            ctlm2.Id_ColetorTopico = 1;
            ctlm2.DataHora         = getData();
            ctlm2.Valor            = "RunFim";
            db.ColetorTopicoLog.Add(ctlm2);
            db.SaveChanges();
            Start();
        }
Beispiel #3
0
 private void MQTT_TEST(string connectionString, string clientId, string username, string password)
 {
     _client                 = MqttClientFactory.CreateClient(connectionString, clientId, username, password);
     _client.Connected      += new ConnectionDelegate(client_Connected);
     _client.ConnectionLost += new ConnectionDelegate(client_ConnectionLost);
     _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
     _client.PublishArrived += _client_PublishArrived;
 }
Beispiel #4
0
        //
        Program()
        {
            string connectionString = "tcp://m16.cloudmqtt.com:14106";

            _client                 = MqttClientFactory.CreateClient(connectionString, "useracl", "username", "password");
            _client.Connected      += new ConnectionDelegate(client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
        }
Beispiel #5
0
 public MQTTManager(string connectionString, string clientId, string userName, string password)
 {
     this._connectionString       = connectionString;
     this._clientId               = clientId;
     this._client                 = MqttClientFactory.CreateClient(connectionString, _clientId, userName, password);
     this._client.Connected      += new ConnectionDelegate(client_Connected);
     this._client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
     this._client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
 }
Beispiel #6
0
        private void ConnectToBroker()
        {
            if (Servers.SelectedIndex < 0)
            {
                ShowSettingsPage();
                return;
            }
            if (_clientConnected)
            {
                return;
            }

            Settings settings = Settings.LoadSettings(Servers.Items[Servers.SelectedIndex]);

            if (!settings.EnableControls)
            {
                return;
            }
            IWifi wifi = new Wifi();

            string server = wifi.GetSSID() == $"\"{settings.LocalSSID}\""
                ? settings.LocalServerName
                : settings.RemoteServerName;

            string connectionString = $"tcp://{server}:{settings.MqttPort}";

            Device.BeginInvokeOnMainThread(() =>
            {
                if (!string.IsNullOrEmpty(settings.Username))
                {
                    client = MqttClientFactory.CreateClient(connectionString, Guid.NewGuid().ToString(), settings.Username,
                                                            settings.Password);
                }
                else
                {
                    client = MqttClientFactory.CreateClient(connectionString, Guid.NewGuid().ToString());
                }

                client.Connected      += ClientConnected;
                client.ConnectionLost += ClientConnectionLost;
                client.PublishArrived += ClientPublishArrived;

                IDeviceInfo device = new DeviceInfo();
                string name        = device.GetName();

                try
                {
                    client.Connect("car/DISCONNECT", QoS.BestEfforts, new MqttPayload(name), false, true);
                }
                catch (Exception ex)
                {
                    Toaster(ex.Message, ToastPriority.Critical, ToastLength.Long);
                    _clientConnected = false;
                }
            });
        }
Beispiel #7
0
        Program(string connectionString, string clientId)
        {
            // Instantiate client using MqttClientFactory
            _client = MqttClientFactory.CreateClient(connectionString, clientId);

            // Setup some useful client delegate callbacks
            _client.Connected      += new ConnectionDelegate(client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
        }
        Program(string clientId)
        {
            var connectionString = "tcp://fantastic-teacher.cloudmqtt.com:1883";

            _client = MqttClientFactory.CreateClient(connectionString, clientId, "gnztvlsa", "CZbmTTBjvd8f");
            // Setup some useful client delegate callbacks
            _client.Connected      += client_Connected;
            _client.ConnectionLost += _client_ConnectionLost;
            _client.PublishArrived += client_PublishArrived;
        }
 void ProgramSetup(string connectionString, string clientId, string username, string password)
 {
     // Instantiate client using MqttClientFactor
     _client = MqttClientFactory.CreateClient(connectionString, clientId, username, password);
     // Setup some useful client delegate callbacks
     _client.Connected      += new ConnectionDelegate(client_Connected);
     _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
     _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
     //textBoxIncomming.Text = e.Payload;
 }
Beispiel #10
0
        private void OpenMqtt()
        {
            client = MqttClientFactory.CreateClient(connectionString, clientId);
            client.Connect(true);

            client.Connected      += new ConnectionDelegate(client_Connected);
            client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);
            client.Published      += new CompleteDelegate(_client_Published);
        }
        /// <summary>
        /// Execute start up tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            m_client = MqttClientFactory.CreateClient("tcp://192.168.0.50:1883", "MQTTKinect");
            m_client.Connect(cleanStart: true);
            m_client.Publish("text", "Kinect 2.0 just loaded!", QoS.BestEfforts, false);
            timer = System.DateTimeOffset.Now.AddSeconds(0.1f);

            if (this.bodyFrameReader != null)
            {
                this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
            }
        }
Beispiel #12
0
        public Form1()
        {
            InitializeComponent();

            _client                 = MqttClientFactory.CreateClient("tcp://postman.cloudmqtt.com:17127", "comp1", "laivxdgr", "RQJhNBmGjTN4");
            _client.Connected      += new ConnectionDelegate(client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.PublishArrived += new PublishArrivedDelegate(Client_PublishArrived);

            // Setup some useful client delegate callbacks

            Start();
        }
        public void Connect(string clientId)
        {
            // Instantiate client using MqttClientFactory
            this._clientId = clientId;
            this._client   = MqttClientFactory.CreateClient(this._connectionString, this._clientId, this._authMode, this._authToken);

            // Setup some useful client delegate callbacks
            this._client.Connected      += new ConnectionDelegate(client_Connected);
            this._client.ConnectionLost += new ConnectionDelegate(client_ConnectionLost);
            this._client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);

            //instantiating the connection
            _client.Connect(true);
        }
Beispiel #14
0
    // Use this for initialization
    protected void Start()
    {
        Debug.Log("Starting");
        // Instantiate client using MqttClientFactory
        _client = MqttClientFactory.CreateClient(ConnectionString, ClientId, UserName, Password);

        Debug.Log(_client);
        // Setup some useful client delegate callbacks
        _client.Connected      += new ConnectionDelegate(client_Connected);
        _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
        _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);

        Debug.Log("Connecting......");
        _client.Connect();
    }
Beispiel #15
0
        void init()
        {
            // User Settings

            XmlDocument xmlConfig = new XmlDocument();

            xmlConfig.Load(AppDomain.CurrentDomain.BaseDirectory + "config.xml");
            var mqttConfig = xmlConfig["RazerChromaMqtt"]["MQTT"];
            var v          = mqttConfig["MqttUser"].InnerText.Trim();

            mqttHost     = mqttConfig["MqttHost"].InnerText.Trim();
            mqttPort     = mqttConfig["MqttPort"].InnerText.Trim();
            mqttUser     = mqttConfig["MqttUser"].InnerText.Trim();
            mqttPw       = mqttConfig["MqttPw"].InnerText.Trim();
            mqttPreTopic = mqttConfig["MqttPreTopic"].InnerText.Trim();

            if (mqttUser == "" || mqttPw == "")
            {
                mqttUser = mqttPw = null;
            }


            // MQTT
            mqttClient                 = MqttClientFactory.CreateClient($"tcp://{mqttHost}:{mqttPort}", "chroma", mqttUser, mqttPw);
            mqttClient.Connected      += MqttC_Connected;
            mqttClient.ConnectionLost += MqttC_ConnectionLost;
            mqttClient.PublishArrived += MqttC_PublishArrived;

            MqttAppender.mqttClient   = mqttClient;
            MqttAppender.mqttPreTopic = mqttPreTopic;

            try
            {
                mqttClient.Connect(mqttPreTopic + "state", QoS.BestEfforts, new MqttPayload("offline"), false);
            }
            catch (Exception e)
            {
                log.Error("Mqtt connect eror : " + e.Message);
                base.Stop();
            }


            Task <IChroma> connectChroma = ColoreProvider.CreateNativeAsync();

            connectChroma.Wait();
            chroma = connectChroma.Result;
        }
        void MQTTProgram(string connectionString, string clientId)
        {
            if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(clientId))
            {
                return;
            }
            // Instantiate client using MqttClientFactory
            _client = MqttClientFactory.CreateClient(connectionString, clientId);

            // Setup some useful client delegate callbacks
            _client.Connected      += new ConnectionDelegate(client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.PublishArrived += new PublishArrivedDelegate(client_PublishArrived);



            Start();
            //Stop();
        }
Beispiel #17
0
        void InitHandle()
        {
            try
            {
                handle = MqttClientFactory.CreateClient(connStr, clientId, user, pass);
                Log.Info("MqttAdaptor handle constructed");
            }
            catch (Exception e)
            {
                Log.Error("MqttAdaptor InitHandle construct throw exp:{0}", e);
                throw;
            }

            handle.Connected      = OnConnected;
            handle.ConnectionLost = OnDisconnected;
            handle.PublishArrived = OnReceived;

            Log.Info("MqttAdaptor InitHandle");
        }
Beispiel #18
0
 //Awake function connects to the mqtt broker and sets a function to be called whenever a publish arrives
 //NOTE: a factory class may be used to allow connections to any mqtt broker not just a hard coded one
 void Awake()
 {
     m_client = MqttClientFactory.CreateClient("tcp://" + IPAddress + ":" + Port, "UnityProxy");
     m_client.Connect(true);
     m_client.PublishArrived += new PublishArrivedDelegate(MessageRecieved);
 }