How To: Getting Temperature Data to the Cloud

The Temperature Monitor Device made by our team combines several off-the-shelf components and some simple programming to yield a system that gathers and offers temperature data. This data can be fed into a middleware like Kepware or any other OPC UA client, making it easy to integrate temperature measurements into your systems. We have links to all the parts we used at the bottom of this page.

Part Cost
Raspberry Pi 4 (1Gb) $80 – $100
Waveshare PoE Hat $25
MCC 134 Thermocouple Hat $150
Misc (Fan, fasteners, etc.) $10
Total $265

*These costs may change after time of writing.

The Temperature Monitor Device relies on the Raspberry Pi 4 computer as its central component. The Pi 4 serves as a base platform, onto which more functionalities are added. This is typically done with expansion boards, less formally known as “hats”. For this project, two hats were installed. First was the Measurement Computing MCC 134 Thermocouple Hat which includes all the necessary circuitry and amplification needed to read temperatures from a thermocouple. Secondly, the Waveshare PoE Hat was installed. This enables PoE functionality for the Raspberry Pi, allowing power and data to be connected to the Pi through a single ethernet cable.
Although optional, we designed and 3D printed an enclosure for the device. The enclosure protects the electronics from bumps and falls and facilitates airflow through the use of a 12V 40mm fan.

We are using spade type surface thermocouples from PPE which can be fixed to the outer surface of a mold, brass fitting, or any other subject. In our case, we have one thermocouple fixed to the to-process and another fixed to the from-process fitting on the back of a TCU. Any thermocouples will work as the MCC 134 supports up to 4 thermocouples of type J, K, R, S, T, N, E, or B

Temp Monitor 2

Software

Interfacing with the MCC 134 hat and managing the OPC UA server is all programmed in Python. We used three packages:

  • The daqhats package provided by Measurement Computing to interface with the MCC 134.
  • The asyncua package to create and manage the OPC UA server.
  • The asyncio package which supplements asyncua.

Below is an example program that offers new temperatures to the OPC UA server every 1.5 seconds.

from asyncua import ua, Server
import asyncio
from daqhats import mcc134, HatIDs, HatError, TcTypes, hat_list
import os

async def main():

board_list = hat_list(filter_by_id = HatIDs.MCC_134)

if len(board_list) < 1:
# If board_list is less than 1, no boards were detected
exit("No MCC Boards were detected")

daqhat = mcc134(board_list[0].address)

# Define which thermocouple types are connected to each terminal
daqhat.tc_type_write(0, TcTypes.TYPE_J)
daqhat.tc_type_write(1, TcTypes.TYPE_J)
daqhat.tc_type_write(2, TcTypes.TYPE_J)
daqhat.tc_type_write(3, TcTypes.TYPE_J)

server = Server()

await server.init()
# IP of 0.0.0.0 indicates that any IP that references the device will work
# e.g. http://127.0.0.1 for local access or the device's IP address for external access
server.set_endpoint("opc.tcp://0.0.0.0:4841")
server.set_server_name("Temp Monitor")
server.set_security_policy([ua.SecurityPolicyType.NoSecurity])

uri = "http://yourwebsite.com"
idx = await server.register_namespace(uri) 

monitor_opc_object = await server.nodes.objects.add_object(idx, "TEMP MONITOR")

monitor_opc_attributes = (
await monitor_opc_object.add_variable(idx, "to_process_temp", 0.1),
await monitor_opc_object.add_variable(idx, "from_process_temp", 0.1),
await monitor_opc_object.add_variable(idx, "cold_inlet_temp", 0.1),
await monitor_opc_object.add_variable(idx, "mold_surface_temp", 0.1)
)

async with server:
while True:

for i in range(4):
temp = daqhat.t_in_read(i)

if temp == mcc134.OPEN_TC_VALUE:
temp = 0.0
elif temp == mcc134.OVERRANGE_TC_VALUE:
temp = 999.9
else:
temp = temp*(9/5) + 32

await monitor_opc_attributes[i].write_value(temp)

# Wait 1.5 seconds before next temperature measurement
await asyncio.sleep(1.5)

if __name__ == '__main__':
asyncio.run(main())

Fitting your needs

The Raspberry Pi, expansion boards, and Python script combination offers a myriad of options to capture and move data.

The hats we used fit our needs, but there are many others to choose from. Measurement Computing, for example, offers a selection of hats to measure temperature, voltage, vibration etc. Another manufacturer by the name of La Chacal offers Raspberry Pi hats to measure 3 phase power consumption using voltage and current sensors. This is to say that the Raspberry Pi is a widely supported platform for such measurements, and the right equipment is no more than a few clicks away.

One of the great benefits of using Python on the Raspberry Pi is its expandability and ease of programming. If you need specific functionality, there is probably a package for it. Here are some notable examples:

  • RPi.GPIO for interacting with Raspberry Pi pins.
  • numpy for data manipulation
  • pandas, scipy for data/statistical analysis
  • keras, tensorflow, pytorch for machine learning and AI

While Python is on the slower end in terms of speed, it is unparalleled in terms of development time.
OPC UA is an industry standard for making data available to other applications. If some other protocol is desired, there are several packages to choose from:

  • requests for http connections
  • paho-mqqt for mqqt connections
  • sockets for tcp/ip connections
  • ftplib for ftp file transfer

Hardware:

Software:

Join Our Conversation

SUBCRIBE TO NOBLE INSIGHTS

Please enter a valid email address.

MORE N-SIGHTS™

Announcing Bold Mold Transfer Service

We have added a new services page to our website! Now you will find our (Bold!) Mold Transfer program alongside our molding and automation offerings. If you find yourself in this position and are looking to move your mold, Noble Plastics is ready to help!

Read More

Practical Industry 4.0

Innovation has followed us across the centuries and will continue to push us into the future. We have seen three industrial revolutions come and go, so what exactly is the fourth, and when is it coming?

Read More

Join Our Conversation

SUBCRIBE TO NOBLE INSIGHTS

Please enter a valid email address.