08 - MQTT Internet of Things
Overview
MQTT is a publish-subscribe messaging protocol that is designed for use in IoT applications and is relatively straightforward to implement.
Getting Started
The following tutorial uses KittenBot's IoT platform as the server. Before using it, please register at https://iot.kittenbot.cn/.
Create an MQTT Topic
Set the topic path (filling in the topic username and password can set the topic as private. You can leave it blank; the topic will be a public topic. Anyone with the topic path can view it.)
warning The topic is unique across the platform. Please set a relatively personalized topic. Try not to set it as a common name like temp.
After creation, click Connect to Topic
Send a test message
<br />
dangerYou may need to refresh to see the new message.
<br />
How to Use
Brick Introduction
Programming Brick | Function Introduction |
---|---|
Connect to WiFi | |
Return WiFi IP address, return 0.0.0.0 if not connected | |
Connect to Meow home MQTT server, public topic | |
If you need to use a private MQTT topic, you can use this brick to enter the username and password | |
Subscribe to a topic | |
Send a message to a topic | |
Read the topic message, you need to subscribe first |
Case 1 - Smart home lamp
This case introduces the communication control of two Grapeboards. If you only have one Grapeboard, you can use it as the controlled receiving end
, and you can directly send instructions to the corresponding topic through the MQTT server page for control.
Effect: You can remotely control the device using the MQTT server as a medium.
<br/><br/>
Program - Control End
Program - Controlled End