修复已知问题

This commit is contained in:
Your Name
2025-04-18 22:35:59 +08:00
parent d7e2243a86
commit 3f5078294f
7 changed files with 29 additions and 13 deletions

View File

@@ -326,8 +326,6 @@ static int HttpSetOTAFile(httpd_request_t *req)
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
exit:
if (buffer) free(buffer);
tc1_log("[OTA] buffer");
tc1_log("[OTA] bbbbbbbbbbbbbbbbbbbb");
return err;
// ota_file_req = req;

View File

@@ -10,7 +10,6 @@
#include "user_wifi.h"
#include "time_server/user_rtc.h"
#include "user_power.h"
#include "mqtt_server/user_mqtt_client.h"
#include "http_server/app_httpd.h"
#include "timed_task/timed_task.h"
@@ -186,10 +185,6 @@ int application_start(void) {
}
}
KeyInit();
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
err = UserMqttInit();
require_noerr(err, exit);
}
err = UserRtcInit();
require_noerr(err, exit);
PowerInit();

View File

@@ -53,6 +53,7 @@ mico_queue_t mqtt_msg_send_queue = NULL;
Client c; // mqtt client object
Network n; // socket network for mqtt client
volatile bool mqtt_thread_should_exit = false;
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
//static mico_timed_event_t mqtt_client_send_event;
@@ -98,6 +99,18 @@ void UserMqttTimerFunc(void *arg) {
}
}
OSStatus UserMqttDeInit(void) {
OSStatus err = kNoErr;
// 1. 请求线程退出
mqtt_thread_should_exit = true;
exit:
if (kNoErr != err)
mqtt_log("ERROR: UserMqttDeInit exit err: %d", err);
return err;
}
/* Application entrance */
OSStatus UserMqttInit(void) {
OSStatus err = kNoErr;
@@ -204,14 +217,14 @@ void MqttClientThread(mico_thread_arg_t arg) {
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
require_action(msg_send_event_fd >= 0, exit,
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
mqtt_thread_should_exit = false;
MQTT_start:
isconnect = false;
/* 1. create network connection */
ssl_settings.ssl_enable = false;
LinkStatusTypeDef LinkStatus;
while (1) {
while (!mqtt_thread_should_exit) {
isconnect = false;
mico_rtos_thread_sleep(3);
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
@@ -272,7 +285,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
registerMqttEvents();
/* 5. client loop for recv msg && keepalive */
while (1) {
while (!mqtt_thread_should_exit) {
isconnect = true;
no_mqtt_msg_exchange = true;
FD_ZERO(&readfds);
@@ -329,10 +342,12 @@ mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d,
mico_rtos_thread_sleep(5);
goto MQTT_start;
exit:
isconnect = false;mqtt_log("EXIT: MQTT client exit with err = %d.", err);
exit:
isconnect = false;
mqtt_log("EXIT: MQTT client exit with err = %d.", err);
UserMqttClientRelease(&c, &n);
mico_rtos_delete_thread(NULL);
mico_rtos_delete_thread(NULL); // 自删
return;
}
// callback, msg received from mqtt server

View File

@@ -22,6 +22,7 @@
#define MQTT_LED_ENABLED user_config->power_led_enabled
extern OSStatus UserMqttInit(void);
extern OSStatus UserMqttDeInit(void);
extern OSStatus UserMqttSend(char *arg);

View File

@@ -239,6 +239,7 @@ static void KeyEventHandler(int num, boolean longPress) {
if (childLockEnabled)
break;
StartLedBlink(3);
UserMqttDeInit();
micoWlanSuspendStation();
ApInit(true);
break;

View File

@@ -4,6 +4,7 @@
#include "mico_socket.h"
#include "user_gpio.h"
#include "http_server/web_log.h"
#include "mqtt_server/user_mqtt_client.h"
char wifi_status = WIFI_STATE_NOCONNECT;
@@ -122,6 +123,9 @@ static void WifiLedTimerCallback(void* arg)
UserLedSet(-1);
break;
case WIFI_STATE_CONNECTED:
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
UserMqttInit();
}
UserLedSet(0);
mico_rtos_stop_timer(&wifi_led_timer);
if (RelayOut()&&user_config->power_led_enabled)

View File

@@ -1125,6 +1125,8 @@ int httpd_parse_hdr_tags(httpd_request_t *req, int sock,
*/
int httpd_get_data(httpd_request_t *req, char *content, int length);
int httpd_get_data2(httpd_request_t *req, char *content, int length);
/** @brief Get the incoming JSON data in case of HTTP POST request
*
* @note This function is an extension to \ref httpd_get_data. Additionally this