title: sending a message to an Azure Iot hub
body: <p>I'm a beginner to AzureIot, I've been given access to an azure account which has an IOT hub.
  from the azure portal I see a connection string of the form:
  <code>HostName=iothub-mycompany.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=_somekey_in_base64_</code></p>
  
  <p>Now all I need is to simply <strong>send a JSON payload to this IOT hub</strong>. Any protocol would do.</p>
  
  <p>I was <strong>assuming</strong> that when I send a message I can see this message with the <a href="https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer" rel="nofollow noreferrer">this device explorer tool</a>. but I'm not sure if I'm doing something wrong or perhaps there is a flaw in my understanding.</p>
  
  <p>I tried examples from blogs, msdn etc In the end I've come up with the code below</p>
  
  <p>It runs, however I have no clue what it's doing and <strong>where to look for whether this message was sent</strong>.</p>
  
  <ul>
  <li><p>The Device explorer shows nothing.</p></li>
  <li><p>I checked the Activity Login portal.azure.com but it seems more like a login activity log.</p></li>
  <li>Also in the azure portal Under explorers I See Iot Devices. I see the device name I need to target.(I know it exists)</li>
  </ul>
  
  <p>Here is the code, part of .Net4.5.2 ConsoleApplication.</p>
  
  <p><code>Program.cs</code>:</p>
  
  <pre><code>class Program
  {
      static DeviceClient deviceClient;
      const string IOT_HUB_CONN_STRING = "connection str in format specified above.";
      const string IOT_HUB_DEVICE_LOCATION = "_some_location.";
      const string IOT_HUB_DEVICE = "device_id";
  
      static void Main(string[] args)
      {
          var ret = SendMessageToIoTHubAsync("temperature", 15);
  
  
          Console.WriteLine("completed:" + ret.IsCompleted);
  
  
      }
      private static async Task SendMessageToIoTHubAsync(string sensorType, int sensorState)
      {
          deviceClient = DeviceClient.CreateFromConnectionString(IOT_HUB_CONN_STRING, TransportType.Mqtt);//i tried other trsnsports
          try
          {
              var payload = "{" +
                  "\"deviceId\":\"" + IOT_HUB_DEVICE + "\", " +
                  "\"location\":\"" + IOT_HUB_DEVICE_LOCATION + "\", " +
                  "\"sensorType\":\"" + sensorType + "\", " +
                  "\"sensorState\":" + sensorState + ", " +
                  "\"localTimestamp\":\"" + DateTime.Now.ToLocalTime() + "\"" +
                  "}";
  
              var msg = new Message(Encoding.UTF8.GetBytes(payload));
  
              Debug.WriteLine("\t{0}&gt; Sending message: [{1}]", DateTime.Now.ToLocalTime(), payload);
  
              await deviceClient.SendEventAsync(msg);
          }
          catch (Exception ex)
          {
              System.Diagnostics.Debug.WriteLine("!!!! " + ex.Message);
          }
      }
  }
  </code></pre>
  
  <p>As a side note, my "device" is <a href="http://software.schneider-electric.com/products/clearscada/" rel="nofollow noreferrer">ClearScada</a>. I will have C# Driver which will get data out of a ClearScada instance, this driver should send that data to the azure iot hub. <sub>essentially I just need to figure the sending from C#
   to Azure iot.</sub>
  <strong>Questions:</strong></p>
  
  <ul>
  <li>Where Can I see my messages.? </li>
  <li>Is my function correct or is there a flaw in my understanding.</li>
  </ul>