> For the complete documentation index, see [llms.txt](https://sharinghub-eng.kittenbot.hk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sharinghub-eng.kittenbot.hk/wifibrick_iot/makecode/thingspeak.md).

# Makecode Coding and Thinkspeak

![](https://kittenbothk.readthedocs.io/en/latest/_images/mcbanner8.png)

### Foreword

When the IoT platform and hardware are ready, we can start coding with the Micro:bit.

The program can be divided into 3 parts:

1. Connecting to the Internet.
2. Connecting to the IoT Platform.
3. Main program.(Publish/Subscribe)

* Robotbit was used when creating this tutorial, for Armourbit users, please refer to the instructions to modify the program.

Navigate to MakeCode’s page before continuing.

[MakeCode](https://makecode.microbit.org/)

#### Importing Extensions

#### Search for KittenBot

#### Import KittenWifi or KOI depending on your hardware

![](https://kittenbothk.readthedocs.io/en/latest/_images/wifi_search.png)

```
  請按自己的硬件選擇Powerbrick或Robotbit插件。
```

#### 1. Connecting to the Internet

***

This section is about connecting the Wifibrick to the internet.

Select KittenWifi from the menu.

These blocks are needed to connect to the internet.

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/iot-60-1.png)

Create the following program.

#### Robotbit/IOBit

![](https://kittenbothk.readthedocs.io/en/latest/_images/wifi_code1.png)

[Sample Program](https://makecode.microbit.org/_ErmXcmDV91cw)

#### Armourbit

![](https://kittenbothk.readthedocs.io/en/latest/_images/wifi_code2.png)

[Sample Program](https://makecode.microbit.org/_2vTCK4Wob5Um)

***

Before moving on, it is recommended that you run this program once to ensure the module can connect to the Wifi network.

{% embed url="<https://youtu.be/v6yIrGqzqO4>" %}

### Registering a ThingSpeak Account

Follow the instructions to register for a ThingSpeak account.

{% content-ref url="/pages/F1R49JSDefR0S6v1fUdg" %}
[ThingSpeak](/wifibrick_iot/platforms/thingspeak.md)
{% endcontent-ref %}

### Setting Up ThingSpeak Platform

#### Create a new Channel

Create a new channel.

![](https://kittenbothk.readthedocs.io/en/latest/_images/120.png)

Choose a name for your channel.

![](https://kittenbothk.readthedocs.io/en/latest/_images/28.png)

Other fields can be ignored, click Save Channel.

![](https://kittenbothk.readthedocs.io/en/latest/_images/38.png)

Open the Sharing tab.

![](https://kittenbothk.readthedocs.io/en/latest/_images/410.png)

Set the sharing settings to “Share channel view with everyone”.

![](https://kittenbothk.readthedocs.io/en/latest/_images/58.png)

The Access will change to “Public”.

![](https://kittenbothk.readthedocs.io/en/latest/_images/65.png)

#### Add a new device

Open the Devices menu, select MQTT.

![](https://kittenbothk.readthedocs.io/en/latest/_images/75.png)

Add a new device.

![](https://kittenbothk.readthedocs.io/en/latest/_images/84.png)

![](https://kittenbothk.readthedocs.io/en/latest/_images/93.png)

Select the channels accessible by this device and click Add Channel.

![](https://kittenbothk.readthedocs.io/en/latest/_images/105.png)

Click Add Device.

![](https://kittenbothk.readthedocs.io/en/latest/_images/1110.png)

IMPORTANT! These MQTT Credentials are used for connecting to ThingSpeak! Please save or download the credentials as they can’t be seen after closing this page.

![](https://kittenbothk.readthedocs.io/en/latest/_images/126.png)

![](https://kittenbothk.readthedocs.io/en/latest/_images/135.png)

### MakeCode Coding

#### Connecting to ThingSpeak

Build the following program and use these parameters to connect to ThingSpeak.

* Host: mqtt3.thingspeak.com
* ID: ThingSpeak Device Client ID
* Username: ThingSpeak Device Username
* Password: ThingSpeak Device Password

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/thingspeak_mc.png)

#### Publishing to ThingSpeak Channel[](https://kittenbothk-eng.readthedocs.io/en/latest/Wifibrick/MakeCode/MC_TS.html#publishing-to-thingspeak-channel)

We need the Channel ID for publishing. The channel ID is displayed on the Channel page as a 7-digit number.

![](https://kittenbothk.readthedocs.io/en/latest/_images/152.png)

Build the following program to publish a data to ThingSpeak:

* MQTT Topic: channels/\[Channel ID]/publish
* Message: field\[field No.]=\[Numeric Data]

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/thingspeak_code1.png)

[WiFiBrick Sample Program](https://makecode.microbit.org/_93d4Ez5qL1iC)

[Koi Sample Program](https://makecode.microbit.org/_7sR03CL49ebj)

On the ThingSpeak page, you can see the published data.

![](https://kittenbothk.readthedocs.io/en/latest/_images/173.png)

#### Subscribing to ThingSpeak Channel[](https://kittenbothk-eng.readthedocs.io/en/latest/Wifibrick/MakeCode/MC_TS.html#subscribing-to-thingspeak-channel)

We can read the channel data by subscribing to the channel.

* MQTT Topic: channels/\[Channel ID]/subscribe/fields/field\[field No.]

Press A to publish a message to the channel, Micro:bit will display the data received.

![.](https://kittenbothk-eng.readthedocs.io/en/latest/_images/thingspeak_code2.png)

[WiFiBrick Sample Program](https://makecode.microbit.org/_FEhijMY0ig37)

[KOI Sample Program](https://makecode.microbit.org/_ec2FpyU2ihub)

You are welcome to join our Whatsapp group to share your IoT projects!

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/iot-59.png)

### 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](https://kittenbothk-eng.readthedocs.io/en/latest/Makecode/makecode_extensionUpdate.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub-eng.kittenbot.hk/wifibrick_iot/makecode/thingspeak.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
