Example #1
0
        public string subscribe(string uid, string topic_filter, Action <PythonDictionary> callback)
        {
            if (topic_filter == null)
            {
                throw new ArgumentNullException(nameof(topic_filter));
            }
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            return(_mqttService.Subscribe(uid, topic_filter, message =>
            {
                var pythonMessage = new PythonDictionary
                {
                    ["client_id"] = message.ClientId,
                    ["topic"] = message.ApplicationMessage.Topic,
                    ["payload"] = message.ApplicationMessage.Payload,
                    ["qos"] = (int)message.ApplicationMessage.QualityOfServiceLevel,
                    ["retain"] = message.ApplicationMessage.Retain
                };

                callback(pythonMessage);
            }));
        }
Example #2
0
        public DeviceRegistryService(MqttService mqttService, ILogger <DeviceRegistryService> logger)
        {
            _mqttService = mqttService ?? throw new ArgumentNullException(nameof(mqttService));
            _logger      = logger ?? throw new ArgumentNullException(nameof(logger));

            _mqttService.Subscribe(null, "$wirehome/devices/+/report/+", OnPropertyReportedViaMqtt);
        }