This project will show you how to use the mcThings IoT Hardware platform to easily measure temperatures and then display them into MyDevices' easy to use Cayenne application! Cayenne offers alert features, events and much more.
We'll use the built-in temperature sensor in the mcModule120 and then send that temperature information, via the mcGateway, into a Cayenne Dashboard using MQTT. MyDevices has a Hackster hub, so be sure to check it out too
Potential use-casesThere are so many things you can do with the mcThings platform! You can create almost any type of IoT solution and then display/store/etc the data using multiple cloud options!
In this particular example, there are tons of use-cases where having multiple battery operated devices relaying temperature (and other info) back to the cloud would be very useful. And since the mcModule120 can last for up to 5 years using a single coin-cell battery, the possibilities are endless! Check out the product brief for the mcModule120 in the schematic section of this project or, check i tout on our website
- Grocery/retail temperature monitoring: Imagine a grocery/retail store where you can measure the temperatures within the freezers/coolers/fridges and then have a real-time dashboard to visualize that data. This could provide very impressive ROI, energy savings and a reduction in lost product.
- Cold-Chain monitoring: Imagine being able to track and alert on temperature fluctuations within a cold-storage facility. This could provide impressive ROI, allow a client to more efficient, be pro-active on maintenance and alerts on any issues.
- Agriculture: Imagine measuring temperatures (and humidity, etc) within a greenhouse/warehouse and using that data to be more efficient, save money/resources and gain valuable data over-time that can help with informed business decisions.
- There are tons of other uses for this type of example! Feel free to leave your comments about other use-cases in the comment section!
The mcThings platform includes 2 main components: mcModules and mcGateways. A powered and connected mcGateway creates the mcAir network (up to 200m range under optimal conditions) and bridges the information between the mcModules (within range) to and from the Internet. Using the IDE (mcStudio) and mcScript (ultra-low power programming language - a subset of VB.NET) allows you to wirelessly connect, debug and program modules with your customized scripts.
Note: You also require an mcDongle to complete firmware updates on the modules/devices and gateways! We recommend looking at the mcModule120 Dev kit which includes everything you need to get going!
You need to sign up for Cayenne and then setup a device:
Device setup
Add your mcGateway into Cayenne- you'll need to choose the 'Bring your own Thing' button to get going. When you click on 'Bring your own Thing' you will then be provided your MQTT credentials:
Your gateway now, move on to the gateway setup below. Your gateway will show up when it firsts connects to Cayenne.
Module and Gateway SetupUsing the above information, you'll need to configure your gateway and program your mcModule120 to send temperatures to Cayenne.
Gateway Config
Server - mqtt.mydevices.com
Port – 1883
Username - Your Cayenne MQTT username
Password - Your Cayenne MQTT password
ClientID - Your device client ID
After you enter the above information into the gateway config, save the settings and you should see your gateway within the Cayenne platform.
mcModule120 Programming
Connect to your module using your gateway within mcStudio and program the devi. Below is an example code that you can use and modify:
Note - Props to Labmaster who provided provided code his initial code on our forum and tested MQTT with Cayenne - Thanks Labmaster!
Class MyDevicesTemp
Const mdUserId As String = "YOUR CAYENNE MQTT USERNAME"
Const mdClientId As String = "YOUR CAYENNE MQTT CLIENT ID"
Const mdChannel As String = "0"
// MQTT topic in MyDevices.com - v1/username/things/clientID/data/channel
Const mdTopic As String = "v1/" + mdUserId + "/things/" + mdClientId + "/data/" + mdChannel
Shared Event CheckTemp() RaiseEvent Every 60 Seconds
Dim temp As Float = TempSensor.GetTemp() // Get Temp from sensor
Dim tempString As String = temp.ToString()
// Create temp JSON object - { "temperature" : "23.06" }
Dim tempJson As Json = New Json
//tempJson.Add("temperature", tempString)
tempJson.Add("temp,c=", "99")
// Create MyDevices preferred JSON object - { "data" : {"temperature" : "23.06"}}
Dim myDevicesPayload As Json = New Json
myDevicesPayload.Add("temp,c=99")
Dim mdPayload As ListOfByte = New ListOfByte
Dim mdData As String = "temp,c=" + tempString
//mdData = "temp,c=99"
mdPayload.Add(mdData)
// Publish to Cayenne MQTT
Lplan.Publish(mdTopic, mdPayload)
End Event
End Class
Visualizing data in CayenneNow that you have your mcModule programmed, you should start to see data incoming into Cayenne. You can add widgets yo your dashboard to visualize the data:
You can also setup triggers/alerts very easily:
Be sure to check out (and join!) our hub here on Hackster to see other examples and projects that we have put together! Check out our forum and YouTube Channel for more support!
Thanks for reading!
Comments
Please log in or sign up to comment.