From d3151dd787520ce4e3616b64e4e331e8bd448aec Mon Sep 17 00:00:00 2001 From: dgjames <1943357252@qq.com> Date: Wed, 12 Mar 2025 20:29:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F2s=E5=88=A4=E6=96=AD=E8=81=94=E7=BD=91?= =?UTF-8?q?=EF=BC=88=E6=9C=89=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/keil-assistant.log | 14 ++++++++ .vscode/settings.json | 4 ++- .vscode/tasks.json | 8 ++--- applications/init.c | 2 +- applications/main.c | 4 +-- my_pro/my_func.c | 1 + my_pro/my_func.h | 1 + my_pro/myproject.c | 65 +++++++++++++++++++++++++++++++++++--- 8 files changed, 86 insertions(+), 13 deletions(-) diff --git a/.vscode/keil-assistant.log b/.vscode/keil-assistant.log index 0d18101..21fe735 100644 --- a/.vscode/keil-assistant.log +++ b/.vscode/keil-assistant.log @@ -20,3 +20,17 @@ [info] Log at : 2025/1/18|00:50:06|GMT+0800 +[info] Log at : 2025/2/3|17:47:00|GMT+0800 + +[info] Log at : 2025/2/11|20:47:29|GMT+0800 + +[info] Log at : 2025/2/13|18:00:08|GMT+0800 + +[info] Log at : 2025/2/16|09:16:38|GMT+0800 + +[info] Log at : 2025/2/18|16:29:01|GMT+0800 + +[info] Log at : 2025/3/5|20:26:51|GMT+0800 + +[info] Log at : 2025/3/10|21:09:20|GMT+0800 + diff --git a/.vscode/settings.json b/.vscode/settings.json index e3877c1..c100fee 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -27,7 +27,9 @@ "rgb.h": "c", "main.h": "c", "indicator_led.h": "c", - "drv_matrix_led.h": "c" + "drv_matrix_led.h": "c", + "init.h": "c", + "string.h": "c" }, // "cortex-debug.openocdPath": "d:/Develop/" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a60053e..8ddf9c6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -81,7 +81,7 @@ { "label": "编译下载(j1)", "type": "shell", - "command": "scons -j1 && copy /z ${workspaceFolder}\\rtthread.bin f:\\", + "command": "scons -j1 && copy /z ${workspaceFolder}\\rtthread.bin g:\\", "args": [], "problemMatcher": { "owner": "cpp", @@ -103,7 +103,7 @@ "label": "编译下载(j8)", "type": "shell", // "command": "scons -j8 && pyocd flash -t stm32l431rctx ${workspaceFolder}/rt-thread.elf", - "command": "scons -j8 && copy /z ${workspaceFolder}\\rtthread.bin f:\\", + "command": "scons -j8 && copy /z ${workspaceFolder}\\rtthread.bin g:\\", "args": [], "problemMatcher": { "owner": "cpp", @@ -132,7 +132,7 @@ "label": "下载固件(pyocd)", "type": "shell", // "command": "pyocd flash -t stm32l431rctx ${workspaceFolder}/rt-thread.elf", - "command": "copy /z ${workspaceFolder}/rtthread.bin f:\\", + "command": "copy /z ${workspaceFolder}/rtthread.bin g:\\", "args": [], "args": [], @@ -191,7 +191,7 @@ "label": "全部编译下载(j8)", "type": "shell", // "command": "scons -c && cd ${workspaceFolder} && rm -fv *.elf *.hex *.bin *.map && scons -j8 && pyocd flash -t stm32l431rctx ${workspaceFolder}/rt-thread.elf", - "command": "scons -c && cd ${workspaceFolder} && rm -fv *.elf *.hex *.bin *.map && scons -j8 && copy /z ${workspaceFolder}/rtthread.bin f:\\", + "command": "scons -c && cd ${workspaceFolder} && rm -fv *.elf *.hex *.bin *.map && scons -j8 && copy /z ${workspaceFolder}/rtthread.bin g:\\", "args": [], "problemMatcher": { "owner": "cpp", diff --git a/applications/init.c b/applications/init.c index a07d508..0e6eda6 100644 --- a/applications/init.c +++ b/applications/init.c @@ -52,7 +52,7 @@ int main_init(void) char str[] = "wifi join Dong abcd07691234"; my_round(20); - system(str); + // system(str); // rt_thread_mdelay(18000); // char *argv[] = {"wifi", "join", "Dong", "abcd07691234"}; // wifi_join(4, argv); diff --git a/applications/main.c b/applications/main.c index 9c5b298..c223c3e 100644 --- a/applications/main.c +++ b/applications/main.c @@ -39,8 +39,8 @@ int main(void) system("snake"); // rt_wlan_config_autoreconnect(RT_TRUE); // rt_wlan_connect("Dong", "abcd07691234"); - rt_wlan_connect("as", "88888888"); - rt_wlan_connect("as", "88888888"); + // rt_wlan_connect("as", "07691234"); + // wlan_connected=rt_wlan_connect("as", "07691234"); system("myproject"); // system("mqtt"); mytime(); diff --git a/my_pro/my_func.c b/my_pro/my_func.c index 72e5c66..308d9fe 100644 --- a/my_pro/my_func.c +++ b/my_pro/my_func.c @@ -10,6 +10,7 @@ //串口 rt_device_t serial; char str[] = "forward\n"; +int wlan_connected=-RT_ERROR; extern char tmp[]; void lcd_black(int x, int y) diff --git a/my_pro/my_func.h b/my_pro/my_func.h index bf9bd4e..0b2368e 100644 --- a/my_pro/my_func.h +++ b/my_pro/my_func.h @@ -9,6 +9,7 @@ //串口 extern rt_device_t serial; extern char str[]; +extern int wlan_connected; void mytime(); void greattime(); diff --git a/my_pro/myproject.c b/my_pro/myproject.c index 3cee4fd..6521571 100644 --- a/my_pro/myproject.c +++ b/my_pro/myproject.c @@ -16,7 +16,6 @@ #include #include "my_func.h" #include "indicator_led.h" - #define THREAD_PRIORITY 25 #define THREAD_STACK_SIZE 4096 #define THREAD_TIMESLICE 5 @@ -30,6 +29,7 @@ rt_thread_t Test_Thread = RT_NULL; rt_thread_t CDC_Thread = RT_NULL; rt_thread_t Serial_Thread = RT_NULL; rt_thread_t LED_Thread = RT_NULL; +rt_thread_t wlan_connect_tid = RT_NULL; char DEMO_PRODUCT_KEY[IOTX_PRODUCT_KEY_LEN + 1] = {0}; char DEMO_DEVICE_NAME[IOTX_DEVICE_NAME_LEN + 1] = {0}; @@ -44,6 +44,9 @@ int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN]); uint64_t HAL_UptimeMs(void); int HAL_Snprintf(char *str, const int len, const char *fmt, ...); +#define WLAN_CONNECTED 1; +#define WLAN_DISCONNECTED 0; + // 定义接受文件内容的缓冲区 char buffer[1026] = {}; char tmp[1026]; @@ -52,7 +55,8 @@ rt_atomic_t page_chosen = 1; rt_atomic_t page_first = 1; rt_atomic_t page_stop = 0; rt_atomic_t last_stop = 0; -rt_atomic_t mqtt_enable = 0; +rt_atomic_t last_connect_status = -RT_ERROR; +rt_atomic_t mqtt_enable = 1; void *pclient = NULL; @@ -270,11 +274,29 @@ void tmp_payload(void) else { lcd_show_string(240 / 2 - 24 * 2, 240 / 2 + 12, 32, "enable "); - if (mqtt_enable && !last_stop) + if (mqtt_enable && !last_stop && wlan_connected == RT_EOK) { last_stop = 1; mqt_init(); } + if (wlan_connected == RT_EOK) + { + lcd_show_string(240 / 2 - 24 * 2, 240 / 2 + 12 + 32, 32, "connect"); + // if (last_connect_status != RT_EOK) + // { + // mqt_init(); + // } + } + else + { + lcd_show_string(240 / 2 - 24 * 2, 240 / 2 + 12 + 32, 32, "disconnect"); + // if (last_connect_status == RT_EOK) + // { + // IOT_MQTT_Destroy(&pclient); + // rt_thread_delete(MQTT_Thread); + // } + } + // last_connect_status = wlan_connected; } } if (ps_data > 1022) @@ -408,7 +430,19 @@ void cdc_entry(void *parameter) rt_thread_mdelay(500); } } +void wlan_connect_thread(void *parameter) +{ + (void *)parameter; + while (1) + { + if (wlan_connected != RT_EOK) + { + wlan_connected = rt_wlan_connect("as", "07691234"); + } + rt_thread_mdelay(2000); + } +} // /* 用于接收消息的信号量 */ // static struct rt_semaphore rx_sem; // /* 接收数据回调函数 */ @@ -462,6 +496,20 @@ void ath_init(void) return; } } +void wla_init(void) +{ + wlan_connect_tid = rt_thread_create("wlanas", wlan_connect_thread, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); + + if (wlan_connect_tid != RT_NULL) + { + rt_thread_startup(wlan_connect_tid); + } + else + { + rt_kprintf("wlan_connect_thread Create Failed!\n"); + } +} +MSH_CMD_EXPORT_ALIAS(wla_init, wla_init, "Infrared"); void serial_init(void) { // // 初始化设备 @@ -505,7 +553,7 @@ void serial_init(void) } 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("MQTT_Thread", mqtt_example_main, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (MQTT_Thread != RT_NULL) { @@ -591,6 +639,7 @@ void tst_init(void) } } MSH_CMD_EXPORT_ALIAS(tst_init, no_mqtt, "Infrared"); + // void evn_init(void) // { // if(rt_event_create("my_event2", RT_IPC_FLAG_FIFO) != RT_EOK) @@ -607,7 +656,13 @@ void my_project(void) ath_init(); - // mqt_init(); + wla_init(); + + if (wlan_connected == RT_EOK) + { + last_stop = 1; + mqt_init(); + } ap3_init();