mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-07 02:42:49 +08:00
修复在不配置MQTT信息的情况下,OTA将大概率无法进行,且后台可能经常卡死刷不出页面的问题
This commit is contained in:
@@ -54,6 +54,7 @@ static bool is_handlers_registered;
|
||||
const struct httpd_wsgi_call g_app_handlers[];
|
||||
char power_info_json[2560] = {0};
|
||||
char up_time[16] = "00:00:00";
|
||||
#define CHUNK_SIZE 512 // 每次发送 512 字节,避免 buffer 太大
|
||||
|
||||
/*
|
||||
void GetPraFromUrl(char* url, char* pra, char* val)
|
||||
@@ -90,16 +91,30 @@ void GetPraFromUrl(char* url, char* pra, char* val)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static OSStatus send_in_chunks(int sock, const uint8_t *data, int total_len) {
|
||||
OSStatus err = kNoErr;
|
||||
for (int offset = 0; offset < total_len; offset += CHUNK_SIZE) {
|
||||
int chunk_len = (total_len - offset > CHUNK_SIZE) ? CHUNK_SIZE : (total_len - offset);
|
||||
err = httpd_send_body(sock, data + offset, chunk_len);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Send chunk failed at offset %d", offset));
|
||||
}
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int HttpGetIndexPage(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
int total_sz = sizeof(web_index_html);
|
||||
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(web_index_html), HTTP_CONTENT_HTML_ZIP);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index headers."));
|
||||
|
||||
err = httpd_send_body(req->sock, web_index_html, sizeof(web_index_html));
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http index body."));
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, HTTP_CONTENT_HTML_ZIP);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send index headers."));
|
||||
|
||||
exit:
|
||||
err = send_in_chunks(req->sock, web_index_html, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send index body."));
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -107,14 +122,15 @@ static int HttpGetAssets(httpd_request_t *req) {
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
char *file_name = strstr(req->filename, "/assets/");
|
||||
if (!file_name) { http_log("HttpGetAssets url[%s] err", req->filename);
|
||||
if (!file_name) {
|
||||
http_log("HttpGetAssets url[%s] err", req->filename);
|
||||
return err;
|
||||
}
|
||||
//http_log("HttpGetAssets url[%s] file_name[%s]", req->filename, file_name);
|
||||
|
||||
int total_sz = 0;
|
||||
const unsigned char *file_data = NULL;
|
||||
const char *content_type = HTTP_CONTENT_JS_ZIP;
|
||||
|
||||
if (strcmp(file_name + 8, "js_pack.js") == 0) {
|
||||
total_sz = sizeof(js_pack);
|
||||
file_data = js_pack;
|
||||
@@ -122,17 +138,25 @@ static int HttpGetAssets(httpd_request_t *req) {
|
||||
total_sz = sizeof(css_pack);
|
||||
file_data = css_pack;
|
||||
content_type = HTTP_CONTENT_CSS_ZIP;
|
||||
} else if (strcmp(file_name + 8, "index.html") == 0) {
|
||||
total_sz = sizeof(web_index_html);
|
||||
file_data = web_index_html;
|
||||
content_type = HTTP_CONTENT_HTML_ZIP;
|
||||
}
|
||||
|
||||
if (total_sz == 0 || file_data == NULL) {
|
||||
http_log("File not found: %s", req->filename);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (total_sz == 0) return err;
|
||||
|
||||
err = httpd_send_all_header(req, HTTP_RES_200, total_sz, content_type);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets headers."));
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset headers."));
|
||||
|
||||
err = httpd_send_body(req->sock, file_data, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send http assets body."));
|
||||
err = send_in_chunks(req->sock, file_data, total_sz);
|
||||
require_noerr_action(err, exit, http_log("ERROR: Unable to send asset body."));
|
||||
|
||||
exit:
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -392,7 +416,10 @@ static int HttpSetMqttConfig(httpd_request_t *req) {
|
||||
|
||||
sscanf(buf, "%s %d %s %s", MQTT_SERVER, &MQTT_SERVER_PORT, MQTT_SERVER_USR, MQTT_SERVER_PWD);
|
||||
mico_system_context_update(sys_config);
|
||||
|
||||
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||
err = UserMqttInit();
|
||||
require_noerr(err, exit);
|
||||
}
|
||||
send_http("OK", 2, exit, &err);
|
||||
|
||||
exit:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const unsigned char js_pack[0xd2be] = {
|
||||
0x1f,0x8b,0x08,0x00,0xb9,0xf8,0xf9,0x67,0x02,0xff,0xd4,0xbd,0xfb,0x72,0xdb,0x46,
|
||||
0x1f,0x8b,0x08,0x00,0x7d,0xc5,0xff,0x67,0x02,0xff,0xd4,0xbd,0xfb,0x72,0xdb,0x46,
|
||||
0xd2,0x38,0xfa,0xff,0x56,0xed,0x3b,0x88,0x48,0x96,0x01,0xc4,0x21,0x45,0xca,0xb1,
|
||||
0x13,0x83,0x1e,0xb1,0x1c,0xdb,0x49,0xbc,0x5f,0x9c,0x64,0xe3,0x5c,0x97,0x62,0x52,
|
||||
0xb8,0x92,0xa0,0x48,0x82,0xe2,0xc5,0x12,0x23,0x72,0xdf,0xe7,0xf7,0x1a,0xe7,0xc9,
|
||||
@@ -3372,7 +3372,7 @@ const unsigned char js_pack[0xd2be] = {
|
||||
0x02,0x0f,0xb7,0x98,0x0c,0x59,0x7f,0x97,0xf2,0x25,0x55,0x7c,0x45,0xad,0x25,0x8e,
|
||||
0x0f,0x58,0x4f,0xcc,0x9f,0x00,0x32,0xd2,0xf4,0xa5,0xf0,0xee,0x02,0x00};
|
||||
const unsigned char css_pack[0x6217] = {
|
||||
0x1f,0x8b,0x08,0x00,0xb9,0xf8,0xf9,0x67,0x02,0xff,0xed,0xbd,0x79,0x73,0xdb,0xc8,
|
||||
0x1f,0x8b,0x08,0x00,0x7e,0xc5,0xff,0x67,0x02,0xff,0xed,0xbd,0x79,0x73,0xdb,0xc8,
|
||||
0xf5,0x28,0xfa,0x7f,0xaa,0xf2,0x1d,0x70,0x9d,0x9a,0x1a,0x6b,0x42,0xc8,0xd8,0x49,
|
||||
0x4a,0x95,0x54,0xbc,0x8f,0x26,0x96,0x9c,0x78,0x19,0x8f,0x9d,0x5f,0x9e,0x0b,0x04,
|
||||
0x9a,0x24,0x24,0x90,0x60,0x00,0x50,0x1b,0x4b,0xb7,0xee,0x07,0xb9,0xef,0xcb,0xbd,
|
||||
@@ -4943,7 +4943,7 @@ const unsigned char css_pack[0x6217] = {
|
||||
0xe6,0x54,0x09,0x49,0xbc,0xd0,0xc2,0x1c,0x55,0x23,0x76,0x55,0x21,0xff,0x3f,0x3f,
|
||||
0xef,0x85,0xce,0x3d,0xbc,0x02,0x00};
|
||||
const unsigned char web_index_html[0x3477] = {
|
||||
0x1f,0x8b,0x08,0x00,0xb9,0xf8,0xf9,0x67,0x02,0xff,0xed,0x7d,0x6d,0x93,0xdb,0xc6,
|
||||
0x1f,0x8b,0x08,0x00,0x7e,0xc5,0xff,0x67,0x02,0xff,0xed,0x7d,0x6d,0x93,0xdb,0xc6,
|
||||
0x91,0xf0,0xf7,0xab,0xca,0x7f,0x18,0xc3,0xaa,0x90,0xbc,0x25,0x40,0x02,0x7c,0x59,
|
||||
0x72,0xdf,0x52,0xca,0xda,0xc9,0xfa,0xb9,0x95,0xe5,0xcb,0xea,0x94,0xe7,0x4e,0x71,
|
||||
0xd1,0x58,0x02,0xbb,0x84,0x05,0x12,0x34,0x00,0xee,0x6a,0x6d,0xab,0x4a,0x4a,0xce,
|
||||
|
||||
@@ -186,8 +186,10 @@ 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();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
|
||||
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
|
||||
|
||||
#define VERSION "v2.1.6"
|
||||
#define VERSION "v2.1.7"
|
||||
|
||||
#define TYPE 1
|
||||
#define TYPE_NAME "TC1"
|
||||
|
||||
@@ -431,6 +431,9 @@ void ProcessHaCmd(char *cmd) {
|
||||
OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
||||
OSStatus err = kUnknownErr;
|
||||
p_mqtt_send_msg_t p_send_msg = NULL;
|
||||
if(mqtt_msg_send_queue == NULL){
|
||||
return err;
|
||||
}
|
||||
|
||||
// mqtt_log("======App prepare to send ![%d]======", MicoGetMemoryInfo()->free_memory);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user