["low_warn"=>0, "high_warn"=>35, "low_crit"=>-5, "high_crit"=>45], "humidity" => ["low_warn"=>20, "high_warn"=>80, "low_crit"=>10, "high_crit"=>90], "eco2" => ["high_warn"=>1000, "high_crit"=>2000], "tvoc" => ["high_warn"=>600, "high_crit"=>1200], "pm2_5" => ["high_warn"=>35, "high_crit"=>75], "pm10" => ["high_warn"=>80, "high_crit"=>150], "nh3" => ["high_warn"=>25, "high_crit"=>50], "h2s" => ["high_warn"=>10, "high_crit"=>20], "ch4" => ["high_warn"=>5000, "high_crit"=>10000], ]; /** 2) 라벨/단위 (화면에서 사용) */ $NS40_FIELD_META = [ "temp" => ["label"=>"TEMP", "unit"=>"℃"], "humidity" => ["label"=>"HUMIDITY", "unit"=>"%"], "eco2" => ["label"=>"eCO2", "unit"=>"ppm"], "tvoc" => ["label"=>"TVOC", "unit"=>"ppb"], "pm2_5" => ["label"=>"PM2.5","unit"=>"µg/m³"], "pm10" => ["label"=>"PM10", "unit"=>"µg/m³"], "nh3" => ["label"=>"NH3", "unit"=>"ppm"], "h2s" => ["label"=>"H2S", "unit"=>"ppm"], "ch4" => ["label"=>"CH4", "unit"=>"ppm"], ]; /** 3) 저장된 JSON이 있으면 병합 */ $NS40_ALERTS = $__NS40_ALERTS_DEFAULT; if (is_file($__NS40_ALERT_JSON)) { $raw = @file_get_contents($__NS40_ALERT_JSON); $j = json_decode($raw, true); if (is_array($j)) { foreach ($j as $k=>$v) { if (is_array($v)) $NS40_ALERTS[$k] = array_merge($NS40_ALERTS[$k] ?? [], $v); } } } /** 4) 이 파일이 직접 실행될 때만 UI 출력 */ $__is_direct = (basename($_SERVER['SCRIPT_NAME'] ?? '') === basename(__FILE__)); if (!$__is_direct) return; ns40_auth_require_page_access('alert_config'); // ⚠️ 다른 include 파일과 함께 로드될 때 전역 함수명 충돌(Fatal: Cannot redeclare ...) 방지 $h = function($s){ return htmlspecialchars((string)$s, ENT_QUOTES|ENT_SUBSTITUTE, "UTF-8"); }; $msg = ""; if ($_SERVER["REQUEST_METHOD"] === "POST") { $next = []; foreach ($_POST as $key=>$val) { // key 형식: field__threshold (예: temp__high_warn) if (strpos($key, "__") === false) continue; [$field,$th] = explode("__", $key, 2); $field = trim($field); $th = trim($th); if ($field==="" || $th==="") continue; if (!isset($next[$field])) $next[$field] = []; // 숫자/소수 허용 $v = trim((string)$val); if ($v === "") continue; if (!is_numeric($v)) continue; $next[$field][$th] = (float)$v; } // 저장(기존 파일이 있으면 유지/병합) $save = $next; // 파일 쓰기 $ok = @file_put_contents($__NS40_ALERT_JSON, json_encode($save, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)); if ($ok !== false) { $msg = "저장 완료: " . basename($__NS40_ALERT_JSON); // 메모리에 반영 $NS40_ALERTS = $__NS40_ALERTS_DEFAULT; foreach ($save as $k=>$v) $NS40_ALERTS[$k] = array_merge($NS40_ALERTS[$k] ?? [], $v); } else { $msg = "저장 실패: 서버 권한(쓰기 권한)을 확인하세요. (" . $h($__NS40_ALERT_JSON) . ")"; } } ?> NS40 경고 임계치 설정

NS40 경고 임계치 설정

• 저장은 /inc/alert_config.json 파일로 이루어집니다. (서버에서 해당 파일/폴더 쓰기 권한 필요)
• index.html 에서는 이 값을 불러와 최신값 KPI 경고 표시(색상/상태)에 사용합니다.
$meta): $a = $NS40_ALERTS[$k] ?? []; ?>
항목 단위 low_warn high_warn low_crit high_crit
"> "> "> ">
대시보드로 돌아가기 ※ 값이 비어있으면 기본값/미설정으로 처리됩니다.