Using KOI to publish message
Before publishing messages to MakerCloud, users must first learn how to connect KOI to MakerCloud via MQTT: Use KOI to connect to MakerCloud
KOI
As long as you successfully connect to MakerCloud, you can use the same publishing blocks to publish messages. Note that you must connect to Wi-Fi and MakerCloud when you start each program.
Publishing blocks
In the MakerCloud expansion, there are different types of publish blocks to allow different data types to be sent to MakerCloud.
Publish a text message
Publishes a text message to a topic via KOI on MakerCloud
Publish key text to message
Publishes a key text message to a topic through KOI on MakerCloud
Publish key-value pair message
Publishes a key-value pair message to a topic through KOI to MakerCloud, and the corresponding line chart will be automatically created on MakerCloud
Publish latitude and longitude update
Publishes a latitude/longitude message to a topic through KOI on MakerCloud
Exercises
Publishing text messages
Learning Focus
- Learn how to publish text messages to MakerCloud topics through KOI
Say "hello" to MakerCloud
Goals
When you press the A button on your micro:bit, the micro:bit will publish the text message "hello" to MakerCloud.
Preparation on MakerCloud:
- Create a project
- Create a topic
Programming on MakeCode:
- Create a new project
- Join KOI extension https://github.com/KittenBot/pxt-koi
- Join MakerCloud KOI Extension https://github.com/scaleinnotech/pxt-makercloud-koi
- On start: Update KOI interface, connect to WiFi and MakerCloud
- When button "A" is pressed: publish text message
- Copy the topic name in MakerCloud
- Paste in the "topic" of the publish text message block
- Enter "hello" in "message"
- Download the program to micro:bit
When finished, return to your project's homepage of MakerCloud. After pressing button A on your micro:bit, you should see the text messages from the micro:bit in the real-time data log.
Publishing key-value pair messages
Learning Focus
- Learn how to publish key-value pairs to topics on MakerCloud through KOI
- Learn to create a line graph on MakerCloud to display and record key-value pair messages
Publishing random numbers
Goals
- When you press button A on your micro:bit, the micro:bit will publish a key-value pair (random number) to MakerCloud
- Create a line graph on MakerCloud to display and record key-value pairs
Preparation on MakerCloud:
- Create a project
- Create a topic
Programming on MakeCode:
- Create a new
- Join KOI extension https://github.com/KittenBot/pxt-koi
- Join MakerCloud KOI Extension https://github.com/scaleinnotech/pxt-makercloud-koi
- On start: Update KOI interface, connect to WiFi and MakerCloud
- When button "A" is pressed: Publish a key-value pair
Note: There are publish key text pairs and publish key-value pairs in the publish blocks. You can use either one. 6. Copy the topic name in MakerCloud
- Paste in the "topic" of the publish text message block
- Enter "num" in "key", and add "random number 0-10" in 0
- Download the program to micro:bit
When finished, return to your project's homepage on MakerCloud. After pressing button A on your micro:bit, you should see the key-value pair messages from the micro:bit in the real-time data viewer.
Then refresh your project's homepage and go to the chart homepage.
MakerCloud will automatically record the name of the key and create a chart for it.