From 103cb878dc9c08c07b0e0187cfed28f7e5857701 Mon Sep 17 00:00:00 2001 From: flykhan Date: Fri, 27 Oct 2023 19:58:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E6=B3=A8=E5=86=8C=E9=A1=B5=EF=BC=8C=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E6=B8=A9=E6=B9=BF=E5=BA=A6=E9=87=87=E9=9B=86=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cgi-bin/mqtt_pub_stoc.c | 4 +- cgi-bin/sqlite_cgi_base.c | 38 ++++++--- html/enroll.html | 101 +++++++++++++++------- html/green_house_info_show.html | 108 +++++++++++++++++------- html/green_house_settings.html | 53 ++++++++++++ html/index.html | 93 +++++++++++++++++++-- html/login.html | 140 ++++++++++++++----------------- html/zhuti.html | 144 -------------------------------- sql_base/green_house.db | Bin 5120 -> 5120 bytes 9 files changed, 380 insertions(+), 301 deletions(-) create mode 100644 html/green_house_settings.html delete mode 100644 html/zhuti.html diff --git a/cgi-bin/mqtt_pub_stoc.c b/cgi-bin/mqtt_pub_stoc.c index 4f907d0..e525577 100644 --- a/cgi-bin/mqtt_pub_stoc.c +++ b/cgi-bin/mqtt_pub_stoc.c @@ -25,8 +25,8 @@ int main(int argc, char const *argv[]) mosquitto_lib_init(); // 初始化(固定格式) struct mosquitto *client = mosquitto_new(NULL, true, NULL); // 创建客户端 mosquitto_connect_callback_set(client, connect_callback); // 设置连接回调函数 - mosquitto_connect(client, "localhost", 1883, 60); // 连接服务器(地址,端口,超时时间) -// mosquitto_connect(client, "flykhan.com", 1883, 60); // 连接服务器(地址,端口,超时时间) + // mosquitto_connect(client, "localhost", 1883, 60); // 连接服务器(地址,端口,超时时间) + mosquitto_connect(client, "flykhan.com", 1883, 60); // 连接服务器(地址,端口,超时时间) mosquitto_loop_start(client); // 开启客户端线程 while (isConnected == 0) ; // 等待连接成功(当连接成功后,isConnected会被置为1,然后跳出循环) diff --git a/cgi-bin/sqlite_cgi_base.c b/cgi-bin/sqlite_cgi_base.c index bbb8793..29c3d16 100644 --- a/cgi-bin/sqlite_cgi_base.c +++ b/cgi-bin/sqlite_cgi_base.c @@ -5,6 +5,7 @@ // cJSON *result_json; // 用于存储查询结果 char login_user_name[32] = ""; +int sql_search_callback_result_number = 0; // 用于存储查询结果的条数(默认为0) // sqlite3的回调函数 // sqlite 每查到一条记录,就调用一次这个回调 @@ -79,6 +80,7 @@ int main(int argc, char const *argv[]) rc = sqlite3_exec(db, query_sql, sql_search_callback, 0, &zErrMsg); // 执行查询语句 if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); cJSON_Delete(json_buf); @@ -86,6 +88,27 @@ int main(int argc, char const *argv[]) return 1; } + // 检查查询结果是否为0 + if (sql_search_callback_result_number == 0) + { + cJSON *result_json = cJSON_CreateObject(); + cJSON_AddNumberToObject(result_json, "code", 1); + cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误"); + char *result_json_string = cJSON_Print(result_json); + + // 输出 JSON 结果 + printf("content-type: application/json;charset=utf-8\r\n"); + printf("\r\n"); + printf("%s\n", result_json_string); + + free(result_json_string); + + cJSON_Delete(json_buf); + sqlite3_close(db); + return 1; + } + + sql_search_callback_result_number = 0; // 重置为0 // 释放资源 cJSON_Delete(json_buf); sqlite3_close(db); @@ -104,16 +127,11 @@ int sql_search_callback(void *NotUsed, // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); // } cJSON *result_json = cJSON_CreateObject(); - if (argc == 0) - { - cJSON_AddNumberToObject(result_json, "code", 1); - cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误"); - } - else - { - cJSON_AddNumberToObject(result_json, "code", 0); - cJSON_AddStringToObject(result_json, "login_user_name", login_user_name); - } + sql_search_callback_result_number++; + + cJSON_AddNumberToObject(result_json, "code", 0); + cJSON_AddStringToObject(result_json, "login_user_name", login_user_name); + char *result_json_string = cJSON_Print(result_json); // 输出 JSON 结果 diff --git a/html/enroll.html b/html/enroll.html index cb41002..cd2d64c 100644 --- a/html/enroll.html +++ b/html/enroll.html @@ -4,7 +4,54 @@ - Document + 用户注册 + @@ -18,39 +65,33 @@
- - - + - let login_data = { - name: name, - password: password - }; - fetch("../cgi-bin/sqlite_cgi_insert_base.cgi", { - method: "POST", - body: JSON.stringify(login_data), - headers: { - "Content-Type": "application/json;charset=utf-8" - } - }) - open("./login.html", "_self"); - // window.localStorage.setItem("login_user", JSON.stringify(data)); - return false; - } - - - \ No newline at end of file + diff --git a/html/green_house_info_show.html b/html/green_house_info_show.html index cb976fc..4c86851 100644 --- a/html/green_house_info_show.html +++ b/html/green_house_info_show.html @@ -5,49 +5,95 @@ 温湿度 +
- +
- +
温度 湿度 时间
+ + - - - \ No newline at end of file + diff --git a/html/green_house_settings.html b/html/green_house_settings.html new file mode 100644 index 0000000..cb976fc --- /dev/null +++ b/html/green_house_settings.html @@ -0,0 +1,53 @@ + + + + + + + 温湿度 + + + +
+ + + + + + + + + +
温度湿度时间
+
+ + + + \ No newline at end of file diff --git a/html/index.html b/html/index.html index 1bbf16d..5d9af59 100644 --- a/html/index.html +++ b/html/index.html @@ -9,12 +9,18 @@ @@ -56,17 +129,21 @@ logo
+ - +
+
+
@@ -78,7 +155,7 @@ window.onload = function () { if (localStorage.getItem("login_user") == null) { open("./login.html", "_self"); - }else{ + } else { let login_user_str = localStorage.getItem("login_user"); let login_user = JSON.parse(login_user_str); userName.innerText = login_user.login_user_name; diff --git a/html/login.html b/html/login.html index 35c244c..1cb57b6 100644 --- a/html/login.html +++ b/html/login.html @@ -19,93 +19,94 @@ display: flex; flex-direction: column; justify-content: space-between; + background-color: #f5f5f5; } - #top { height: 50px; background-color: lightblue; - } - - #foot { - height: 40px; - background-color: lightblue; - } - - #main { - height: 100%; - background-color: lightcyan; - } - - #top { display: flex; - flex-direction: row; justify-content: space-between; - justify-items: center; align-items: center; padding: 5px; border-bottom: 1px solid lightgray; } #logo>img { - width: 180px; + width: 45px; height: 45px; } #foot { + height: 40px; + background-color: lightblue; border-top: 1px solid lightgray; - padding: 10px 0; + display: flex; + justify-content: center; + align-items: center; } - form { - width: 300px; - height: 300px; - background-color: rgba(41, 117, 117, 0.667); - box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5); - border-radius: 8px; - max-width: 100%; - padding: 0px 35px 0; - } - - form { + #main { + height: 100%; + background-color: lightcyan; display: flex; flex-direction: column; justify-content: center; align-items: center; } + form { + width: 300px; + height: auto; + background-color: rgba(41, 117, 117, 0.667); + box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5); + border-radius: 8px; + padding: 20px; + } + .row { display: flex; - flex-direction: row; - justify-content: center; - flex-wrap: nowrap; + flex-direction: column; + margin-bottom: 10px; + } + + .row-buttons { + display: flex; + justify-content: space-between; + margin-top: 10px; } input { - padding: 10px 5px; + padding: 10px; margin: 5px; border-radius: 5px; + border: none; } button { - width: 80px; - height: 30px; + padding: 10px 20px; border-radius: 3px; + background-color: #4caf50; + color: #ffffff; + border: none; + cursor: pointer; } - #main { - display: flex; - flex-direction: row; - justify-content: space-between; - justify-items: center; - align-items: center; + button a { + color: #ffffff; + text-decoration: none; } - #insert { - font-size: 60px; - font-family: "楷体"; - writing-mode: vertical-rl; - /* 竖行模式 */ + button:hover { + background-color: #45a049; + } + + #title { + font-size: 40px; + font-weight: bold; + text-align: center; + /* margin-top: 20px; */ + margin-bottom: 140px; } @@ -118,32 +119,23 @@
基础版
-
-
- 快速 - 畅联 -
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
+ 智慧农业大棚管理系统 +
+
+ +
+
+ +
+
+ + +
+
- -
- -
- -
-
- - - - - \ No newline at end of file diff --git a/sql_base/green_house.db b/sql_base/green_house.db index a6bb9cb7133d3e4f6c85f9d1cbdfd92b9c93c6d1..d688d2da0059028c2dbe59fce7e1e24e3b40c5cc 100644 GIT binary patch delta 441 zcmZqBXwaA-%_uuj#+g-?LHFa1jVTM51=yHZF))8%e!zT%`4ICC=2e>oS*9^d@UXEk zhzlDU8CO&o8yj=5vM>nq19?W153xG|wVYsJzQlZj`8)Gl=3C59Hw$uXVHVRg@dMFc)@VPVB-Q*oE2Q!aN{PJNQ8C+|0uNhXnuzCuq6= delta 87 zcmV-d0I2_fD1a!C8vzZG976>S04?Gtv1FhF3