Beispiel #1
0
        private void Client_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            try
            {
                switch (e.Topic)
                {
                case MqttTopic.RegisterTopic:
                    SmartLockRegister smartLock = new SmartLockRegister(e.Message);
                    byte[]            resArray  = smartLock.PackageResponse();
                    MqttClient        client    = (MqttClient)sender;
                    string            resTopic  = MqttTopic.GetClientTopic("SYS", smartLock.SmartLockClient.IotID, "REG");
                    client.Publish(resTopic, resArray);
                    break;

                case MqttTopic.EventTopic:
                    SmartLockDataPackage dataPackage = new SmartLockDataPackage(e.Message);
                    break;

                case MqttTopic.RespondTopic:
                    break;

                case MqttTopic.DataTopic:
                    break;
                }
            }
            catch (Exception ex)
            {
                MqttErroEventArgs eventArgs = new MqttErroEventArgs((sender as MqttClient).ClientId, ex.Message);
                RaiseMqttErroOccurred(eventArgs);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Represents an MQTT topic with Physical Quantity data.
 /// </summary>
 public QuantityData(MqttTopic Topic, double Value, byte NrDecimals, string Unit)
     : base(Topic)
 {
     this.value      = Value;
     this.nrDecimals = NrDecimals;
     this.unit       = Unit;
 }
        /// <summary>
        /// Returns true if OgcDataStreamInfo instances are equal
        /// </summary>
        /// <param name="other">Instance of OgcDataStreamInfo to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OgcDataStreamInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     DataStreamId == other.DataStreamId ||
                     DataStreamId != null &&
                     DataStreamId.Equals(other.DataStreamId)
                     ) &&
                 (
                     MqttTopic == other.MqttTopic ||
                     MqttTopic != null &&
                     MqttTopic.Equals(other.MqttTopic)
                 ) &&
                 (
                     MqttServer == other.MqttServer ||
                     MqttServer != null &&
                     MqttServer.Equals(other.MqttServer)
                 ) &&
                 (
                     ExternalId == other.ExternalId ||
                     ExternalId != null &&
                     ExternalId.Equals(other.ExternalId)
                 ) &&
                 (
                     Metadata == other.Metadata ||
                     Metadata != null &&
                     Metadata.Equals(other.Metadata)
                 ) &&
                 (
                     SensorType == other.SensorType ||
                     SensorType != null &&
                     SensorType.Equals(other.SensorType)
                 ) &&
                 (
                     UnitOfMeasurement == other.UnitOfMeasurement ||
                     UnitOfMeasurement != null &&
                     UnitOfMeasurement.Equals(other.UnitOfMeasurement)
                 ) &&
                 (
                     fixedLatitude == other.fixedLatitude ||
                     fixedLatitude != null &&
                     fixedLatitude.Equals(other.fixedLatitude)
                 ) && (
                     fixedLongitude == other.fixedLongitude ||
                     fixedLongitude != null &&
                     fixedLongitude.Equals(other.fixedLongitude)
                     ));
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (DataStreamId != null)
         {
             hashCode = hashCode * 59 + DataStreamId.GetHashCode();
         }
         if (MqttTopic != null)
         {
             hashCode = hashCode * 59 + MqttTopic.GetHashCode();
         }
         if (MqttServer != null)
         {
             hashCode = hashCode * 59 + MqttServer.GetHashCode();
         }
         if (ExternalId != null)
         {
             hashCode = hashCode * 59 + ExternalId.GetHashCode();
         }
         if (Metadata != null)
         {
             hashCode = hashCode * 59 + Metadata.GetHashCode();
         }
         if (SensorType != null)
         {
             hashCode = hashCode * 59 + SensorType.GetHashCode();
         }
         if (UnitOfMeasurement != null)
         {
             hashCode = hashCode * 59 + UnitOfMeasurement.GetHashCode();
         }
         if (fixedLatitude != null)
         {
             hashCode = hashCode * 59 + fixedLatitude.GetHashCode();
         }
         if (fixedLongitude != null)
         {
             hashCode = hashCode * 59 + fixedLongitude.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #5
0
        public async Task SendCloudToDeviceMessage(string topicKey, string payload, CancellationToken stopToken)
        {
            MqttTopic topic = null;

            cloudToDevicePublishingTopics.TryGetValue(topicKey, out topic);

            if (topic != null)
            {
                logger.LogInformation($"Cloud to device message for mqtt device {downstreamClientCredentials.ClientId} on topic {topic.Topic}");

                await PublishMessage(downstreamClient, topic.Topic, payload, null, stopToken);
            }
            else
            {
                logger.LogError($"Unexpected topic key {topicKey} for mqtt device {downstreamClientCredentials.ClientId}");
            }
            await Task.CompletedTask;
        }
Beispiel #6
0
 /// <summary>
 /// Represents an MQTT topic with JSON-encoded data.
 /// </summary>
 public JsonData(MqttTopic Topic, string Json, object Value)
     : base(Topic)
 {
     this.json  = Json;
     this.value = Value;
 }
Beispiel #7
0
 /// <summary>
 /// Represents an MQTT topic with boolean data.
 /// </summary>
 public BooleanData(MqttTopic Topic, bool Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #8
0
 /// <summary>
 /// Represents an MQTT topic with time span data.
 /// </summary>
 public TimeSpanData(MqttTopic Topic, TimeSpan Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #9
0
 public Data(MqttTopic Topic)
 {
     this.topic = Topic;
 }
Beispiel #10
0
 /// <summary>
 /// Represents an MQTT topic with GUID data.
 /// </summary>
 public GuidData(MqttTopic Topic, Guid Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #11
0
 /// <summary>
 /// Represents an MQTT topic with XML data.
 /// </summary>
 public XmlData(MqttTopic Topic, string Xml, XmlDocument Value)
     : base(Topic)
 {
     this.xml   = Xml;
     this.value = Value;
 }
Beispiel #12
0
 /// <summary>
 /// Represents an MQTT topic with integer data.
 /// </summary>
 public IntegerData(MqttTopic Topic, long Value)
     : base(Topic)
 {
     this.value = Value;
 }
 /// <summary>
 /// Represents an MQTT topic with Floating-point data.
 /// </summary>
 public FloatingPointData(MqttTopic Topic, double Value, byte NrDecimals)
     : base(Topic)
 {
     this.value      = Value;
     this.nrDecimals = NrDecimals;
 }
 /// <summary>
 /// Represents an MQTT topic with Date &amp; Time &amp; Offset data.
 /// </summary>
 public DateTimeOffsetData(MqttTopic Topic, DateTimeOffset Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #15
0
 /// <summary>
 /// Represents an MQTT topic with binary data encoded as decimal strings.
 /// </summary>
 public HexStringData(MqttTopic Topic, byte[] Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #16
0
 /// <summary>
 /// Represents an MQTT topic with base64-encoded binary data.
 /// </summary>
 public Base64Data(MqttTopic Topic, byte[] Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #17
0
 /// <summary>
 /// Represents an MQTT topic with Duration data.
 /// </summary>
 public DurationData(MqttTopic Topic, Duration Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #18
0
 /// <summary>
 /// Represents an MQTT topic with string data.
 /// </summary>
 public StringData(MqttTopic Topic, string Value)
     : base(Topic)
 {
     this.value = Value;
 }
Beispiel #19
0
 /// <summary>
 /// Represents an MQTT topic with Date &amp; Time data.
 /// </summary>
 public DateTimeData(MqttTopic Topic, DateTime Value)
     : base(Topic)
 {
     this.value = Value;
 }