Building a Temperature Monitor using mcMod120 and Wia

Hi All, In this tutorial we will be accessing the temperature sensor data from the mcMod120 and displaying it on Wia. Hopefully this tutorial will help by putting all the information in one place to make your setup as quick and easy as possible. Using these devices can enable you to track data and information from around your home or business and have it all reported in one place.

Creating a Wia Device

Login to your Wia account and go to devices on the left-hand side of the screen. Click the + button and name your new device. It’s as simple as that! Wia will automatically generate and provide you with a unique device ID and secret key that will allow you to access and code your specific device.

Software and Hardware Setup

First, you’ll need to download the mcThings platform. You can do so by following the link to the Getting Started page. If you are new to programming, I would recommend looking through the mcScript and mcStudio introduction guides included in the download as they are a good source for background information on the platform. IMPORTANT: Make sure to update all of your devices to the newest versions of the software using the mcOTA Updater. Follow the steps described in the mcThings tutorial explaining how to update your modules. You’ll need to follow the same process for updating your gateway using the mcGW110host.bin file. Additionally, you’ll need to follow these steps provided by mcThings to complete the update of your gateway.

Once, you’ve done this, you can begin setting up your mcThings devices. Connect your mcGate to your computer via a USB cord and open the mcStudio IDE. Your gateway must also be connected to the internet. You can either plug in an ethernet cord (recommended) or you can connect the device to Wi-Fi (see video here). Once in mcStudio, press Ctrl + D to open the devices menu and click on the mcGate that you just connected. Click on Connect Gateway at the top of the menu to finish connecting your gateway to the computer.


Now that your Gateway is connected, you can begin connecting your modules. Only one module can be connected at a time, but once you load your completed code onto one module you can disconnect it and connect another module and load code onto that as well. The Gateway can simultaneously receive information from over 1,000 different modules that are in range of the gateway so you shouldn’t have an issue with connecting multiple modules to the same gateway.

To connect a module, select the Gateway you just connected in the Devices menu. The Gateway should automatically detect your device and list it in the bottom section of the menu. Select it, and click Connect Device. This can take some time so don’t worry if it does not immediately connect, but it should not take longer than 60 seconds for your device to successfully connect. If it doesn’t connect, you can abort and try again.


Now, you can select your connected gateway and click on Gateway Config in the top left of the devices menu. This will bring up a screen that looks like the following:


Input the following information in the sections under MQTT.

Server -
Port – 1883
Username - Your Wia Device Secret Key
Password - A blank space character
ClientID - Your Wia Device ID

### Code Now that you’re all set up, it’s time to start coding. The following code will allow your device to access Wia’s platform to display incoming data. All you need to do is substitute your device’s unique ID where it says “Wia Device ID” on line 3.

Class TempLogger
    // Device ID in Wia
    Const wiaDeviceId As String = "Wia Device ID"
    // MQTT topic in Wia
    Const wiaTopic As String = "devices/" + wiaDeviceId + "/events/temperature"

    Shared Event CheckTemp() RaiseEvent Every 30 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)

        // Create Wia preferred JSON object - { "data" : {"temperature" : "23.06"}}
        Dim wiaPayload As Json = New Json
        wiaPayload.Add("data", tempJson)

        // Publish to wia MQTT
        Lplan.Publish(wiaTopic, wiaPayload.ToListOfByte)
    End Event   
End Class

You’ll also need to give mcStudio access to the TempSensor Library in your project. To do this, go to File > Add Library Code > TempSensor. This will bring up another script that contains the Library. Now all you have to do is build your code and upload it to your module. To build your code, either press F6 or go to Project > Build. Then, you can load your code to the module by either pressing F7 or going to Project > Load and Save. Make sure your module is connected before attempting to load your code. After the code is loaded, the module will be automatically disconnected from the gateway and will start running the code you uploaded. To view the incoming data, go back to your Wia account and click on the Devices tab on the left side of the screen, then choose the specific device that you created.


Depending on how often your device is reporting data, it may take some time for any values to come through. Refresh the page every few seconds until you see your data appear. You can go to Events in the menu across the top of the screen to view a list of all the data points your device has recorded.

That’s it for today! Happy sensing!


Recommended article

Ready to get started?
Talk to our sales team or setup an account.