title: How can I connect to a broker using MQTT in MVC framework?
body: <p>I'm trying to set up an MQTT connection to a test broker: "test.mosquitto.org" in C# using MVC(this one is just for practise). Eventually I want to make a web application that collects and shows data from databases on different locations. There seem to be no tutorials for MVC framework so I'm following this example: <a href="https://gist.github.com/cwschroeder/7b5117dca561c01def041e7d4c6d2771" rel="nofollow noreferrer">https://gist.github.com/cwschroeder/7b5117dca561c01def041e7d4c6d2771</a>. </p>
  
  <p>The hard part for me is converting that example to MVC framework(with the controllers, models, etc.)</p>
  
  <p><strong>So I have a few questions about this:</strong></p>
  
  <ul>
  <li>Is there a better/easier option for this than MVC?</li>
  <li>What framework is used in the sample?</li>
  <li>What would be my first steps to set up a connecting to a broker in MVC?(also wondering if it would be possible to see an example in code)</li>
  </ul>
  
  <p>I already added some properties and a start + installed the M2mqtt library.
  No idea where to go from here. I wish I could just copy paste the sample but that is obviously not possible with MVC.   </p>
  
  <p><strong>MqttClientController</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using uPLibrary.Networking.M2Mqtt;
  using uPLibrary.Networking.M2Mqtt.Messages;
  using uPLibrary.Networking.M2Mqtt.Session;
  using MvcTestMqtt.Models;
  
  
  namespace MvcTestMqtt.Controllers
  {
      public class MqttClientController : Controller
      {
          // GET: MqttClient
          public ActionResult Index()
          {
  
              return View();
          }
  
          public ActionResult ConnectClient()
          {
              var mqtt = new MqttModel();
              new MqttClient(mqtt.BrokerAddress);
              new MqttClient(mqtt.clientID);
              return View();
          }
      }
  }
  </code></pre>
  
  <p><strong>MqttModel:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using uPLibrary.Networking.M2Mqtt;
  using uPLibrary.Networking.M2Mqtt.Messages;
  using MvcTestMqtt.Controllers;
  
  
  namespace MvcTestMqtt.Models
  {
      public class MqttModel
      {
          MqttClient client { get; set; }
          public string clientID { get; set; }
          public string BrokerAddress = "test.mosquitto.org";
      }
  }
  </code></pre>