初始化
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
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user