Introduction: Thermal Analysis of Heat Exchanger Using Azure IoT Hub

About: For Remote Supervision

Heat exchanger considers one of the most common types of exchangers widely used in the industrial processes. This exchanger consists of a vessel with different sizes contains a number of tubes inside. The rate of transferred heat depends on several factors such as feed temperature and humidity, shell diameter, a number of tubes, tube geometry, baffle spacing and cutting spacing. So temperature analysis becomes very important in order to maintain the correct temperature in tubes and diagnose the faults in it. Correct measures taken can increase the fault tolerance of the device.

Wireless Sensor Networks has been installed in many industrial applications like structural monitoring of civil infrastructure, vibration analysis of hydro turbines etc. and has done remarkably well in irradicating many of the industrial complications.

In this Instructable we will be going through Wireless Temperature and Humidity Sensors and it's advantages in Thermal analysis of Heat exchanger. So here we will be demonstrating the following-

  • wireless temperature and Humidity Sensors.
  • Temperature analysis using these Sensors.
  • Gathering and analysing the data using Wireless gateway device
  • Publishing and Subscribing to Sensor data using Azure.

Step 1: Hardware and Software Specifications

Step 2: IoT Long Range Wireless Temperature Humidity Sensor

These are Industrial Grade Long Range Temperature and Humidity Sensors with a sensor resolution of ±1.7%RH ±0.6° C. Powered by just 2 AA batteries (included) with an operational lifetime of 500,000 wireless transmissions, you can expect to achieve up to 10 years of battery life depending on environmental conditions and the transmission interval can be chosen by you. Optionally, this sensor may be externally powered. These sensors have 2 Mile Range with On-Board Antenna. The range can be boasted up to 28 miles using mesh networking architecture.

Step 3: Getting the Temperature and Humidity Values

We are getting following values from the wireless Temperature and Humidity Sensors:

  • Temperature in Celcius
  • Temperature in Fahrenheit
  • Relative Humidity
  • Battery Usage

These data is then visualized and analyzed in Azure IoT hub. To get Started with setting up of Azure IoT Hub, Go through this tutorial. The following procedure is to be followed in order to send the values Azure IoT hub.

Azure IoT hub follows MQTT protocol in order to publish and subscribe the data.

  • Azure functions is another important feature provided by azure portal. Using Azure functions, we can write a piece of code or function in cloud. In this project we are parsing the JSON containing raw sensor data and getting the real temperature and Humidity values from it using Azure function. To set up Azure function follow this tutorial.
  • We will get the real temperature and humidity data using parsed JSON raw data

public static async Task Run(HttpRequestMessage req, TraceWriter log) { double humidity; int rawTemp; double Ctemp; double Ftemp; double voltage; string utcEnque; string devFormat; string utcProcess; log.Info("C# HTTP trigger function processed a request: " + content); JArray array = JArray.Parse($"{await req.Content.ReadAsStringAsync()}");

//parsing the JSON array foreach(dynamic message in array){ utcProcess = message.EventProcessedUtcTime; utcEnque = message.EventEnqueuedUtcTime; humidity = ((message.Humid1)*256 + (message.Humid2))/100; rawTemp = ((message.Temp1)*256 + (message.Temp2)); Ctemp = rawTemp /100.0; Ftemp = Ctemp *1.8 + 32; int bat = ((message.Bat1)*256 + (message.Bat2)); voltage = 0.00322 * bat; string utcTime = utcProcess.ToString(); DateTime localDateTime = DateTime.Parse(utcTime); DateTime utcDateTime = localDateTime.ToUniversalTime(); string usTimeZone = "US Eastern Standard Time"; TimeZoneInfo ust = TimeZoneInfo.FindSystemTimeZoneById(usTimeZone); DateTime dateTime = TimeZoneInfo.ConvertTime(utcDateTime, ust); log.Info(dateTime.ToString("dd/MM/yyyy HH:mm:ss")); }

return req.CreateResponse(HttpStatusCode.OK, "Executed");

}

public class Message { [JsonProperty("temp1")] public int temp1 { get; set; } [JsonProperty("temp2")] public int temp2 { get; set; } [JsonProperty("humid1")] public int humid1 { get; set; } [JsonProperty("humid2")] public int humid2 { get; set; } [JsonProperty("bat1")] public int bat1 { get; set; } [JsonProperty("bat2")] public int bat2 { get; set; } }

Step 4: Analyzing Data in PowerBi

We are using Power BI to visualize the data. It provides interactive ways to analyze data. This data can be interpreted in the form of Line charts, Bar graphs, Pie charts etc. Start by creating an account in Power Bi and sign in into your account. In the last post, we had set up Power Bi and sent data to Power Bi using stream analytics job. In this post, we are using Azure function to send the sensor data to power Bi. To set up Power Bi read this blog.

There are four methods to send the data to Power Bi:

  • Directly streaming the data to Power Bi from IoT hub.
  • Using API to send data to Power Bi.
  • Using web-hook functions
  • Using PubNub.

Here in our case we are using Power BI API and sending a HTTP response to Power BI from azure function. There are different graphs, line charts, Pi charts etc. listed in the Visualization panel. We can create the chart by selecting any of the graphs from the Visualization panel.

We can also export the data as an excel sheet or in CSV format. Which in later stages can be used for data analytics.

Azure Function Code for PowerBI

Parse all the JSON objects from the JSON, and get the real values of temperature, humidity, and others. Here the product is a Product class object where we are storing the parsed values.

Product product = new Product();

foreach(dynamic message in array){
humidity = ((message.humid1)*256 + (message.humid2))/100; rawTemp = ((message.temp1)*256 + (message.temp2)); Ctemp = rawTemp /100.0; Ftemp = Ctemp *1.8 + 32; int bat = ((message.bat1)*256 + (message.bat2)); voltage = 0.00322 * bat; utcProcess = message.EventProcessedUtcTime; utcEnque = message.EventEnqueuedUtcTime; product.Ctemperature = Ctemp; product.Ftemperature = Ftemp; product.humid = humidity; product.battery = voltage; //product.dateTime = ; product.EventProcessedUtcTime=utcProcess; product.EventEnqueuedUtcTime=utcEnque; }

public class Product{ public double Ctemperature{get; set;} public double humid{get; set;} public double battery{get; set;} //public double dateTime{get; set;} public string EventProcessedUtcTime { get; set; } public string EventEnqueuedUtcTime { get; set; } public double Ftemperature{get; set;} }


  • Now create a variable to store a connection string of Power Bi
  • Create an instance of HTTP client

string connString = "https://api.powerbi.com/beta/***************";
HttpClient client = new HttpClient();

  • We need to send JSON to power Bi. So, Serialize the Json using model class object.
  • Send the converted JSON to power bi as an HTTP request.

string output = JsonConvert.SerializeObject(product);
HttpContent httpContent = new StringContent("[" + output + "]"); HttpResponseMessage response = await client.PostAsync(connString, httpContent);

response.EnsureSuccessStatusCode();


Step 5: Data Visualization in Power BI

Here we are visualizing our sensor data at different dates and time. We can see the percentage change in Humidity, Temperature and Battery Usage during different days with there values respectively.

Step 6: Azure Email Hosting for Wireless Temperature Sensor Using SendGrid

Software as a service(Saas application) provides another amazing feature called SendGrid. In Microsoft Azure, SendGrid support swiftly delivers Email notifications to different Users.

The setup for Send Grid is described in this blog.

Here We will be describing the code for sending email notification using Azure function.

  • Add these dependencies, "Send Grid" is used for accessing SendGrid mailing services.

#r "SendGrid"
using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Net; using System.Net.Mail; using SendGrid.Helpers.Mail; using Microsoft.Extensions.Logging;

  • Create variables for storing to mail, from mail, smtp port, username , password, smtp host, subject of mail and mail body.

string fromMail="enter from mail";
string toMail="enter to mail"; int smtpPort = 587; string smtpUserName="Enter your smtp send grid username"; string smtpPassword = "enter sendgrid password"; string smtpHost = "smtp.sendgrid.net"; string subject = "Temperature Alert!!!"; string mailMessage = "Temperature has reached beyond 30";

  • Create an instance of MailMessage and SmtpClient

MailMessage mail = new MailMessage(fromMail,toMail);
SmtpClient smtpClient = new SmtpClient();

  • Set the port, delivery method, smtp host, user credentials mail body and subject to the Smtp client and mail Message object.

smtpClient.Port = smtpPort;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; smtpClient.Host = smtpHost; smtpClient.Credentials = new System.Net.NetworkCredential(smtpUserName,smtpPassword); mail.Subject = subject; mail.Body = mailMessage;

  • Set the port, delivery method, smtp host, user credentials mail body and subject to the Smtp client and mail Message object.

smtpClient.Port = smtpPort;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; smtpClient.Host = smtpHost; smtpClient.Credentials = new System.Net.NetworkCredential(smtpUserName,smtpPassword); mail.Subject = subject; mail.Body = mailMessage;

  • Whenever the temperature crosses the 30 degrees threshold. The user will get a mail to the described email id.

if(product.Ctemperature > 30.00){
smtpClient.Send(mail); }

Notification Outcomes

  • An automated email notification will be delivered to the user eachtime the temperature crosses 30 degrees mark.
  • Send Grid delivers the Email Notification to the same subject everytime. We don't have to scroll down in the inbox in search of last delivered message. Just search for the Temperature Alert!!! and you will get the list of messages.

Step 7: Overall Code

The firmware of this setup can be found in this GitHub repository