Пример #1
0
        public void Start()
        {
            // create client instance
            client = new MqttClient(Global.mqtt_address);

            // 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[] { Global.mqtt_prefix + "/cmd/#" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });

            Event.WriteInfo("MqttServer", " Mqtt Subsribe to " + Global.mqtt_prefix + "/cmd/# at " + Global.mqtt_address);
        }
Пример #2
0
        public void Start()
        {
            Uri uri = new Uri("http://0.0.0.0:" + Global.webapi_port + "/");

            host = new WebServiceHost(typeof(HAIService), uri);

            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IHAIService), new WebHttpBinding(), "");
                host.Open();

                Event.WriteInfo("WebService", "Listening on " + uri.ToString());
            }
            catch (CommunicationException ex)
            {
                Event.WriteError("WebService", "An exception occurred: " + ex.Message);
                host.Abort();
            }
        }