Exemplo n.º 1
0
        public Task SetState(AdapterPowerState powerState, AdapterColor color, params IHardwareParameter[] hardwareParameters)
        {
            if (!SupportsColor && color != null)
            {
                throw new InvalidOperationException("Color is not supported by adapter.");
            }

            var r = 0;
            var g = 0;
            var b = 0;

            if (powerState == AdapterPowerState.On && color == null)
            {
                r = 1023;
                g = 1023;
                b = 1023;
            }
            else if (powerState == AdapterPowerState.On && color != null)
            {
                r = color.Red;
                g = color.Green;
                b = color.Blue;
            }

            var topic = OutpostTopicBuilder.BuildCommandTopic(_deviceName, "RGB/Set");
            var json  = new JObject
            {
                ["r"] = r,
                ["g"] = g,
                ["b"] = b
            };

            _deviceMessageBroker.Publish(topic, json, MqttQosLevel.AtMostOnce);
            return(Task.FromResult(0));
        }
Exemplo n.º 2
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.º 3
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));
        }
Exemplo n.º 4
0
        public void SendCode(Lpd433MhzCode code)
        {
            var topic = OutpostTopicBuilder.BuildCommandTopic(_deviceName, "LPD/Send");
            var json  = new JObject
            {
                ["value"]    = code.Value,
                ["length"]   = code.Length,
                ["protocol"] = code.Protocol,
                ["repeats"]  = code.Repeats
            };

            _deviceMessageBroker.Publish(topic, json, MqttQosLevel.AtMostOnce);
        }
        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);
        }