예제 #1
0
        public Task Publish(CommandModel command)
        {
            var message = new MqttApplicationMessageBuilder()
                          .WithTopic("BOILER_COMMAND/JSON")
                          .WithPayload(JsonConvert.SerializeObject(command))
                          .Build();

            return(mqttClientService.PublishAsync(message, CancellationToken.None));
        }
예제 #2
0
    public Task PublishAsync(string exchange, string typeName, byte[] body,
                             CancellationToken cancellationToken = default)
    {
        var msg = new MqttApplicationMessage
        {
            Topic       = exchange,
            ContentType = typeName,
            Payload     = body
        };

        return(_mqttClientService.PublishAsync(msg));
    }
        public async Task <string> ScheduleAsync(EmailMessage message, CancellationToken cancellationToken)
        {
            var context = _httpContextAccessor.HttpContext;

            if (context is null)
            {
                throw new InvalidOperationException($"Email scheduler is being invoked outside of request context.");
            }
            if (!context.User.Identity.IsAuthenticated)
            {
                throw new UnauthorizedException();
            }
            var owner = context.User.FindFirstValue(OAuth2ClaimTypes.Ownership);

            if (string.IsNullOrEmpty(owner))
            {
                throw new ForbiddenException($"Current user does not specify ownership.");
            }
            var messageId = await _mqttClientService.PublishAsync(new EmailMessageTask(message, owner), cancellationToken);

            return(messageId.HasValue ? messageId.Value.ToString() : string.Empty);
        }
예제 #4
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);
        }
예제 #5
0
 public async Task PublishAsync(string topic, string payload)
 {
     await _mqttClientService.PublishAsync(topic, payload);
 }
예제 #6
0
 public async Task PublishToMqttBroker(string topic, string payload)
 {
     await mqttClientService.PublishAsync(topic, payload);
 }
 public Task SendMessageToTopic([FromBody] string payload)
 {
     return(_mqttClient.PublishAsync(payload));
 }
예제 #8
0
        public void CatchThief()
        {
            AddMessageToConsole(Me, "Sending catch thief signal.");

            m_MqttClient.PublishAsync("suitceyes/kyd/CatchThief");
        }