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.
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!
Using the mcModule enclosure, you can easily install the module to a door/window/etc and place the magnet clip so that it lines up with the module when the object is closed. You can also use your own magnets! We recommend a strong magnet like neodymium. If you are building a customized enclosure or have a unique object that you want to use the reed switch with, this is a good option.
mcModule enclosure w/ magnet clip
mcMod120 in enclosure
We're going to push the information to an MQTT client app on an Android phone to see the status in real-time!
We also sent temperature info to the app at the same time
Check out the below video and code for putting this together as you'll need to setup your gateway and your MQTT broker properly to push information to your phone:
Class ProductionRoom/YOURPROJECTNAMEHERE Shared Event ReedSwitchChanged() Dim payload As ListOfByte = New ListOfByte Dim payString As String = "" If ReedSwitch = True Then LedRed = True payString = "Open" Else LedRed = False payString = "Closed" End If payload.Add(payString) Lplan.Publish("mcThings/ProductionRoomDoor/YOURTOPICNAMEHERE", payload) Thread.Sleep(10000) Thread.ClearHardwareEvent() Dim uptime As Integer = Device.Uptime() End Event Shared Event CheckVoltage() RaiseEvent Every 2 Days Dim BattVolt As Short = Device.BatteryVoltage If BattVolt < 2200 Then Lplan.IFTTT("YOURIFTTTMAKERKEYTHERE", "YOUREVENTNAMEHERE") Else End If End Event End Class
We also included a bit of programming to check the battery voltage every 2 days and send a message to the maker channel on IFTTT if below 2.2 volts (above is measured in millivolts).
IFTTT - Code
Below is code to setup a message to be sent to IFTTT if the door is opened and closed. Again we added a battery voltage check. Using IFTTT allows you to send the information to a ton of different services! We usually use notifications via the IFTTT Android app but you could receive an email, log the information into a spreadsheet, etc!
Class IFTTTAndroidDoor Shared Event ReedSwitchChanged() If ReedSwitch = True Then LedRed = True 'Enter your maker channel event name such as 'doorOpen' Lplan.IFTTT("YOURIFTTTMAKERKEYHERE", "doorOpen") Else LedRed = False 'Optional to add the below closed function as well Lplan.IFTTT("YOURIFTTTMAKERKEYHERE", "doorClosed") End If Thread.Sleep(10000) Thread.ClearHardwareEvent() Dim uptime As Integer = Device.Uptime() End Event 'check the battery voltage every 2 days Shared Event CheckVoltage() RaiseEvent Every 2 Days Dim BattVolt As Short = Device.BatteryVoltage If BattVolt < 2200 Then Lplan.IFTTT("YOURIFTTTKETHERE", "ProductionRoomBattery/YOURTOPICHERE") Else End If End...Read more »