# WiFi and IoT

### Notice for using WiFi

### KOI 2 can only connect to WiFi networks with a 2.4GHz frequency, please make sure that the WiFi network is compatible.

### MakeCode Programming Tutorial

#### Extension link: [**https://github.com/KittenBot/pxt-koi2**](https://github.com/KittenBot/pxt-koi2)

Search for KOI2 in the search bar, select KOI 2.(KOI 2 has been approved by Microsoft)

<figure><img src="/files/Sw7BOOSrTSX5zHmVemsd" alt=""><figcaption></figcaption></figure>

The extension will be imported into your project.

### Coding Blocks

<figure><img src="/files/2qaAQSt8I6HCWaUBs0iY" alt=""><figcaption></figcaption></figure>

### Sample Program

### Connecting to a WiFi network

{% hint style="info" %}
KOI 2 can only connect to WiFi networks with a 2.4GHz frequency, please make sure that the WiFi network is compatible.
{% endhint %}

{% hint style="info" %}
Armourbit users need to use the corresponding initialization block
{% endhint %}

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6uJvpXC43onNIIwhMlWo%2Fuploads%2FPGyECwlPd2M3JqUBLDfO%2Fimage.png?alt=media&#x26;token=662ace3f-a8eb-4fbf-8a10-1d9643c88b1e" alt=""><figcaption></figcaption></figure>

{% embed url="<https://makecode.microbit.org/_cEy78WKd6XVR>" %}

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

#### Sample Program Operations

1. Press Button A on the Micro:bit to connect to a Wifi network.
2. Press Button B on the Micro:bit to display the IP address.

{% hint style="info" %}
Before continuing to the next section, please make sure the KOI has successfully connected to the Wifi network and an IP address is obtained.

If the IP address shows 0.0.0.0, it means that the KOI has failed to connect to the network.
{% endhint %}

<div><figure><img src="/files/ybR6h2eaei9e5THG4PS5" alt=""><figcaption></figcaption></figure> <figure><img src="/files/1xyLt7tD4UDIWBKCfkby" alt=""><figcaption></figcaption></figure></div>

### Connecting with MQTT Platform

{% hint style="info" %}
Armourbit users need to use the corresponding initialization block
{% endhint %}

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6uJvpXC43onNIIwhMlWo%2Fuploads%2FPGyECwlPd2M3JqUBLDfO%2Fimage.png?alt=media&#x26;token=662ace3f-a8eb-4fbf-8a10-1d9643c88b1e" alt=""><figcaption></figcaption></figure>

{% embed url="<https://makecode.microbit.org/_CgYhzEgsX22E>" %}

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

#### Sample Program Operations

1. Press Button A on the Micro:bit to connect to Wifi and MQTT Platform.
2. Press Button B on the Micro:bit to publish a message on the MQTT channel.
3. Micro:bit will display the message received on the MQTT channel.

### MakerCloud Sample Program

{% embed url="<https://makecode.microbit.org/_DovYtzcEhbfk>" %}

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

Messages sent to Makercloud need to follow this formatting, for dn and dsn, any value is fine so as you choose an unique value, for key, replace it with the field name of the MQTT channel.

<figure><img src="/files/3oqbXKT97hMoXYrv4AOe" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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/airelated/ai-camera-koi-2/makecode-programming/wifi-and-iot.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.
