暂时不编译day5,lcd显示温度成功

This commit is contained in:
james 2024-08-01 11:09:36 +08:00
parent be09a1c768
commit b846ef98a6
4 changed files with 25 additions and 12 deletions

View File

@ -2,9 +2,7 @@ from building import *
import os import os
cwd = GetCurrentDir() cwd = GetCurrentDir()
src = [ src = [ ]
'mqtt.c',
]
CPPPATH = [cwd] CPPPATH = [cwd]

View File

@ -4,3 +4,5 @@
![alt text](image.png) ![alt text](image.png)
关了就好了 关了就好了
![alt text](image-1.png) ![alt text](image-1.png)
### 开了soft rtc
![alt text](image-3.png)

BIN
dayandnight/image-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -38,6 +38,8 @@ char tmp[1026];
// Humi:湿度值,Temp:温度值 // Humi:湿度值,Temp:温度值
float Humi, Temp; float Humi, Temp;
void ath_init(void);
void mqt_init(void);
#define EXAMPLE_TRACE(fmt, ...) \ #define EXAMPLE_TRACE(fmt, ...) \
do { \ do { \
@ -104,7 +106,10 @@ static int example_subscribe(void *handle)
void show_lcd() void show_lcd()
{ {
lcd_show_string(10, 69 + 16 + 24, 32, tmp); sprintf(tmp, "Temp: %.3f", Temp);
lcd_show_string(10, 10, 24, tmp);
sprintf(tmp, "Humi: %.3f", Humi);
lcd_show_string(10, 10+24, 24, tmp);
} }
void make_file() void make_file()
@ -144,12 +149,13 @@ void tmp_payload(void)
sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt); sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp); // rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
make_file(); make_file();
lcd_show_string(10, 69 + 16 + 24, 32, "RT-Thread"); show_lcd();
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f}}", Temp, Humi); sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f}}", Temp, Humi);
return; return;
} }
void test_lcd() void test_lcd()
{ {
ath_init();
while(1) while(1)
{ {
tmp_payload(); tmp_payload();
@ -245,9 +251,8 @@ static void mqtt_example_main(void *parameter)
rt_thread_t MQTT_Thread = RT_NULL; rt_thread_t MQTT_Thread = RT_NULL;
void my_project(void) void ath_init(void)
{ {
// 初始化设备 // 初始化设备
Dev = aht10_init(AHT10_I2C_BUS); Dev = aht10_init(AHT10_I2C_BUS);
if (Dev == RT_NULL) if (Dev == RT_NULL)
@ -255,7 +260,9 @@ void my_project(void)
rt_kprintf("AHT10_init Fail"); rt_kprintf("AHT10_init Fail");
return; return;
} }
}
void mqt_init(void)
{
MQTT_Thread = rt_thread_create("MTQQ_Thread", mqtt_example_main, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); MQTT_Thread = rt_thread_create("MTQQ_Thread", mqtt_example_main, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
if (MQTT_Thread != RT_NULL) if (MQTT_Thread != RT_NULL)
@ -266,6 +273,12 @@ void my_project(void)
{ {
rt_kprintf("MQTT Thread Create Failed!\n"); rt_kprintf("MQTT Thread Create Failed!\n");
} }
}
void my_project(void)
{
ath_init();
mqt_init();
} }
MSH_CMD_EXPORT_ALIAS(my_project,myproject, run my project); MSH_CMD_EXPORT_ALIAS(my_project,myproject, run my project);