示例#1
0
 private async void RTConnect()
 {
     status.Text = "Connecting to client ...";
     if (await mqtt.Connect())
     {
         status.Text = "Running";
     }
     else
     {
         C_Close(null, null);
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            //Intailize the Broker Settings
            BrokerModel _Broker = new BrokerModel();

            _Broker.Url           = "tailor.cloudmqtt.com";
            _Broker.Username      = "******";
            _Broker.Password      = "******";
            _Broker.Port          = 11300;
            _Broker.SSLPort       = 21300;
            _Broker.WebSocketPort = 31300;

            //Connect to Server
            MQTT mQTT = new MQTT();

            mQTT.Initailize(_Broker);
            mQTT.Connect();

            while (true)
            {
                if (mQTT.Connected)
                {
                    //publish string
                    mQTT.Publish("StringValue", "5");

                    //publish json Object
                    Sensor Sensor     = new Sensor();
                    var    result     = Sensor.CreateSensor();
                    string Jsonresult = JsonConvert.SerializeObject(result);
                    mQTT.Publish("SensorObject", Jsonresult);

                    //publish json List of Objectss

                    var    resultList     = Sensor.CreateSensorList();
                    string JsonresultList = JsonConvert.SerializeObject(resultList);
                    mQTT.Publish("SensorList", JsonresultList);
                }


                Thread.Sleep(10000);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            //Intailize the Broker Settings
            BrokerModel _Broker = new BrokerModel();

            _Broker.Url           = "tailor.cloudmqtt.com";
            _Broker.Username      = "******";
            _Broker.Password      = "******";
            _Broker.Port          = 11300;
            _Broker.SSLPort       = 21300;
            _Broker.WebSocketPort = 31300;

            //Connect to Server
            MQTT mQTT = new MQTT();

            mQTT.Initailize(_Broker);
            mQTT.Connect();
            mQTT.SubscribeEventHandler(client_MqttMsgPublishReceived);
            mQTT.Subscribe("StringValue");
            mQTT.Subscribe("SensorObject");
            mQTT.Subscribe("SensorList");
        }