获取所有信息

This commit is contained in:
zogodo
2019-09-25 23:31:10 +08:00
parent ad33beaf2b
commit b8cb934702
3 changed files with 15 additions and 10 deletions

View File

@@ -67,16 +67,20 @@ exit:
return err;
}
static int http_get_socket_status(httpd_request_t *req)
#define TC1_STATUS_JSON "{'sockets':'%s','station_ssid':'%s','station_pwd':'%s','ap_ssid':'%s','ap_pwd':'%s'}"
static int http_get_tc1_status(httpd_request_t *req)
{
OSStatus err = kNoErr;
const unsigned char* status = get_socket_status();
const unsigned char* sockets = get_socket_status();
char* tc1_status = malloc(256);
sprintf(tc1_status, TC1_STATUS_JSON, sockets, sys_config->micoSystemConfig.ssid,
sys_config->micoSystemConfig.ssid, "TC1-AP", "123456");
err = httpd_send_all_header(req, HTTP_RES_200, strlen(socket_status), HTTP_CONTENT_HTML_STR);
err = httpd_send_all_header(req, HTTP_RES_200, strlen(tc1_status), HTTP_CONTENT_HTML_STR);
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers."));
err = httpd_send_body(req->sock, status, strlen(socket_status));
err = httpd_send_body(req->sock, (const unsigned char*)tc1_status, strlen(tc1_status));
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body."));
exit:
@@ -166,7 +170,8 @@ save_out:
struct httpd_wsgi_call g_app_handlers[] = {
{"/", HTTPD_HDR_DEFORT, 0, http_get_index_page, NULL, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, http_get_socket_status, http_set_socket_status, NULL, NULL},
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, http_set_socket_status, NULL, NULL},
{"/status", HTTPD_HDR_DEFORT, 0, http_get_tc1_status, NULL, NULL, NULL},
{"/wifi/config", HTTPD_HDR_DEFORT, 0, http_get_wifi_config, http_set_wifi_config, NULL, NULL},
};

View File

@@ -187,7 +187,7 @@ function Ajax(url, onsuccess, type, data) {
xml_http.onreadystatechange = function () {
if (xml_http.readyState == 4) {
if (xml_http.status == 200) {
onsuccess(xml_http.responseText);
onsuccess(xml_http.responseText.replace(/'/g, '"'));
}
else {
alert("Ajax error: " + xml_http.status);
@@ -220,9 +220,9 @@ var pswd_ipt = document.getElementById("pswd");
var mode_rd1 = document.getElementById("mode1");
var mode_rd2 = document.getElementById("mode2");
HttpGet("/socket", function (re) {
var status = re;
var status_arr = status.split(",");
HttpGet("/status", function (re) {
var status = JSON.parse(re);
var status_arr = status.sockets.split(",");
for (var i = 0; i < status_arr.length; i++) {
checkboxs[i].checked = status_arr[i] == "1";
}

File diff suppressed because one or more lines are too long