IoT Platform x MIT AI2

IoT use cases are usually paired with a mobile application, by using MIT AI2, we can easily build an app for using IoT use cases.

MakerCloud x MIT AI2

MakerCloud has an official extension for using their platform with MIT AI2, please refer to their official documentation for details.

MakerCloud Official Documentation

Other IoT Platform x MIT AI2

Most platforms supporting MQTT will support MIT AI2, ThingSpeak is used as an example in this article.

Download a 3rd party MQTT extension for AI2.

Download Extension

../../_images/118.png

Download the file from Download section.

../../_images/28.png

Extract the aix file.

../../_images/38.png

../../_images/410.png

Go to MIT AI2, open a new project.

MIT AppInventor 2

../../_images/57.png

Find “Import Extension” from the left hand side menu.

../../_images/64.png

Upload the aix file.

../../_images/74.png

../../_images/83.png

Drag the component into the screen.

../../_images/93.png

In the properties of the MQTT component, enter the MQTT host in the Broker field.

Fill in other parameters according to the requirements of your IoT platform.

For ThingSpeak, fill in mqtt.thingspeak.com for broker and your ThingSpeak clientID for clientID.

../../_images/103.png

Enter UserName and UserPassword if required, for ThingSpeak, enter the user name and password here.

../../_images/119.png

Connecting to your chosen platform

Build the following program to test if you can connect to the IoT platform.

../../_images/124.png

../../_images/134.png

After pressing the button, the text should change to “true”, this indicates a connection to the IoT platform has been established.

../../_images/141.jpg

Publishing messages on AI2

Try sending a random number to the platform.

../../_images/152.png

../../_images/161.png

../../_images/172.png

Enter the topic name, ThingSpeak is used as the example in this article.

../../_images/182.png

Attach a string element to the message parameter.

../../_images/192.png

For ThingSpeak, join the 2 strings containing the field number and the data.

../../_images/201.png

Try the program, you should be able to see the data on ThingSpeak.

../../_images/211.png

Subscribing to MQTT on AI2

We can also subscribe and listen to MQTT data.

Build the following program to read MQTT data.

../../_images/221.png

../../_images/231.png

Use the following block to trigger an action after a message is received.

../../_images/241.png

Try the program, you should be able to see the data on ThingSpeak and on your app.

../../_images/251.png

../../_images/261.jpg

Download Sample Program

The above program is available to download.

AI2 Sample Program Download