mcThings
Published © GPL3+

Project Using the mcPlug for IoT Applications!

Using MQTT, Losant, IFTTT and the mcThings IoT platform to create feasible and real IoT automation solutions with the mcPlug.

BeginnerFull instructions provided30 minutes1,339

Things used in this project

Hardware components

mcPlug
mcThings mcPlug
A relay with an embedded mcModule120 that allows you to provide power to a 'plugged in' device/appliance/etc!
×1
mcModule120 Dev Kit
mcThings mcModule120 Dev Kit
We recommend a kit for this example so that you have multiple modules to gather information from (Not required but you will need at least one mcModule, one mcGateway and an mcDongle)
×1
mcMod120 Module
mcThings mcMod120 Module
You'll need at least one mcModule120 for this project
×1
mcGateway110
mcThings mcGateway110
You'll need an mcGateway for this project
×1
mcDongle
mcThings mcDongle
You'll need one of these to complete your firmware updates! Be sure to update your firmware to the latest versions before starting
×1

Software apps and online services

mcStudio
mcThings mcStudio
IDE for programming mcThings gear
Losant Platform
Losant Platform
Comprehensive IoT cloud application
Maker service
IFTTT Maker service
Used if you wish to send the information to another service using IFTTT
MQTT
MQTT

Story

Read more

Schematics

mcMod120 brief

Code

mcPlug Subscribe code

mcScript
Used to program the mcPlug to receive incoming MQTT messages and then give power or not to a device/appliance/etc
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 publish

mcScript
checking the temperature and then sending a unique MQTT topic to your broker as well as option to send information to IFTTT
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 

Credits

mcThings

mcThings

17 projects • 70 followers
Use mcThings to quickly & easily create, test and deploy IoT solutions for industrial, business/commercial and individual needs!

Comments