Ejemplo n.º 1
0
 private void RegisterSubscriptions()
 {
     client.Subscribe("mqttmessenger/server/userconnected", QoS.BestEfforts);
     client.Subscribe("mqttmessenger/server/getmessages", QoS.BestEfforts);
     client.Subscribe("mqttmessenger/server/newmessage", QoS.BestEfforts);
     client.Subscribe("mqttmessenger/bob/messagedump", QoS.BestEfforts);
 }
Ejemplo n.º 2
0
        // todo Critical Section
        // user thread should ensure both of the two entrance thread-safely
        public void RegisterDelegate(IMessageConsumer consumer, string serviceId)
        {
            delegates[serviceId] = consumer;
            var rule = MetaData.GetServiceRoutingRule(serviceId);

            if (rule == null)
            {
                throw new Exception();
            }

            var key = rule.MqttRule.GetSubscribeKey(uuid);

            if (!handle.IsConnected)
            {
                toSubscribe[key] = true;
                return;
            }

            try
            {
                handle.Subscribe(key, QoS.AtLeastOnce);
                subscriptions[key] = true;
            }
            catch (Exception e)
            {
                Log.Error("MqttAdaptor RegisterDelegate throw exp:{0}", e);
                throw;
            }
        }
Ejemplo n.º 3
0
 private void RegisterSubscriptions()
 {
     //client.Subscribe("mqttmessenger/server/userconnected", QoS.BestEfforts);
     //client.Subscribe("mqttmessenger/server/getmessages", QoS.BestEfforts);
     //client.Subscribe("mqttmessenger/server/newmessage", QoS.BestEfforts);
     //client.Subscribe("mqttmessenger/bob/messagedump", QoS.BestEfforts);
     client.Subscribe("eebus/daenet/command", QoS.BestEfforts);
     client.Subscribe("eebus/daenet/telemetry", QoS.BestEfforts);
 }
Ejemplo n.º 4
0
        private void ClientConnected(object sender, EventArgs e) => Device.BeginInvokeOnMainThread(delegate
        {
            client.Subscribe("car/STATE", QoS.BestEfforts);
            client.Subscribe("car/RESPOND", QoS.BestEfforts);
            client.Subscribe("car/STATUS", QoS.BestEfforts);
            StatusText.Text = string.Empty;

            _clientConnected = true;

            IDeviceInfo device  = new DeviceInfo();
            string name         = device.GetName();
            MqttPayload payload = new MqttPayload(name);
            client.Publish("car/CONNECT", payload, QoS.BestEfforts, false);
            movement = new Movement();
            MoveCar();
        });
Ejemplo n.º 5
0
 void RegisterOurSubscriptions()
 {
     Console.WriteLine("Subscribing to globalchoices/357660090106246\n"); // Edmunds Q2
     //onsole.WriteLine("Subscribing to globalchoices/#\n"); // Edmunds Q2
     _client.Subscribe("globalchoices/357660090106246", QoS.AtLeastOnce);
     //_client.Subscribe("globalchoices/#", QoS.AtLeastOnce);
 }
Ejemplo n.º 6
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init ();

            // Code for starting up the Xamarin Test Cloud Agent
            #if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start();
            #endif

            MqttClient.Ios.Bootstrapper.Setup ();

            LoadApplication (new App ());

            var connectionString = Keys.MQTT_BROKER_CONNECTION;
            var clientId = "iphone";

            // 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);

            _client.Connect ();
            _client.Subscribe (
                new Subscription[] {
                    new Subscription ("/status", QoS.BestEfforts),
                    new Subscription ("/cmd", QoS.BestEfforts),
                    new Subscription ("/event", QoS.BestEfforts),

                });

            return base.FinishedLaunching (app, options);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            lblConnected.Text = "Disconnected";
            _mqttClient = MqttClientFactory.CreateClient("tcp://m11.cloudmqtt.com:12360", Guid.NewGuid().ToString(), "mike", "cloudmqtt");
            _mqttClient.Connected += (object sender, EventArgs e) => {

                InvokeOnMainThread(() =>
                {
                    var subscription = new Subscription("mqttdotnet/pubtest", QoS.BestEfforts);
                    _mqttClient.Subscribe(subscription);
                    setConneectedState();
                });
            };
            _mqttClient.ConnectionLost += (object sender, EventArgs e) => {
                InvokeOnMainThread(() => {
                    setDisconnectedState();
                });
            };
            _mqttClient.Subscribed += _mqttClient_Subscribed;
            _mqttClient.Unsubscribed += _mqttClient_Unsubscribed;
            _mqttClient.PublishArrived += _mqttClient_PublishArrived;

            _mqttClient.Connect();
        }
Ejemplo n.º 8
0
    //subscribe to topic function is called by mqtt client classes on other gameobjects
    //it subscribes the proxy to the given topic and creates an entry for the subscribing gameobject in the subscribers dictionary
    public void SubscribeToTopic(string _topic, mqttClient _client)
    {
        if (!m_subscribers.ContainsKey(_topic))
        {
            m_client.Subscribe(_topic, QoS.BestEfforts);
            m_subscribers.Add(_topic, new List <mqttClient> ());
        }

        m_subscribers[_topic].Add(_client);
    }
Ejemplo n.º 9
0
        void RegisterOurSubscriptions(string topic)
        {
            //Console.WriteLine("Subscribing to mqttdotnet/subtest/#\n");
            //    ComMessage = "Subscribing to " + topic;
            int returnvalue = _client.Subscribe(topic + "/#", QoS.BestEfforts);

            if (returnvalue > 0)
            {
                ConnectStstus = Status.ConnectedRegisterd;
            }
            else
            {
                textBoxAllStatus.Text = "Publish  Unable to resgisted ";
                ConnectStstus         = Status.UnableRegist;
            }
        }
Ejemplo n.º 10
0
 void RegisterOurSubscriptions()
 {
     Console.WriteLine("Subscribing to mqttdotnet/subtest/#\n");
     _client.Subscribe("temperature", QoS.BestEfforts);
 }
Ejemplo n.º 11
0
 void RegisterOurSubscriptions()
 {
     Console.WriteLine("Subscribing to pubtest\n");
     _client.Subscribe("pubtest", QoS.AtLeastOnce);
 }
Ejemplo n.º 12
0
        private static void SetupMqtt()
        {
            try
            {
                _mqtt = MqttClientFactory.CreateClient(_settings.Server, _settings.Key);

                _mqtt.PublishArrived -= new PublishArrivedDelegate(MqttPublishArrived);
                _mqtt.ConnectionLost -= new ConnectionDelegate(MqttConnectionLost);

                _mqtt.Connect();

                Subscription subscription = new Subscription(_settings.Key, QoS.BestEfforts);
                _mqtt.Subscribe(subscription);

                _mqtt.PublishArrived += new PublishArrivedDelegate(MqttPublishArrived);
                _mqtt.ConnectionLost += new ConnectionDelegate(MqttConnectionLost);

                _blinkLedCommand.Execute(CreateLedBlinkCommand(2));
            }
            catch (Exception ex)
            {
                Restart("Setup MQTT has failed", ex);
            }
        }
Ejemplo n.º 13
0
        private void ConnectToBroker(string ip, int port, string clientId)
        {
            if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(clientId) || port == 0)
                return;
            if (_client != null)
            {
                _client.PublishArrived -= new PublishArrivedDelegate(_client_PublishArrived);
                _client.Connected -= new ConnectionDelegate(_client_Connected);
                _client.ConnectionLost -= new ConnectionDelegate(_client_ConnectionLost);
                _client.Published -= new CompleteDelegate(_client_Published);
                _client.Subscribed -= new CompleteDelegate(_client_Subscribed);
                _client.Unsubscribed -= new CompleteDelegate(_client_Unsubscribed);
                if (_client.IsConnected)
                {
                    // TODO this might be async
                    _client.Disconnect();
                }
            }

            _client = MqttClientFactory.CreateClient("tcp://" + ip + ":" + port.ToString(), clientId);

            _client.Connect();

            // Subscribe to the house code in config
            string houseCode = ConfigurationManager.AppSettings["HouseCode"];

            _client.Subscribe("/" + houseCode + "/#", QoS.BestEfforts);
            _client.Subscribe("$SYS/broker/clients/#", QoS.BestEfforts);
            _client.PublishArrived += new PublishArrivedDelegate(_client_PublishArrived);
            _client.Connected += new ConnectionDelegate(_client_Connected);
            _client.ConnectionLost += new ConnectionDelegate(_client_ConnectionLost);
            _client.Published += new CompleteDelegate(_client_Published);
            _client.Subscribed += new CompleteDelegate(_client_Subscribed);
            _client.Unsubscribed += new CompleteDelegate(_client_Unsubscribed);
        }
Ejemplo n.º 14
0
 void client_Connected(object sender, EventArgs e)
 {
     _client.Subscribe("/test/client2", QoS.BestEfforts);
     _client.Publish("/test/client1", "1", QoS.BestEfforts, false);
 }
Ejemplo n.º 15
0
 public void Subscribe(string topic, string name)
 {
     StaticResources.messageQueue.Enqueue("时间:" + DateTime.Now.ToString() +
                                          "订阅信息,信息ID为:" +
                                          mqtt.Subscribe(topic, StaticResources.NameToQos(name)));
 }
Ejemplo n.º 16
0
 protected void RegisterOurSubscriptions()
 {
     Debug.Log("Subscribing to " + Topic);
     _client.Subscribe(Topic, QoS.BestEfforts);
 }
Ejemplo n.º 17
0
 void RegisterOurSubscriptions()
 {
     Console.WriteLine("Subscribing to mqttdotnet/subtest/#\n");
     _client.Subscribe(strMQTT_TCP_Server_Topic, QoS.BestEfforts);
 }
Ejemplo n.º 18
0
 private void MqttC_Connected(object sender, EventArgs e)
 {
     log.Info("Mqtt Connect");
     mqttClient.Subscribe(mqttPreTopic + "set/#", QoS.BestEfforts);
     mqttClient.Publish(mqttPreTopic + "state", new MqttPayload("online"), QoS.BestEfforts, false);
 }
Ejemplo n.º 19
0
 void RegisterOurSubscriptions()
 {
     _client.Subscribe("/Testing/topic/#", QoS.BestEfforts);
 }