增加部分状态显示

This commit is contained in:
zjk
2025-05-21 09:33:44 +08:00
parent fea319d3bf
commit af8e7a1ed1
11 changed files with 206 additions and 119 deletions
@@ -86,6 +86,38 @@ void HttpServer::handleWebSocketEvent(struct mg_connection* c, int ev, void* ev_
// 返回测试页面HTML
mg_http_reply(c, 200, "Content-Type: text/html; charset=utf-8\r\n", TESTPAGE_HTML.c_str());
}
} else if (mg_match(hm->uri, mg_str("/moosdb_test"), NULL)) {
if (mg_strcmp(hm->method, mg_str("POST")) == 0) {
// 解析JSON请求
char *key = mg_json_get_str(hm->body, "$.key");
char *value = mg_json_get_str(hm->body, "$.value");
if (key && value) {
LOG_F(INFO, "Received MOOSDB test message: key=%s, value=%s", key, value);
// TODO: 这里添加处理MOOSDB测试消息的逻辑
// 例如: m_powerManger->handleMoosdbTest(key, value);
bool success = true;
success = m_powerManger->sendNotification(key,value);
if (!success) {
mg_http_reply(c, 500, "Content-Type: application/json\r\n",
"{\"success\": false, \"error\": \"Failed to send MOOSDB test message\"}");
return;
}
// 返回成功响应
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{\"success\": true, \"message\": \"MOOSDB test message received\"}");
} else {
mg_http_reply(c, 400, "Content-Type: application/json\r\n",
"{\"success\": false, \"error\": \"key and value fields are required\"}");
}
// 释放分配的内存
if (key) free(key);
if (value) free(value);
} else {
mg_http_reply(c, 405, "Content-Type: text/plain\r\n", "Method Not Allowed");
}
} else if (mg_match(hm->uri, mg_str("/control"), NULL)) {
// 处理断路器控制请求
if (mg_strcmp(hm->method, mg_str("POST")) == 0) {
@@ -520,6 +552,9 @@ void HttpServer::pushSystemData() {
j["moosdb"]["cpuLoad"] = Json::Value(m_powerManger->GetPublicCPULoad());
j["moosdb"]["timeSinceIterate"] = Json::Value(m_powerManger->GetPublicTimeSinceIterate());
j["moosdb"]["lastIterateTime"] = Json::Value(m_powerManger->GetPublicLastIterateTime());
j["moosdb"]["lastIterateCount"] = Json::Value(m_powerManger->GetPublicIterateCount());
j["moosdb"]["serverHost"] = Json::Value(m_powerManger->GetServerHost());
j["moosdb"]["serverPort"] = Json::Value(m_powerManger->GetServerPort());
// 时间戳
j["timestamp"] = Json::Value((Json::UInt64)(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count()));