Skip to main content
All CollectionsConnect your Devices
Connect a mcModule to Ubidots over MQTT
Connect a mcModule to Ubidots over MQTT

Learn to setup the mcModule to communicate with Ubidots over MQTT.

Sergio M avatar
Written by Sergio M
Updated over 3 months ago

The mcModule is a computer like device that is incredibly small, powerful and energy efficient. Running on a single coin cell battery, these devices can last up to five years! Attaching the mc-Modules on almost anything, you are able to measure and control many variables remotely.

IMPORTANT: If you are purchasing a mc-Module, ensure you also have the mc-Gateway and the mcDongle. All three products in tandem work to create the mcThings platform which can easily communicate with Ubidots direct from the devices or by way of the mcStudio and UbiFunctions.

By following this guide you will be able to PUBLISH data taken from your mc-Modules devices to Ubidots in just a few minutes!

Requirements

Step-by-Step

  1. Setting up Firmware  

  2. Setting up mcGateway 

  3. Setting up mcModules 

  4. Sending (PUBLISH) Data to Ubidots

  5. Summary

 1. Setting up firmware

Before beginning to work with the mcModule & mcGateways it's important have the devices updated with the latest version of the firmware. These firmware updates provide increased functionality and are used to keep everything up to date and operational in your Apps.

To update the firmware you will need the mcOTA, a desktop application used in conjunction with the mcDongle to facilitate over-the-air mcOS updates to mcDevices and mcGateways. 

To learn how to get your device up to date, refer to the guide below:

2. Setting up mc-Gateway 

To begin, you need to setup the mcThings Gateway in order to be able to forward the data received from the mcModules to Ubidots. 

If your gateway is not already configured to transmit data to Ubidots, please refer to the article below:

Once the gateway is properly configured, you can continue with the next steps.

3. Setting up the mc-Modules

All the mcThings hardware series are programmed using an IDE of of mcThings called mcStudio. This Integrated Development Environment (IDE) mcScript using a programming language which is based and focuses on Visual Basic programming

mcStudio includes features for authoring, modifying, compiling, refactoring, deploying and debugging your code. Also, it provides the interface to wirelessly debug and load programming into mcThings hardware.

To start we highly recommend you checkout the mcStudio's introduction video:

1. Update the mcModule with the last firmware version using the mcOTA updater (step #1 above). 

2. Then, you need to assign the device(s) you are going to work with. To do this, open the mcStudio and go to Tools –>Devices.

In the following window you will see the status of your mcThing devices. At this point, the status of the gateway should be "Connected" to be able to detect the module desired to be programmed.
​ 
Once the mcGateway is connected you’ll be able to see the mc-Module.

3. Once the mcGateway is connected you'll be able to see any mcModule detected. To detected the mcModule just connect it to your computer and wait a couple of seconds until is shown in the second block below.

At this point, verify if the Uid which appear in the "Device Maintenance and Connection" window is related with the one printed on your mcModule. Then, to establish the connection, press the "Connect Device" button:

4. Once your mc-Module establishes the connection properly, the status of the device will change to "Connected". This step will take approximately 60 seconds, so please be patient.

At this point, you are ready to start programming the mcModues to transmit readings taken from the sensors to Ubidots.

4. Sending (PUBLISH) Data to Ubidots 

1. To start sending values to Ubidots, create a project in the mcStudio IDE. To create the project, go to File –> Create Project.

2. Copy and paste the code sample below into the project. Then, assign the Device Label desired where is indicated in the sample code. This device label will be the identifier for Ubidots. Any time data is sent and directed at this device label, the underlying variables of that device will be updated accordingly. 

Define PinMode Pin0 As AnalogInput Alias Sensor

Class Ubidots_AnalogRead
    Shared Event Boot()
        Lplan.SetBeaconTime(175)
    End Event

    Const DeviceLabel As String = "Your_Device_label"
    Const topic As String = "/v1.6/devices/" + DeviceLabel

    Shared Event SensorRead() RaiseEvent Every 10 Seconds
        Dim value As Float
        value = Sensor

        Dim payload As Json = New Json
        payload.Add("sensor", value)

        Lplan.Publish(topic, payload.ToListOfByte)
    End Event

End Class


3. Now with the code already place it in the project, let's run the code in order to test that everything is working as is expected. To run the code, press the Run button located at the upper-right of the IDE:

At this point, you should be able to see a new device create in your Ubidots account. The name of the device will be the one assigned by you as the Device Label: 

    Const DeviceLabel As String = "Your_Device_label"

In our example here, we assigned "mc-module" as device label, for this reason the device created in the Ubidots is the same "mc-module":

5. Summary 

Ubidots & mcThings provide you an easy access into the Internet of Things efficiency and optimization world, and in just few minutes you were able to create the first steps of any IoT App or Solution. Now it’s time to create and optimize things, systems, and spaces!

Now it is time to create a dashboard to control and manage the variables of your mcThings devices. To learn more about Ubidots widgets and events, check out these helpful video tutorials.

Other readers have also found useful...

Did this answer your question?