> 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/mckb.md).

# Makecode X KittenBlock IoT

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

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

### Foreword

We will learn how to use WifiBrick and KittenBlock to develope IoT application.

```
KOI is also supported.
```

### Step 1: Setting Up KittenBlock

#### The computer must connect to the same network as the WifiBrick.

Activate local MQTT client.

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

### Step 2: Kittenblock Programming

We will write a simple script in KittenBlock to allow us to send and receive messages.

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

Import the IoT extension.

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

Build the following program, fill in the MQTT server address if it is not automaically inputted.

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

#### Programming Wifibrick

Open MakeCode, import WifiBrick extension.

Wifibrick Extension: **<https://github.com/KittenBot/pxt-kittenwifi>**

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

Build th following program and fill in the Wifi name and password.

Input the host ip and the topic name of the local IoT client from KittenBlock.

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

Upload the program and wait for the WifiBrick to finish connection, press A to send the brightness value to local IoT client, the KittenBlock program will display the value.

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

Return to KittenBlock and modify the program to allow it to send an IoT message to Micro:bit.

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

Modify the program in MakeCode to allow WifiBrick to read IoT messages.

Subscribe to the same topic that the KittenBlock program is publishing to.

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

Micro:bit will now show the icon based on the message it receives.

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

#### Programming KOI

Open MakeCode and import KOI extension.

KOI Extension: **<https://github.com/KittenBot/pxt-koi>**

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

KOI is programmed similarly to WifiBrick. But KOI will need a MQTT Read block for getting IoT messages whereas it is automatic on WifiBrick.

Build the following program and enter the Wifi credentials and the host address.

Use the same topics between KittenBlock and KOI.

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

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


---

# 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/mckb.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.
