(MakeCode Coding)

Makecode Coding and MakerCloud

../../_images/mcbanner.png

Foreword:

In this tutorial, you will learn how to use MakerCloud platfrom with a Wifibrick or KOI. A Robotbit will be used for demonstration.

Step 1: Platform Preparation

Log in to MakerCloud and set up an IoT service.

Navigate to the mainpage and create a project.

Or use ones that you created previously.

../../_images/mc16.png

You will be redirected to the main page of your IoT project. Select Create Topic.

../../_images/mc27.png

Create a MQTT topic.

../../_images/mc32.png

Navigate to the Internet of Things tab.

The topic name will be automatically generated, this topic name should remain secret as it is the key to access this topic.

../../_images/mc42.png

The IoT platform is now ready to be used for IoT operations.

Step 2: Load the extension

We will load an extension so that we can communicate with MakerCloud’s server.

Extension for Wifibrick: https://github.com/maxwong-scale/pxt-makercloud-V2

Extension for KOI: https://github.com/scaleinnotech/pxt-makercloud-koi

Loading Extensions

Step 3: Coding

1: Connecting Wifibrick to MakerCloud

Blocks for initiating connection:

../../_images/mc121.png

As a Robotbit is used in this tutorial, we initiate the Wifibrick with Tx & Rx pins.

../../_images/mc51.png

Armourbit users can use ports to initialize.

../../_images/mc61.png

The Micro:bit will display a short animation when connecting to the Wifi.

../../_images/mc16.gif

The Micro:bit will display a short animation when connecting to the MQTT server.

../../_images/mc17.gif

2: Publishing to the Topic

Blocks for publishing:

../../_images/mc131.png

Let’s publish a random number to our topic.

Copy and paste your topic name here.

../../_images/mc71.png

The data we sent will be shown in the real-time data feed.

../../_images/mc101.png

A chart will also be generated.

../../_images/mc151.png

We can manually publish data to a topic with this window.

../../_images/mc112.png

3: Subscribing to a Topic

Blocks for subscribing and reading data:

../../_images/mc141.png

In order to obtain data from a topic, a subscription is required.

In this example, let’s subscribe to the same topic we publish data to.

../../_images/mc81.png

Sample Program

Sample Program for Wifibrick

../../_images/mc91.png

Sample Code Link

Sample Program for KOI

../../_images/mc181.png

Sample Code Link

Conclusion:

This concludes the basic usage of the MakerCloud platform with a Micro:bit, for more advanced usage, please refer to the official tutorials.

Extension Version and Updates

There may be updates to extensions periodically, please refer to the following link to update/downgrade your extension.

Makecode Extension Update