Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
home
/
nonga.eemo.co.kr
/
public_html
/
www
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/nonga.eemo.co.kr/public_html/www/cron_check_alarm.php
<? include_once("/home/nonga.eemo.co.kr/public_html/www/dbconn.php"); include_once("/home/nonga.eemo.co.kr/public_html/www/lib.php"); $result_sens=mysql_query("select * from farm_sensor where sens_uptime is not null ") or die(); while($rs_sens=mysql_fetch_array($result_sens)) { $vv_time=time()-40; $result_raw=mysql_query("select * from iot_raw where sensor_no='{$rs_sens[no]}' and unix_timestamp(regdate) >= '$vv_time' and alarm_pushed_date is null order by no asc ") or die(); $rs_dong=RS("select * from farm_dong_info where no='{$rs_sens[dong_no]}' "); $rs_farm=RS("select * from farm where no='{$rs_sens[farm_no]}' "); $rs_ipcam=RS("select * from farm_ipcamera where farm_no='{$rs_sens[farm_no]}' and dong_info='{$rs_dong[dong_name]}' "); //echo "select * from iot_raw where sensor_no='{$rs_sens[no]}' and unix_timestamp(regdate) >= '$vv_time' and alarm_pushed_date is null order by no asc <br><br>"; if($rs_sens[no]==9) { //echo "now humi = ".$rs_sens[now_humi_value]." , humi_max_set = ".$rs_sens[set_humi_max_value]."<br>"; } while($rs_raw=mysql_fetch_array($result_raw)) { if($rs_raw[sensor_no]==9) { //echo "now humi = ".$rs_raw[humi]." <br>"; } if($rs_sens[sensor_type]==1) { if($rs_raw[temp] < $rs_sens[set_temper_min_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 온도가 ".$rs_raw[temp]." 도로<br> 기준치 ".$rs_sens[set_temper_min_value]." 도 이하로 떨어졌습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 온도가 ".$rs_raw[temp]." 도로 기준치 ".$rs_sens[set_temper_min_value]." 도 이하로 떨어졌습니다 "; $event_msg=$rs_farm[farm_name]." , ".$tts_cont; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='1', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='1', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='tmp', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$event_msg', register_date=now() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } if($rs_raw[temp] > $rs_sens[set_temper_max_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 온도가 ".$rs_raw[temp]." 도로<br> 기준치 ".$rs_sens[set_temper_max_value]." 도 이상으로 올라갔습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 온도가 ".$rs_raw[temp]." 도로 기준치 ".$rs_sens[set_temper_max_value]." 도 이상으로 올라갔습니다 "; $event_msg=$rs_farm[farm_name]." , ".$tts_cont; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='1', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='1', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='tmp', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$tts_cont', register_date=now() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } if($rs_raw[humi] < $rs_sens[set_humi_min_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 습도가 ".$rs_raw[humi]." %로<br> 기준치 ".$rs_sens[set_humi_min_value]." % 이하로 떨어졌습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 습도가 ".$rs_raw[humi]." 퍼센트로 기준치 ".$rs_sens[set_humi_min_value]." 퍼센트 이하로 떨어졌습니다 "; $event_msg=$rs_farm[farm_name]." , ".$tts_cont; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='2', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='1', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='hum', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$event_msg', register_date=now() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } if($rs_raw[humi] > $rs_sens[set_humi_max_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 습도가 ".$rs_raw[humi]." %로<br> 기준치 ".$rs_sens[set_humi_max_value]." % 이상으로 올라갔습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 습도가 ".$rs_raw[humi]." 퍼센트로 기준치 ".$rs_sens[set_humi_max_value]." 퍼센트 이상으로 올라갔습니다 "; $event_msg=$rs_farm[farm_name]." , ".$tts_cont; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='2', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='1', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='hum', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$event_msg', register_date=now() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } } else if($rs_sens[sensor_type]==2) { if($rs_raw[adc_data] < $rs_sens[set_anal_min_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 정전압센서가 ".$rs_raw[adc_data]." 로<br> 기준치 ".$rs_sens[set_anal_min_value]." 이하로 떨어졌습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 정전압센서가 ".$rs_raw[adc_data]." 기준치 ".$rs_sens[set_anal_min_value]." 이하로 떨어졌습니다 "; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='3', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='2', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='blackout', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$tts_cont', register_date=UNIX_TIMESTAMP() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } if($rs_raw[adc_data] > $rs_sens[set_anal_max_value]) { $title="알람발생"; $cont="<b>".$rs_dong[dong_name]." 알람발생</b><br><br>".$rs_sens[pos_no]." 정전압센서가 ".$rs_raw[adc_data]." 로<br> 기준치 ".$rs_sens[set_anal_max_value]." 이상으로 올라갔습니다."; $tts_cont=$rs_dong[dong_name]." 알람발생 , ".$rs_sens[pos_no]." 정전압센서가 ".$rs_raw[adc_data]." 기준치 ".$rs_sens[set_anal_max_value]." 이상으로 올라갔습니다 "; $mode="warning"; mysql_query("insert into farm_msg_alarm set farm_no='{$rs_dong[farm_no]}' , farm_code='{$rs_farm[farm_code]}', msg_gubun='긴급알림', title='$title', cont='$tts_cont', sensor_type='3', regdate=now() ") or die(mysql_error()); mysql_query("update iot_raw set is_alarm='1', alarm_type='2', alarm_pushed_date=now() where no='{$rs_raw[no]}' ") or die(); mysql_query("insert into control_center_event set farm_no='{$rs_sens[farm_no]}' , dong_no='{$rs_sens[no]}', ch_no='{$rs_ipcam[ch_no]}', event_type='blackout', tmp_value='{$rs_raw[temp]}', hum_value='{$rs_raw[humi]}', blackout_value='{$rs_raw[adc_data]}', event_msg='$tts_cont', register_date=UNIX_TIMESTAMP() ") or die(mysql_error()); if($rs_dong[set_alarm]==1 && $rs_farm[set_alarm]==1) { $result_mem=mysql_query("select * from member where farm_no='{$rs_dong[farm_no]}' and fcm_token is not null ") or die(); while($rs_mem=mysql_fetch_array($result_mem)) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts=$rs_farm[set_alarm_tts]; $is_sound=$rs_farm[set_alarm_tts]==1?"0":$rs_farm[set_alarm_sound]; $isvib=$rs_farm[alarm_vibrate]; $ispopup=$rs_farm[alarm_popup]; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into push_send_log set arr_mem_no='{$rs_mem[no]}', title='$title', cont='$cont', tts_cont='$tts_cont', is_tts='$istts', mode='$mode', is_sound='$is_sound', regdate=now(), mode2='2' ") or die(mysql_error()); } else { } } } } } echo $event_msg."\n\n"; } } function send_notification($tokens, $message) { $url = 'https://fcm.googleapis.com/fcm/send'; $fields = array( 'registration_ids' => $tokens, 'data' => $message ); $key = "AIzaSyCG6QsJex8nT-CVCMaDQL7vKxclJl3_XwI"; $headers = array( 'Authorization:key =' . $key, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $response = curl_exec($ch); curl_close($ch); $json=json_decode($response,true); //NotRegistered = 앱삭제 if($json["success"]) { return "success"; } else { return $response; } } ?>