/// <summary>
 /// Constructs a PublishArrivedArgs object
 /// </summary>
 /// <param name="topic">Source of message</param>
 /// <param name="payload">Message body</param>
 /// <param name="retained">Whether or not the message is retained</param>
 public PublishArrivedArgs(string topic, MqttPayload payload, bool retained, QoS qos)
 {
     _topic    = topic;
     _payload  = payload;
     _retained = retained;
     _qos      = qos;
 }
Example #2
0
 public void Connect(string willTopic, QoS willQoS, MqttPayload willMsg, bool willRetain, bool cleanStart)
 {
     _keepAlive = 60;
     DoConnect(new MqttConnectMessage(
                   _clientID, _username, _password, _keepAlive, willTopic, willMsg.TrimmedBuffer, willQoS, willRetain, cleanStart
                   ));
 }
Example #3
0
        public int Publish(string topic, MqttPayload payload, QoS qos, bool retained)
        {
            _keepAlive = 60;

            if (manager.IsConnected)
            {
                // Reset the PINGREQ timer as this publish will reset the server's counter
                if (keepAliveTimer != null)
                {
                    int kmillis = 1000 * _keepAlive;
                    keepAliveTimer.Change(kmillis, kmillis);
                }
                ushort messID = MessageID;
                manager.SendMessage(new MqttPublishMessage(messID, topic, payload.TrimmedBuffer, qos, retained));
                return(messID);
            }
            else
            {
                throw new MqttNotConnectedException("You need to connect to a broker before trying to Publish");
            }
        }