初始化
This commit is contained in:
29
iotweb/Controllers/ValuesController.cs
Normal file
29
iotweb/Controllers/ValuesController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MQTTnet.Server;
|
||||
namespace iotweb.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
private readonly MqttServer _mqttServer;
|
||||
|
||||
public ValuesController(MqttServer mqttServer)
|
||||
{
|
||||
_mqttServer = mqttServer;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet()]
|
||||
public async Task<IActionResult> GetConnectedClients()
|
||||
{
|
||||
var clients = await _mqttServer.GetClientsAsync();
|
||||
return Ok(clients.Select(c => new
|
||||
{
|
||||
Id = c.Id,
|
||||
Endpoint = c.Endpoint
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
33
iotweb/Controllers/WeatherForecastController.cs
Normal file
33
iotweb/Controllers/WeatherForecastController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace iotweb.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user