Exemple #1
0
        // обновление документа
        public async Task UpdateFromUIAsync(Client client, Device device)
        {
            if (device.TypeOfDevice == "Light")
            {
                if (ConnectSingleton.IsConnected == false)
                {
                    await _mqttClientService.ConnectAsync(client.Id);

                    await _mqttClientService.SubscribeAsync(device.Topic);

                    ConnectSingleton.getInstance(true);
                }
                var messagePayload = new MqttApplicationMessageBuilder()
                                     .WithTopic(device.Topic)
                                     .WithPayload(device.Payload)
                                     .WithExactlyOnceQoS()
                                     .WithRetainFlag()
                                     .Build();
                await _mqttClientService.PublishAsync(messagePayload);
            }
            await Devices.ReplaceOneAsync(new BsonDocument("_id", new ObjectId(device.Id)), device);
        }
Exemple #2
0
 public async Task Subscribe(string topic)
 {
     await _mqttClientService.SubscribeAsync(topic);
 }