●RT-Thread Studio/Keil MDK5(固件开发、编译)
●SquareLine Studio(LVGL UI设计工具)
资料链接
●RT-Thread Studio下载链接:
https://download_redirect.rt-thread.org/download/studio/RT-Thread_Studio_2.2.7-setup-x86_64.exe
●SquareLine Studio下载链接:https://static.squareline.io/downloads/SquareLine_Studio_Windows_v1_3_2.zip
●MQTTX 下载链接:
https://packages.emqx.net/MQTTX/v1.9.6/MQTTX-Setup-1.9.6-x64.exe
●项目代码链接:
https://gitee.com/Rbb666/hmi-board-eth-monitor
如果遇到家庭网络连接没有以太网选项,请按照如下步骤:
1、电脑连接手机热点
2、使能电脑的移动热点
3、回到WLAN属性界面,则会显示以太网选项了
获取到IP地址后,可以输入 ping www.baidu.com 测试网络是否可以用。
在 RT-Thread Setting 中搜索 Kawaii-mqtt 软件包,并使能mqtt test功能,
然后ctrl+s 拉取软件包到工程内:
将下面代码粘贴覆盖 packages/kawaii-mqtt-latest/test/test.c
#include
#include
#include
#include
#include
#include "mqttclient.h"
static void sub_topic_handle1(void* client, message_data_t* msg)
{
(void) client;
KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
KAWAII_MQTT_LOG_I("%s:%d %s()...\ntopic: %s\nmessage:%s", __FILE__, __LINE__, __FUNCTION__, msg->topic_name, (char*)msg->message->payload);
KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------");
}
static int mqtt_publish_handle1(mqtt_client_t *client)
{
mqtt_message_t msg;
memset(&msg, 0, sizeof(msg));
msg.qos = QOS0;
msg.payload = (void *)"this is a kawaii mqtt test ...";
return mqtt_publish(client, "pub5323", &msg);
}
static char cid[64] = { 0 };
static void kawaii_mqtt_demo(void *parameter)
{
mqtt_client_t *client = NULL;
rt_thread_delay(6000);
mqtt_log_init();
client = mqtt_lease();
rt_snprintf(cid, sizeof(cid), "rtthread-5323", rt_tick_get());
mqtt_set_host(client, "broker.emqx.io");
mqtt_set_port(client, "1883");
mqtt_set_user_name(client, "RT-Thread");
mqtt_set_password(client, "012345678");
mqtt_set_client_id(client, cid);
mqtt_set_clean_session(client, 1);
KAWAII_MQTT_LOG_I("The ID of the Kawaii client is: %s ",cid);
mqtt_connect(client);
mqtt_subscribe(client, "sub5323", QOS0, sub_topic_handle1);
while (1) {
mqtt_publish_handle1(client);
mqtt_sleep_ms(4 * 1000);
}
}
int ka_mqtt(void)
{
rt_thread_t tid_mqtt;
tid_mqtt = rt_thread_create("kawaii_demo", kawaii_mqtt_demo, RT_NULL, 2048, 17, 10);
if (tid_mqtt == RT_NULL) {
return -RT_ERROR;
}
rt_thread_startup(tid_mqtt);
return RT_EOK;
}
MSH_CMD_EXPORT(ka_mqtt, Kawaii MQTT client test program);
{
"temp": 23,
"humi": 20,
"lux": 120
}
使用MQTT工具向开发板订阅的Topic发送数据:
开发板串口终端接收到此消息,并打印:
导入工程有以下两种方式,请任选其一即可(推荐方式一):
方式一:使用RT-Thread Studio