Getting Started with mc-Things and Losant

Taron Foxworth
Taron Foxworth | 4 minute read

In this tutorial, we are going to use the mc-Things platform and hardware to send data to Losant. Once in Losant, we can graph the sensor data and build workflows to give the data life.

Things has built an impressive platform to build IoT solutions quickly. If you are familiar with the mc-Things platform, you can go straight to the Losant integration. If not, check out this video to learn more about mc-Things:

mc-Thing's created a small module called the mc-Module. The mc-Module is a tiny, low-cost, and low-power device. Each mc-Module can last up to five years on a single battery. They operate over a low-power LAN called mc-Air. The modules connect to another device called mc-Gateway to connect to cloud services like Losant. The mc-Modules also support over the air software updates and live debugging. Its features make the mc-Module ideal for a broad range of projects of all sizes.

mc-Things created an excellent tutorial on how to track temperature data, sent it to IFTTT, and chart it in Google Drive. For this tutorial, we are going to do something similar. We are going to use the mc-Module to track temperature and send it to Losant over MQTT.

Materials:

  • mc-Module 120 - Tiny computer with a bunch of sensors
  • mc-Dongle - Hardware required for updating the firmware on your mc-Modules and the mc-Gateway
  • mc-Studio - mc-Things IDE
  • mc-Gateway - The gateway will allow you to speak to your mc-Modules and send data back and forth
  • Losant Account
  • Windows Machine - Right now, mc-Things’ development environment only supports a Windows environment.

First, you need to go to mc-Things support to make sure you have the latest firmware and drivers. mc-Things did a great job creating video tutorials for their products. There is a great tutorial to help you update the mc-Modules. Altogether, you need to update the mc-Module, mc-Gateway Application Processor, and mc-Gateway Host Processor. If you run into any trouble, the mc-Thing forum is a great place to get answers.

Now that your mc-Module and mc-Gateway are updated, get them connected to mc-Studio

mc-Studio is a dedicated IDE to program the mc-Modules. To connect the mc-Gateway and mc-Module, check out this video. Once you have everything connected, your device menu should look like so:

mc_studio_device_connected.png

Everything is connected, let's open up the MC Studio and write some code. mc-Things has created a programming language and IDE to program the mc-Modules. The language is called mc-Script. If you're familiar with Visual Basic, you should feel right at home. Here is a simple program to make the LED on the module blink:

mc-Script is an event-based language. Here is a helpful excerpt from the mc-Script docs:

This is how mc‑Script™ functions. Sleep until there is something to do. mc‑Script™ is made to solve this problem and operates by design in a low power mode close to the hardware.
 
You may ask yourself where the LedRed variable comes from. mc‑Script™ “knows” the device and “knows” what the RedLed is. A number of standard constants exist automatically to simplify development.

To deploy this program to the device, we need to build and load it to the device. To build, press F5 in the mc-Studio. To load it to the mc-Module, press F7. Then, you should get a message confirming.

The mc-Things platform can use MQTT to send data to Losant. MQTT is configured in the mc-Gateway. The mc-Modules connect to the mc-Gateway to send data back and forth from the internet. In Losant, you can set up Gateways and Peripherals. Peripheral devices don’t connect directly to Losant; in the same manner, the mc-Modules don’t directly connect to the network. Peripherals need to use a Gateway - in our case the mc-Gateway - to send the data through the gateway to Losant.

Create a Gateway device in Losant for the mc-Gateway

First, create an account or log into Losant and create an application for this project. Then, create a new device.

create-gateway.png
Selecting Gateway is important. The rest of the default settings are appropriate for this project.

Create a Peripheral device in Losant for the mc-Module

create-peripheral.png

Let's select Peripheral as the type of device. Then, use the gateway you created above as the gateway for this device. We also need to set up two attributes for this device. Attributes tell Losant what data we expect to receive from the device. We are going to track two attributes with "number" as their data type: temperature and battery Voltage.

losant_temperature_attribute.png

Create an Access Key/Secret in Losant

The Access Key/Secret are used in mc-Studio as the MQTT username and password.

access-key-popup.png

Connect the mc-Gateway to Losant’s MQTT broker

In the device menu in mc-Studio, at the top, you’ll see Gateway Config. Once opened, we can update the MQTT settings.

mc_things_mqtt_settings.png

MQTT Server - broker.losant.com
MQTT Port - 1883
MQTT Username - Your Losant Access Key
MQTT Username - Your Losant Access Secret
MQTT ClientId - This is the Device ID of the gateway you created in Losant.

Add TempSensor Library

To use the temperature sensor library, you must first add it to your project. In the menu, navigate to File > Add Library code > TempSensor. This menu option will add the library to your project.

Create a new project in mc-Studio

Create a project in mc-Studio called TempLogger. Let's use this example code to start:

We are creating two events, CheckTemp and CheckVoltage. The CheckTemp event will check the temperature data every 30 seconds and publish that data to Losant. CheckVoltage will do the same but monitoring the voltage of the battery. CheckVoltage is helpful because we can set up a workflow in Losant to notify us if the battery in the mc-Module gets too low.

Again, to deploy this program to the mc-Module, we need to build and load it with F5 and F7, respectfully.

Check out data in Losant

Now, if you set everything up correctly, navigate to the data explorer to graph your temperature and voltage data from the mc-Module.

losant-temperature-graph.png


What's Next?

You can build a dashboard, trigger reactions using our workflows or anything you can imagine. To create and learn more with Losant, we have compiled a list of great tutorials and projects you can use for inspiration. Also, mc-Things has a great YouTube playlist of awesome projects you can do with their platform as well.

Tagged