Exemplo n.º 1
0
        public OutpostLpdBridgeAdapter(string id, string deviceName, IDeviceMessageBrokerService deviceMessageBroker)
        {
            _deviceName          = deviceName ?? throw new ArgumentNullException(nameof(deviceName));
            _deviceMessageBroker = deviceMessageBroker ?? throw new ArgumentNullException(nameof(deviceMessageBroker));

            Id = id ?? throw new ArgumentNullException(nameof(id));
            _deviceMessageBroker.Subscribe(OutpostTopicBuilder.BuildNotificationTopic(deviceName, "LPD/Received"), OnLpdCodeReceived);
        }
Exemplo n.º 2
0
        public INumericSensorAdapter CreateDhtHumiditySensorAdapter(string deviceName)
        {
            if (deviceName == null)
            {
                throw new ArgumentNullException(nameof(deviceName));
            }

            var topic = OutpostTopicBuilder.BuildNotificationTopic(deviceName, "DHT/Humidity");

            return(new MqttBasedNumericSensorAdapter(topic, _deviceMessageBroker, _logService));
        }
        public static void PublishDeviceMessage(this IDeviceMessageBrokerService deviceMessageBrokerService, string deviceId, string notificationId, string payload)
        {
            if (deviceMessageBrokerService == null)
            {
                throw new ArgumentNullException(nameof(deviceMessageBrokerService));
            }
            if (deviceId == null)
            {
                throw new ArgumentNullException(nameof(deviceId));
            }
            if (notificationId == null)
            {
                throw new ArgumentNullException(nameof(notificationId));
            }

            var topic = OutpostTopicBuilder.BuildNotificationTopic(deviceId, notificationId);

            deviceMessageBrokerService.Publish(topic, Encoding.UTF8.GetBytes(payload), MqttQosLevel.AtMostOnce);
        }