first commit
This commit is contained in:
8
Web/imasBackend/.idea/.gitignore
generated
vendored
Normal file
8
Web/imasBackend/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
12
Web/imasBackend/.idea/dataSources.xml
generated
Normal file
12
Web/imasBackend/.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@localhost" uuid="76688b31-a8ea-4f6d-a3ba-125f73939125">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
9
Web/imasBackend/.idea/imas-backend.iml
generated
Normal file
9
Web/imasBackend/.idea/imas-backend.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jquery" level="application" />
|
||||
</component>
|
||||
</module>
|
6
Web/imasBackend/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
Web/imasBackend/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
6
Web/imasBackend/.idea/jsLibraryMappings.xml
generated
Normal file
6
Web/imasBackend/.idea/jsLibraryMappings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="PROJECT" libraries="{jquery}" />
|
||||
</component>
|
||||
</project>
|
8
Web/imasBackend/.idea/modules.xml
generated
Normal file
8
Web/imasBackend/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/imas-backend.iml" filepath="$PROJECT_DIR$/.idea/imas-backend.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
20
Web/imasBackend/.idea/php.xml
generated
Normal file
20
Web/imasBackend/.idea/php.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
4
Web/imasBackend/.idea/vcs.xml
generated
Normal file
4
Web/imasBackend/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
21
Web/imasBackend/ESP01/getData.php
Normal file
21
Web/imasBackend/ESP01/getData.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
include_once("../db_config.php");
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
|
||||
$queryString = "SELECT * FROM status LIMIT 1";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
$standby = $row['standby'];
|
||||
$reboot = $row['reboot'];
|
||||
|
||||
$data = array(
|
||||
"standby" => $standby,
|
||||
"reboot" => $reboot
|
||||
);
|
||||
echo json_encode($data);
|
||||
|
||||
|
8
Web/imasBackend/db_config.php
Normal file
8
Web/imasBackend/db_config.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$dbname = "IMAS";
|
||||
|
||||
// Create connection
|
||||
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
62
Web/imasBackend/debug.php
Normal file
62
Web/imasBackend/debug.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
include_once 'db_config.php';
|
||||
//header('Content-Type: application/json');
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
|
||||
// 获取 POST 数据
|
||||
$postData = file_get_contents('php://input');
|
||||
echo $postData;
|
||||
// 解析 JSON 数据
|
||||
$data = json_decode($postData, true);
|
||||
|
||||
// 检查是否成功解析
|
||||
if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||
echo json_encode(['error' => 'JSON 解析错误: ' . json_last_error_msg()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理数据
|
||||
$standby = isset($data['standby']) ? $data['standby'] : 0;
|
||||
$reboot = isset($data['reboot']) ? $data['reboot'] : 0;
|
||||
$humidifier = isset($data['humidifier']) ? $data['humidifier'] : 0;
|
||||
$screen = isset($data['screen']) ? $data['screen'] : 1;
|
||||
|
||||
|
||||
// 处理逻辑示例
|
||||
$response = [
|
||||
'message' => '数据接收成功',
|
||||
'standby' => $standby,
|
||||
'reboot' => $reboot,
|
||||
'humidifier' => $humidifier,
|
||||
'screen' => $screen,
|
||||
];
|
||||
|
||||
// 返回 JSON 响应
|
||||
|
||||
$queryString = "UPDATE `status` SET `standby`='$standby', `reboot`='$reboot', `humidifier`='$humidifier', `screen`='$screen'";
|
||||
mysqli_query($conn, $queryString);
|
||||
|
||||
$queryString = "select * FROM status";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
if(mysqli_num_rows($result) > 0){
|
||||
$data = []; // 初始化为空数组
|
||||
while ($row = mysqli_fetch_object($result)) { // 获取查询结果作为对象
|
||||
$data[] = $row; // 将对象追加到数组中
|
||||
}
|
||||
echo substr(json_encode($data),1,58) ; // 输出 JSON 格式的响应
|
||||
}
|
||||
}else{
|
||||
$queryString = "select * FROM status";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
if(mysqli_num_rows($result) > 0){
|
||||
$data = []; // 初始化为空数组
|
||||
while ($row = mysqli_fetch_object($result)) { // 获取查询结果作为对象
|
||||
$data[] = $row; // 将对象追加到数组中
|
||||
}
|
||||
echo substr(json_encode($data),1,58) ; // 输出 JSON 格式的响应
|
||||
}
|
||||
}
|
33
Web/imasBackend/getLocalData.php
Normal file
33
Web/imasBackend/getLocalData.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
include_once "db_config.php"; // 数据库配置文件
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
|
||||
// 这里假设连接已经建立,并且您有 $link 变量代表数据库连接
|
||||
|
||||
// 定义SQL查询,获取最近的10条记录
|
||||
$query = "SELECT * FROM localdata ORDER BY time DESC LIMIT 1";
|
||||
|
||||
// 执行查询
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
// 检查查询结果
|
||||
if (!$result) {
|
||||
die("查询失败: " . mysqli_error($conn)); // 处理错误
|
||||
}
|
||||
|
||||
// 处理查询结果
|
||||
$data = [];
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
$data[] = $row; // 将每一行数据存入数组
|
||||
}
|
||||
|
||||
// 返回 JSON 格式的数据
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($data);
|
||||
|
||||
// 关闭数据库连接
|
||||
mysqli_close($conn);
|
22
Web/imasBackend/getSetting.php
Normal file
22
Web/imasBackend/getSetting.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
include_once("db_config.php");
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
|
||||
$queryString = "SELECT * FROM control_list";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
if(mysqli_error($conn)){
|
||||
echo json_encode(["code" => 1, "msg" => mysqli_error($conn)]);
|
||||
exit();
|
||||
}
|
||||
else{
|
||||
$data = array();
|
||||
while($row = mysqli_fetch_assoc($result)){
|
||||
$data[] = $row;
|
||||
}
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
52
Web/imasBackend/postLocalData.php
Normal file
52
Web/imasBackend/postLocalData.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
include_once "db_config.php";
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
|
||||
|
||||
// 处理 OPTIONS 请求
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(204);
|
||||
exit();
|
||||
}
|
||||
|
||||
// 获取原始 POST 数据
|
||||
$input = json_decode(file_get_contents("php://input"), true); // 将 JSON 转换为 PHP 数组
|
||||
|
||||
// 检查是否成功解析 JSON
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
echo json_encode(["error" => "无效的 JSON 数据"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$local_temperature = $input["Temperature"] ?? "";
|
||||
$local_humidity = $input["Humidity"] ?? "";
|
||||
|
||||
//$standby = $input["status"]["standby"] ?? 0;
|
||||
//$reboot = $input["status"]["reboot"] ?? 0;
|
||||
//$humidifier = $input["status"]["humidifier"] ?? 0;
|
||||
//$screen = $input["status"]["screen"] ?? 1;
|
||||
|
||||
|
||||
$time = time();
|
||||
$date = date("Y-m-d H:i:s", $time);
|
||||
|
||||
$queryString = "INSERT INTO localdata (time, temperature, humidity) VALUES ('$date', '$local_temperature', '$local_humidity')";
|
||||
|
||||
mysqli_query($conn, $queryString);
|
||||
if(mysqli_error($conn)){
|
||||
echo json_encode(["error" => "数据库错误"]);
|
||||
}
|
||||
|
||||
$queryString = "select * FROM status";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
if(mysqli_num_rows($result) > 0){
|
||||
$data = []; // 初始化为空数组
|
||||
while ($row = mysqli_fetch_object($result)) { // 获取查询结果作为对象
|
||||
$data[] = $row; // 将对象追加到数组中
|
||||
echo substr(json_encode($data),1, 58); // 返回 JSON 格式的响应
|
||||
}
|
||||
}
|
54
Web/imasBackend/postSetting.php
Normal file
54
Web/imasBackend/postSetting.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
include_once "db_config.php";
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type");
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($input["boot"]) || !isset($input["shutdown"]) || !isset($input["start"]) ||
|
||||
!isset($input["end"]) || !isset($input["min_humidity"]) || !isset($input["max_humidity"]) ||
|
||||
!isset($input["min_temperature"]) || !isset($input["max_temperature"]) ||
|
||||
!isset($input["enable_boot"]) || !isset($input["enable_humidify"]) ||
|
||||
!isset($input["enable_temp_threshold"]) || !isset($input["enable_humi_threshold"])) {
|
||||
echo json_encode(["error" => "无效的请求数据"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
// 获取输入数据
|
||||
$boot = $input["boot"];
|
||||
$shutdown = $input["shutdown"];
|
||||
$start = $input["start"];
|
||||
$end = $input["end"];
|
||||
$min_humidity = $input["min_humidity"];
|
||||
$max_humidity = $input["max_humidity"];
|
||||
$min_temperature = $input["min_temperature"];
|
||||
$max_temperature = $input["max_temperature"];
|
||||
$enable_boot = $input["enable_boot"];
|
||||
$enable_humidify = $input["enable_humidify"];
|
||||
$enable_temp_threshold = $input["enable_temp_threshold"];
|
||||
$enable_humi_threshold = $input["enable_humi_threshold"];
|
||||
|
||||
|
||||
// 更新数据库
|
||||
$queryString = "UPDATE control_list SET
|
||||
boot='$boot',
|
||||
shutdown='$shutdown',
|
||||
start='$start',
|
||||
end='$end',
|
||||
min_humidity='$min_humidity',
|
||||
max_humidity='$max_humidity',
|
||||
min_temperature='$min_temperature',
|
||||
max_temperature='$max_temperature',
|
||||
enable_boot='$enable_boot',
|
||||
enable_humidify='$enable_humidify',
|
||||
enable_temp_threshold='$enable_temp_threshold',
|
||||
enable_humi_threshold='$enable_humi_threshold'";
|
||||
|
||||
if (mysqli_query($conn, $queryString)) {
|
||||
echo json_encode(["success" => "设置更新成功"]);
|
||||
} else {
|
||||
echo json_encode(["error" => "设置更新失败: " . mysqli_error($conn)]);
|
||||
}
|
||||
|
41
Web/imasBackend/postStatus.php
Normal file
41
Web/imasBackend/postStatus.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
include_once "db_config.php";
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
header("Access-Control-Allow-Origin: *"); // 允许跨域请求
|
||||
header("Access-Control-Allow-Methods: POST, OPTIONS"); // 允许的方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
|
||||
|
||||
// 处理 OPTIONS 请求
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(204);
|
||||
exit();
|
||||
}
|
||||
|
||||
// 获取原始 POST 数据
|
||||
$input = json_decode(file_get_contents("php://input"), true); // 将 JSON 转换为 PHP 数组
|
||||
|
||||
// 检查是否成功解析 JSON
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
echo json_encode(["error" => "无效的 JSON 数据"]);
|
||||
exit();
|
||||
}
|
||||
|
||||
$standby = $input["standby"];
|
||||
$reboot = $input["reboot"];
|
||||
$humidifier = $input["humidifier"];
|
||||
$screen = $input["screen"];
|
||||
|
||||
|
||||
$queryString = "UPDATE status SET standby='$standby', reboot='$reboot', humidifier='$humidifier', screen='$screen'";
|
||||
mysqli_query($conn, $queryString);
|
||||
if(mysqli_error($conn)){
|
||||
echo json_encode(["error" => "状态更新失败"]);
|
||||
}
|
||||
else{
|
||||
echo json_encode(["success" => "状态更新成功"]);
|
||||
}
|
||||
|
||||
|
||||
|
18
Web/imasBackend/test.php
Normal file
18
Web/imasBackend/test.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, POST');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
header('Access-Control-Allow-Headers: Authorization');
|
||||
header('Access-Control-Allow-Headers: X-Requested-With');
|
||||
header("Content-Type: application/json"); // 返回 JSON 格式的响应
|
||||
include_once "db_config.php";
|
||||
$queryString = "select * FROM status";
|
||||
$result = mysqli_query($conn, $queryString);
|
||||
if(mysqli_num_rows($result) > 0){
|
||||
$data = []; // 初始化为空数组
|
||||
while ($row = mysqli_fetch_object($result)) { // 获取查询结果作为对象
|
||||
$data[] = $row; // 将对象追加到数组中
|
||||
}
|
||||
echo substr(json_encode($data),1,58) ; // 输出 JSON 格式的响应
|
||||
}
|
7
Web/imasBackend/weatherInfo.php
Normal file
7
Web/imasBackend/weatherInfo.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *"); // 允许所有域名访问
|
||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); // 允许的请求方法
|
||||
header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
|
||||
header("Content-type:application/json");
|
||||
$weather = json_decode(file_get_contents('https://restapi.amap.com/v3/weather/weatherInfo?key=12085a54026b8e80ed3f69ec9c328e3e&city=510115&extensions=base&output=JSON'));
|
||||
echo json_encode($weather);
|
Reference in New Issue
Block a user