Things used in this project
|Software apps and online services:|
Using the mcPlug and mcThings platform in tandem
In this project we're going to show you how easy the mcPlug and the mcThings platform is to create feasible, realistic, scalable and automated IoT solutions. For this example, we'll use an mcModule120 to check a temperature and if it is too hot, it then sends a message to tell the mcPlug to turn on a fan! We'll be using Losant as our MQTT broker and also using IFTTT!
Using the mcPlug along with the rest of the mcThings platfrom gives the ability to create countless IoT solutions. And because you can use the mcModule to relay the temperature information, you can place the device anywhere due to the battery!
- Smart Greenhouse - Automate a greenhouse or other temperature sensitive environment by controlling devices/appliances automatically with variables measured by other mcThings devices
- Agriculture/industrial - Power water heaters, pumps, etc automatically based on any other variable you wish to measure
- Retail - Provide power to lights/displays/etc automatically based on other variables
- Home Automation - Wirelessly and automatically provide power to house appliances, Holiday lights, Christmas Tree, that neon bar sign that your wife hates, lamps, blenders, fans, etc
- The possibilities are endless!
How the platform works:
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.
Programming the Plug and mcModule120
We programmed the mcModule120 to check the temperature every 30 seconds. If the temperature was over 25C, it then publishes a topic to Losant. Using the below workflow, another topic was published which allowed the mcPlug to provide power to the fan! If the temperature was below 25C, the plug would then turn off the fan.
See the code at the end of this project for both the mcModule and the mcPlug.
Setting up a workflow in Losant
We setup a workflow that received the incoming MQTT topic and then relayed an outgoing topic which provided power to the fan via the mcPlug.
*Check out the walk-through on connecting the mcThings platform to Losant's application. We also have examples in our other projects (including video!)*
We also wanted to use the Losant 'Go' smartphone app so we added a device to the workflow, selected the Losant Button and then setup the device and the application. We also added a virtual button that allows you to activate the workflow directly from the workflow screen
You could also capture data on how often and how long the fan, appliance, device, etc is running or not as well as visualize that data using the Losant application.
Within the below code, we included a line so you can publish to the IFTTT service
You could track the usage within a google spreadsheet, send a notification to your phone, or use any of the tons of IFTTT applets that are available!
Thanks for reading!
The mcThings IoT hardware platform is perfect for creating real commercialized IoT solutions that are feasible, ultra-low power, scalable and battery powered to be placed anywhere.
We'd love to hear your ideas for other use-cases for the mcPlug and the mcThings platform in general!
Please become a member of our hub here on Hackster to stay up-to-date with new projects! We've got plenty more to come.
mcPlug Subscribe codemcScript
Class FanTempSubscribe Shared Event Boot() Lplan.SetMidPowerMode(1) Lplan.Subscribe("mcThings/FanOn") Lplan.Subscribe("mcThings/FanOff") End Event Shared Event SubscriptionDelivery() Dim msg As Message = Lplan.GetDelivery() If msg.Topic= "mcThings/FanOn" Then Relay = True ElseIf msg.Topic= "mcThings/FanOff" Then Relay = False End If End Event End Class
mcModule MQTT and IFTTT publishmcScript
Class FanTempPublish 'Set a constant MQTT topic Const mcPlugOn As String = "mcThings/PlugOn" Const mcPlugOff As String = "mcThings/PlugOff" 'Optional to set module to mid-power mode if you wish 'Shared Event Boot() ' Lplan.SetMidPowerMode(2) 'End Event 'Check temperature every XX seconds/minutes/days Shared Event CheckTemp() RaiseEvent Every 30 Seconds Dim TempC As Float = TempSensor.GetTemp Dim TempF As Float = TempSensor.ToFarenheit(TempC) 'program logic for IFTTT and MQTT topic publish If TempC > 25.0 Then LedRed = True Lplan.IFTTT("YOURIFTTKEYHERE", "FanOn") Dim payloadOn As ListOfByte = New ListOfByte() payloadOn.Add(1) 'publish topic to MQTT broker Lplan.Publish(mcPlugOn, payloadOn) LedRed = False ElseIf TempC < 24.99 Then LedGreen = True Lplan.IFTTT("YOURIFTTTKEYHERE", "FanOff") Dim payloadOff As ListOfByte = New ListOfByte() payloadOff.Add(1) 'publish topic to MQTT broker Lplan.Publish(mcPlugOff, payloadOff) LedGreen = False Else End If End Event End Class
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!