Пример #1
0
        public async Task <IActionResult> Publish([Required] string deviceName, [Required] string action, string payload)
        {
            try
            {
                Log.Information($"Publish deviceName: {deviceName} action: {action} payload: {payload}");
                var mqttTopic = $"{deviceName}/{action}";
                await _mqttService.PublishAsync(mqttTopic, payload);

                Log.Information($"Publish success (topic: {mqttTopic})");

                return(Ok(mqttTopic));
            }
            catch (Exception e)
            {
                Log.Error($"Publish error", e);
                return(StatusCode(500, "Publish error, see log"));
            }
        }