private void NodePropertyHandler(SubscriptionMessage message) { var topic = message.Topic.Replace(MQTTRootTopicLevel, ""); if (ProccessMQTTMessageForNodeProperties(topic, message.Message)) { message.Seen = true; } }
private void AddMessage(SubscriptionMessage message) { var id = Guid.NewGuid(); while (!Messages.TryAdd(id, message)) { Thread.Sleep(100); } ; }
public void DeviceTopicHandler(SubscriptionMessage message) { var deviceRootTopic = message.Topic.Replace("/$homie", ""); if (Devices.Find(device => device.MQTTRootTopicLevel == deviceRootTopic) == null) { var device = ServiceProvider.GetService <HomieDevice>(); device.Setup(deviceRootTopic); Devices.Add(device); } }
private void DeviceNodeHandler(SubscriptionMessage message) { var nodeRootTopic = message.Topic.Replace("/$type", ""); var nodeID = nodeRootTopic.Replace(MQTTRootTopicLevel + "/", ""); if (Nodes.Find(node => node.MQTTRootTopicLevel == nodeRootTopic) == null) { var node = new DeviceNode(nodeRootTopic, nodeID, MQTTManager); node.ChangeEvent += OnNodeChange; node.PropertyChangeEvent += OnNodePropertyChange; Nodes.Add(node); } }
public async Task <SubscriptionMessage> WaitForMessage(string topicRegex, TimeSpan timeout = default, bool doSee = true) { if (timeout.Ticks == 0) { timeout = TimeSpan.FromSeconds(10); } SubscriptionMessage message = null; AddListner(new Listener(topicRegex, (msg) => { message = msg; }, true, doSee)); return(await Task.Run(async() => { var start = DateTime.Now; while (message == null && (DateTime.Now - start) < timeout) { await Task.Delay(100); } return message; })); }