Beispiel #1
0
        public bool Unsubscribe(MqttMessage mqttMessage)
        {
            if (_client == null)
            {
                return(false);
            }

            mqttMessage.SetMessageType(MqttMessage.MqttMessageType.MQTT_UNSUBSCRIBE);

            if (!mqttMessage.sendImmediately)
            {
                _client.QueueMessage(mqttMessage.UnsubscribeMessage);
                _sensorManager.UnmapTopicToSensor(mqttMessage, this);
                return(true);
            }

            var success = _client.Unsubscribe(mqttMessage);

            Log.Verbose($"[{SensorIdentifier}] unsubscribing to [{mqttMessage.GetRawTopic()}] ({success})");

            if (success.messageId > 0)
            {
                _sensorManager.UnmapTopicToSensor(mqttMessage, this);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public bool Publish(MqttMessage mqttMessage)
        {
            if (_client == null)
            {
                return(false);
            }

            mqttMessage.SetMessageType(MqttMessage.MqttMessageType.MQTT_PUBLISH);

            if (!mqttMessage.sendImmediately)
            {
                _client.QueueMessage(mqttMessage.PublishMessage);
                return(true);
            }

            Log.Verbose($"[{SensorIdentifier}] publishing to [{mqttMessage.GetRawTopic()}]: [{mqttMessage.message}]");

            var success = _client.Publish(mqttMessage);

            if (success.messageId > 0)
            {
                return(true);
            }

            return(false);
        }