Beispiel #1
1
        public void TaskRun()
        {
            Trace.t(cc.Norm, "Vision TaskRun started");

            Program.Pilot.Send(new { Cmd = "SRVO", Value = servoPosition });

            if (!Program.PilotString.Contains("com"))
            {
                Mq = new MqttClient(Program.PilotString);
                Trace.t(cc.Norm, string.Format("vision connecting to MQTT @ {0}", Program.PilotString));
                Mq.Connect("MMPXY");
                Trace.t(cc.Norm, "vision connected");

                Mq.MqttMsgPublishReceived += PixyMqRecvd;
                Mq.Subscribe(new string[] { "robot1/pixyCam" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
            }

            SubState = VisionState.Run;

            // if finished, exit task
            while (Program.State != RobotState.Shutdown)
            {
                if (SubState == VisionState.Run)
                    if (coneFlag != ConeState.Lost && DateTime.Now > lastSeenTime + lostWaitTime)
                        LostCone();

                Program.Delay(100).Wait();
            }

            Trace.t(cc.Warn, "Vision exiting");
            SubState = VisionState.Idle;
            if (Mq != null && Mq.IsConnected)
                Mq.Disconnect();
        }
        private async void MainPage_Loaded(object s, RoutedEventArgs e)
        {
            disconnected();

            _mqtt = new MqttClient("m11.cloudmqtt.com", 12360, false, MqttSslProtocols.None);
            _mqtt.ConnectionClosed += (sender, args) =>
            {
                disconnected();
            };
            _mqtt.MqttMsgSubscribed += (sender, args) =>
            {
                connected();
            };

            _mqtt.MqttMsgPublishReceived += (sender, args) =>
            {
                var msg = Encoding.ASCII.GetString(args.Message);

                switch (msg)
                {
                    case "happy":
                    {
                        _animator.drawFrame(0);
                    }
                    break;
                    case "sad":
                    {
                        _animator.drawFrame(1);
                    }
                    break;
                    case "indifferent":
                    {
                        _animator.drawFrame(2);
                    }
                    break;
                }

                _clear.schedule(() => _backpack.clear(), 5000);
            };

            Task.Run(() =>
            {

                _mqtt.Connect("1", "mike", "cloudmqtt");
                _mqtt.Subscribe(new[] {"mqttdotnet/pubtest/#"}, new[] {MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE});
            });

            _backpack = new Adafrut8x8LEDBackpack();
            await _backpack.initializeAsync();

            _animator = new BackpackAnimator(_backpack, EmoticonsFrameGenerator.getAnimationFrames());
        }
Beispiel #3
0
 // Use this for initialization
 void Start()
 {
     client = new MqttClient(MQTT_BROKER_ADDRESS);
     client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
     client.Connect("unity");
     client.Subscribe(new string[] { "doebi/#" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
 }
Beispiel #4
0
        public static void Main()
        {
            led = new OutputPort(Pins.ONBOARD_LED, false);

            Microsoft.SPOT.Hardware.Utility.SetLocalTime(new DateTime(2014, 4, 13));

            Thread.Sleep(10000);

            var networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];

            if (networkInterface.IPAddress == IPAddress.Any.ToString())
            {

                networkInterface.EnableDhcp();
                networkInterface.EnableDynamicDns();
                networkInterface.RenewDhcpLease();
            }

            // create client instance
            //MqttClient client = new MqttClient("dev.rabbitmq.com", 1883, false, null);
            MqttClient client = new MqttClient("206.205.188.34", 1883, false, null);

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
            client.MqttMsgSubscribed += client_MqttMsgSubscribed;
            client.MqttMsgUnsubscribed += client_MqttMsgUnsubscribed;
            client.MqttMsgPublished += client_MqttMsgPublished;

            // subscribe to the topic
            client.Subscribe(new string[] { "ABC12345/led" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });

            //Console.ReadLine();
            var state = client.Connect("ABC12345", "guest", "guest", false, 0, false, null, null, true, 60);
        }
    protected void InitMqtt()
    {
        var client = new uPLibrary.Networking.M2Mqtt.MqttClient(appState.Config.MqttServer, int.Parse(appState.Config.MqttPort), false);

        try
        {
            client.Connect("holoclient");
        }
        catch (Exception e)
        {
            Debug.LogError("Error connecting to mqtt");
        }
        if (client.IsConnected)
        {
            // register to message received
            client.MqttMsgPublishReceived += (sender, e) =>
            {
                UnityMainThreadDispatcher.Instance().Enqueue(() =>
                {
                    var msg = Encoding.UTF8.GetString(e.Message);
                    switch (e.Topic)
                    {
                    case "view":
                        SetView(msg);
                        break;
                    }
                    GameObject _3dText = GameObject.Find("tbTemp");
                    _3dText.GetComponent <TextMesh>().text = msg;
                });
            };

            //// subscribe to the topic "/home/temperature" with QoS 2
            client.Subscribe(new string[] { "view" }, new byte[] { uPLibrary.Networking.M2Mqtt.Messages.MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        }
    }
 public MqttWorker(string brokerHostname, string[] nodes)
 {
     client = new MqttClient(brokerHostname);
     client.Connect(Guid.NewGuid().ToString());
     client.Subscribe(nodes.Select(n => $"nodes/{n}/packets").ToArray(), nodes.Select(n => MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE).ToArray());
     client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
     WorkerSupportsCancellation = true;
 }
Beispiel #7
0
        public void Setup()
        {
            mqttClient = new MqttClient(Config.MqttHost, Config.MqttPort, false, null);
            mqttClient.Connect(Config.MqttClientId, Config.MqttUsername, Config.MqttPassword);

            Console.WriteLine("Connected: " + mqttClient.IsConnected);

            mqttClient.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
            mqttClient.MqttMsgSubscribed += client_MqttMsgSubscribed;

            mqttClient.Subscribe(new string[] { Config.MqttTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        }
Beispiel #8
0
        public static void Main(string[] args)
        {
            MqttClient client = new MqttClient(MQTT_BROKER_ADDRESS);

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);

            client.Subscribe(new string[] { "/testit/now" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        }
Beispiel #9
0
        public static void Main()
        {
            netduino = NetduinoFactory.Get(ConfigurationManager.LedPinType);
            netduino.Setup();

            mqttClient = new MqttClient(ConfigurationManager.MqttHost, ConfigurationManager.MqttPort, false, null);
            mqttClient.Connect(ConfigurationManager.MqttClientId, ConfigurationManager.MqttUsername, ConfigurationManager.MqttPassword);

            mqttClient.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
            mqttClient.MqttMsgSubscribed += client_MqttMsgSubscribed;

            mqttClient.Subscribe(new string[] { ConfigurationManager.MqttTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        }
Beispiel #10
0
        public static void Main()
        {
            netduino = NetduinoFactory.Get(config.AppSettings["LedPinType"]);
            netduino.Setup();

            mqttClient = new MqttClient(IPAddress.Parse(config.AppSettings["MqttHost"]), int.Parse(config.AppSettings["MqttPort"]), false, null);
            mqttClient.Connect(config.AppSettings["MqttClientName"] + "-" + config.AppSettings["MqttPairingCode"], config.AppSettings["MqttUsername"], config.AppSettings["MqttPassword"]);

            mqttClient.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
            mqttClient.MqttMsgSubscribed += client_MqttMsgSubscribed;

            mqttClient.Subscribe(new string[] { config.AppSettings["MqttTopic"] + config.AppSettings["MqttPairingCode"] }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE });
        }
Beispiel #11
0
    private void Start()
    {
        mqttClient = new MqttClient(mqttBrokerHost);
        mqttClient.MqttMsgPublishReceived += HandleClientMqttMsgPublishReceived;

        String clientId = Guid.NewGuid().ToString();

        mqttClient.Connect(clientId);

        string[] topics = { mqttTopic };
        byte[]   qualityOfServiceLevels = { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE };
        mqttClient.Subscribe(topics, qualityOfServiceLevels);
    }
Beispiel #12
0
        private static void ConnectSubscribe(string APIKEY, string FEEDID)
        {
            var ip = System.Net.IPAddress.Parse("216.52.233.120"); //this is api.xively.com ...

            var mqc = new MqttClient(ip);
            mqc.Connect(APIKEY);

            byte[] qosleve = new byte[1];
            qosleve[0] = 0;
            mqc.Subscribe(new string[] { APIKEY + FEEDID }, qosleve);

            mqc.MqttMsgPublishReceived += new MqttClient.MqttMsgPublishEventHandler(mqc_MqttMsgPublishReceived);
        }
Beispiel #13
0
    // Use this for initialization
    void Start()
    {
        // create client instance
        client = new MqttClient("vps.provolot.com", 1883 , false , null );

        // register to message received
        client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

        string clientId = Guid.NewGuid().ToString();
        client.Connect(clientId);

        // subscribe to the topic "/home/temperature" with QoS 2
        client.Subscribe(new string[] { "hello/world" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
    }
Beispiel #14
0
        public override async Task InitializeAsync(DevicePluginConfigurationModel configuration)
        {
            await base.InitializeAsync(configuration);

            try
            {
                _deviceid = configuration.Properties["DeviceId"];
                string deviceSas     = configuration.Properties["DeviceSas"];
                string iotHubAddress = configuration.Properties["IotHubAddress"];
                int    iotHubPort    = Int32.Parse(configuration.Properties["IotHubPort"]);

                // init mqtt client
                _mqttclient = new uPLibrary.Networking.M2Mqtt.MqttClient(iotHubAddress, iotHubPort, true, MqttSslProtocols.TLSv1_2);
                _mqttclient.ConnectionClosed += MqttclientOnConnectionClosed;
                _mqttclient.Connect(_deviceid, $"{iotHubAddress}/{_deviceid}/api-version=2016-11-14", deviceSas);
                _mqttclient.Subscribe(new[] { $"devices/{_deviceid}/messages/devicebound/#" }, new byte[] { 0 });
                _mqttclient.Subscribe(new[] { "$iothub/methods/POST/#" }, new byte[] { 0 });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                //TODO Log
            }
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            // create client instance
            uPLibrary.Networking.M2Mqtt.MqttClient client = new uPLibrary.Networking.M2Mqtt.MqttClient(Properties.Settings.Default.BrokerIP);

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            string clientId = Guid.NewGuid().ToString();

            client.Connect(clientId);

            // subscribe to the topic "/home/temperature" with QoS 2
            client.Subscribe(new string[] { "#" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
            //client.Publish("ct/1/temp", Encoding.UTF8.GetBytes("20"));
        }
Beispiel #16
0
        public static void FireEvent()
        {
            var client = new MqttClient("mqtt.bconimg.com");

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            var clientId = Guid.NewGuid().ToString();

            client.Connect(clientId);

            // subscribe to the topic "/home/temperature" with QoS 2
            client.Subscribe(
                new string[] { "merge01" },
                new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            // create client instance
            MqttClient client = new MqttClient(IPAddress.Parse("54.94.232.13"));
            client.ProtocolVersion = MqttProtocolVersion.Version_3_1;

            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId, "hack", "12345");

            string[] topic = { "presenca" };
            byte[] qosLevels = { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE };
            client.Subscribe(topic, qosLevels);

            client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;

            Console.WriteLine("Aguardando requisições...");
        }
        public MainPage()
        {
            this.InitializeComponent();

            disconnected();

            _mqtt = new MqttClient("m11.cloudmqtt.com", 12360, false, MqttSslProtocols.None);
            _mqtt.ConnectionClosed += (sender, args) => { disconnected(); };
            _mqtt.MqttMsgSubscribed += (sender, args) =>
            {
                connected();
            };
            _mqtt.MqttMsgPublishReceived += (sender, args) =>
                            {
                var msg = Encoding.ASCII.GetString(args.Message);

                switch (msg)
                {
                    case "happy":
                        {
                        }
                        break;
                    case "sad":
                    {
                    }
                        break;
                    case "indifferent":
                        {
                        }
                        break;
                }
            };

            Task.Run(() =>
            {
                try
                {
                    _mqtt.Connect("1", "mike", "cloudmqtt");
                    _mqtt.Subscribe(new[] {"mqttdotnet/pubtest/#"}, new[] {MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE});
                }
                catch (Exception ex)
                {

                }
            });
        }
        static void Main(string[] args)
        {
            try
            {
                    MqttClient client = new MqttClient("172.30.28.5");

                    client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

                    string clientId = Guid.NewGuid().ToString();
                    client.Connect(clientId);

                    //client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
                    client.Subscribe(new string[] { "/home/temperature" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
            }
            catch(Exception ex)
            {
                Console.WriteLine("Failed to connect: " + ex.Message);
            }
        }
Beispiel #20
0
        /// <summary>
        /// The inputManager, this class manages the connection to the broker.
        /// </summary>
        /// <param name="_sAddress"></param>
        public InputManager(string _sAddress)
	    {
            // initialize the parser.
            parser = new DataParser();
            databaseManager = new DatabaseManagment.DbManager();

            try
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(_sAddress);
                Console.WriteLine(hostEntry);
                string hostname = hostEntry.HostName;
                Client = new MqttClient(hostname, 8883, false, null, null, MqttSslProtocols.None);
            }
            catch (Exception e)
            {
                Program.Log(e.Message);
                Client = new MqttClient(IPAddress.Parse(_sAddress), 8883, false, null, null, MqttSslProtocols.None);
            }

            // setup of the client.
            Client.ConnectionClosed += Client_ConnectionClosed;
            Client.MqttMsgSubscribed += Client_MqttMsgSubscribed;
            Client.MqttMsgPublishReceived += MessageReceived;
            Client.ProtocolVersion = MqttProtocolVersion.Version_3_1_1;
            byte response = Client.Connect(Guid.NewGuid().ToString());
            
            // check if the connection is made else print the problem and return.
            if (Client.IsConnected)
            {
                Connected = true;
                Console.WriteLine("The connection is made " + response);
            }
            else
            {
                Program.Log("The connection is not made, the return code is : " + response);
                return;
            }
            Client.Subscribe(subjects, qosLevels);


	    }
Beispiel #21
0
        static void Main(string[] args)
        {
            string AppEUI = @"70B3D57ED0000538"; // TODO: make configurable
            string AccessKey = @"Dj8ebO/p+agcxgKoRMmF0rKd07X7m4idj+M6HiS48EY="; // TODO: make configurable

            string username = AppEUI;
            string password = AccessKey;

            string mqttBrokerHostName = "rene-ttn-test"; // TODO: make configurable
                                                         // TODO: use TLS

            Console.WriteLine("starting up...");
            MqttClient client = new MqttClient(mqttBrokerHostName); // TODO: add error handling!

            // Register event handler for Connection being closed
            client.ConnectionClosed += client_ConnectionClosed;

            // register event handler for received messages
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            // Register event handler for subscription
            client.MqttMsgSubscribed += client_MqttMsgSubscribed;

            string clientId = "RSTest";
            client.Connect(clientId, username, password);   // TODO: add error handling

            // subscribe to the topic ( all Applications, all Devices
            client.Subscribe(new string[] { @"+/devices/+/up" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

            Console.WriteLine("Press <Enter> to quit");
            Console.ReadLine();

            // Remove event handler for Connection being closed
            client.ConnectionClosed -= client_ConnectionClosed;
            client.Disconnect();

            Console.WriteLine("Ended!");
        }
        static void Main(string[] args)
        {
            using (_bus = BusFactory.GetBus())
            {
                MqttClient client = new MqttClient("localhost");

                string clientId = Guid.NewGuid().ToString();
                client.Connect(clientId, "administrator", "password");

                client.Subscribe(new[]
                {
                    Topics.Humidity,
                    Topics.Temperature
                }, new[]
                {
                    MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE,
                    MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE
                });
                client.MqttMsgPublishReceived += ClientOnMqttMsgPublishReceived;

                Console.ReadKey();
            }
        }
        public void Start()
        {
            try
            {
                _client = new MqttClient(Uri);
                _client.MqttMsgPublishReceived += MqttMsgPublishReceived;

                _client.Connect("Plant1", UserName, Password);

                // Connect with a will to post if we become disconnected.
                //_client.Connect("Plant1", UserName, Password, false, 0, true, "/Tinamous/V1/Status", "Sprinker down!", true, 60);

                if (_client.IsConnected)
                {
                    Debug.Print("Connected to Tinamous MQTT service");
                    _client.Subscribe(new[] { "/Tinamous/V1/Status.To/Sprinkler" }, new byte[] { 0 });
                    PostStatus("Sprinkler Alive!");
                }
            }
            catch (Exception ex)
            {
                Debug.Print("Failed to connect to MQTT service." + ex.Message);
            }
        }
Beispiel #24
0
 public static void Main()
 {
     Console.WriteLine("aXon Robotics Server Version 1.0");
     Console.WriteLine("Processing Startup");
     bool connected = false;
     while (connected == false)
     {
         try
         {
             Console.WriteLine("Connecting to MQTT Server!");
             Client = new MqttClient(IPAddress.Parse("192.168.1.19"));
             byte code = Client.Connect("aXon");
             Client.Subscribe(new[] {"/RXAUTH", "/testRX"},
                              new[] {MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE});
             Client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
             connected = true;
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     Console.ReadLine();
 }
Beispiel #25
0
        private void ConnectToMQTT()
        {
            string serverAddress = AppSettings.Default.server;
            int port = Convert.ToInt32(AppSettings.Default.port);

            client = new MqttClient(IPAddress.Parse(serverAddress), port, false, null, MqttSslProtocols.None);

            log.Info("Connecting to MQTT Broker at " + serverAddress + ":" + port);

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            try
            {
                client.Connect(Guid.NewGuid().ToString());
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message,ex.Message);
                log.Error(ex.InnerException.Message + " - " + ex.Message);
            }

            // subscribe to all topics
            client.Subscribe(new string[] { "#" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE});
        }
Beispiel #26
0
        public override async Task StartAsync()
        {
            try
            {
                mqtt = new MqttClient(HostSetting, Port, false, null);
                enabled = true;
                mqtt.MqttMsgPublishReceived += mqtt_MqttMsgPublishReceived;
                mqtt.ConnectionClosed += mqtt_ConnectionClosed;
                Connect();

                var pubTopic = this.ControlTopicFormat;
                mqtt.Subscribe(new string[] {pubTopic}, new byte[] {0});
                await Publish(FloodTopic, "zVirtualScenes Connected");



            }
            catch (Exception e)
            {
                Log.ReportErrorAsync(e.Message, CancellationToken);
            }
            await Log.ReportInfoFormatAsync(CancellationToken, "{0} started", Name);
            NotifyEntityChangeContext.ChangeNotifications<DeviceValue>.OnEntityUpdated += Plugin_OnEntityUpdated;
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            // create client instance
            uPLibrary.Networking.M2Mqtt.MqttClient client = new uPLibrary.Networking.M2Mqtt.MqttClient(Properties.Settings.Default.BrokerIP);

            // register to message received
            client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);

            // subscribe to the topic "/home/temperature" with QoS 2
            client.Subscribe(new string[] { "#" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
            //client.Publish("ct/1/temp", Encoding.UTF8.GetBytes("20"));
        }
        void StartMqtt()
        {
            #if MF_FRAMEWORK_VERSION_V4_3
            Debug.GC(true);
            #endif
            bool networkReset = false;
            if (!connected) { return; }

            // give the network some settle time
            Util.Delay(networkSettleTime);

            while (mqtt == null || !mqtt.IsConnected) {
                networkReset = false;
                while (!networkAvailable) {
                    Util.Delay(2000);
                    networkReset = true;
                }
                // the network needs a bit of settle time, dhcp etc
                if (networkReset) { Util.Delay(networkSettleTime); }

                mqtt = new MqttClient(serviceAddress);
                if (mqtt != null && networkAvailable) { mqtt.Connect(clientId); }

            }

            mqtt.MqttMsgPublishReceived += mqtt_MqttMsgPublishReceived;
            mqtt.Subscribe(ConfigurationManager.MqqtSubscribe, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE });
        }
Beispiel #29
0
 void ListenWayPointsTask()
 {
     Mq = new MqttClient(PilotString);
     Trace.t(cc.Norm, string.Format("listenWayPointsTask, connecting to MQTT @ {0}", PilotString));
     Mq.Connect("MM1");
     Trace.t(cc.Norm, "listenWayPointsTask connected");
     Mq.MqttMsgPublishReceived += PublishReceived;
     Mq.Subscribe(new string[] { "Navplan/WayPoints" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
 }
        private void initMqtt()
        {
            client = new MqttClient(MQTT_BROKER_ADDRESS);
            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);
            //subscribe
            client.MqttMsgPublishReceived += async (sender, e) =>
            {

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var gpio = GpioController.GetDefault();
                    // Show an error if there is no GPIO controller
                    if (gpio == null)
                    {
                        GpioStatus.Text = "There is no GPIO controller on this device.";
                        return;
                    }
                    string Message = new string(Encoding.UTF8.GetChars(e.Message));
                    if (Message.IndexOf(":") < 1) return;
                   // handle message received 
                   TxtMsg.Text = "Message Received : " + Message;
                   //switch gpio state
                   string[] pinItem = Message.Split(':');
                    int pinsel = Convert.ToInt32(pinItem[0]);
                    GpioPinValue state = pinItem[1] == "True" ? GpioPinValue.High : GpioPinValue.Low;
                    if (pins.ContainsKey(pinsel)) {
                        pins[pinsel].Write(state);
                    }
                    else {
                        var pin = gpio.OpenPin(pinsel);
                        pin.Write(state);
                        pin.SetDriveMode(GpioPinDriveMode.Output);
                        pins.Add(pinsel, pin);
                    }
                    devices[pinsel] = (state == GpioPinValue.High ? true : false);
                    GpioStatus.Text = string.Format("PIN {0} -> {1}", pinsel, state == GpioPinValue.High ? "ON" : "OFF");

                });
            };
            client.Subscribe(new string[] { "/raspberry/control" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE });

        }