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/api_get_w5100_temper.php_org
<? session_cache_limiter('no-cache, must-revalidate'); session_start(); header("Pragma: no-cache"); header("Cache-Control: no-cache,must-revalidate"); header("Content-Type: text/html; charset=utf-8"); include_once("dbconn.php"); include_once("lib.php"); foreach($_GET as $key => $value) { ${$key}=mysql_real_escape_string(trim($value)); } foreach($_POST as $key => $value) { ${$key}=mysql_real_escape_string(trim($value)); } $div_hh=date('H'); $jdate=date('Y-m-d'); // $query="insert into tmp_nodemcu // set // sensor_no='$sensor_no', // wifi_no='$wifi_no', // temp='$temper', // badak_temp='$badak_temp', // humi='$humi', // gas_no2='$gas_no2', // gas_co='$gas_co', // gas_nh3='$gas_nh3', // giap='$giap', // lux='$lux', // co2='$co2', // voc='$voc', // mac='$mac', // regdate=now() // "; // mysql_query($query) or die(mysql_error()); $rs_sens=RS("select * from farm_sensor where mac='$mac' "); $rs_farm=RS("select * from farm where no='{$rs_sens[farm_no]}' "); $rs_dong=RS("select * from farm_dong_info where no='{$rs_sens[dong_no]}' "); $rs_member=RS("select * from member where farm_no='$rs_farm[no]' "); $temper_org = $temper; $humi_org = $humi; if($rs_sens[no]) { $temper = $temper_org+($rs_sens[bo_temp]); $humi = $humi_org+($rs_sens[bo_humi]); $query="insert into iot_raw set traid='', repid='', logid='', tstamp='', bat='', rssi='', snr='', power='1', temp='$temper', humi='$humi', adc_data='', firm='1.0', err_code='', farm_code='', farm_no='{$rs_sens[farm_no]}', wifi_code='', wifi_no='', dong_code='', dong_no='{$rs_sens[dong_no]}', sensor_code='', sensor_no='{$rs_sens[no]}', sensor_type='{$rs_sens[sensor_type]}', blackout_data='1', jtime=now(), regdate=now() "; mysql_query($query) or die(mysql_error()); $iot_raw_no=mysql_insert_id(); /* ----------------------- */ // $rs_tot=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sens[no]}' and date(jtime)='$jdate' and LPAD(hour(jtime),2,'0')='$div_hh' "); // $rs_hour=RS("select * from iot_hour where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sens[no]}' and jdate='$jdate' and jhour='$div_hh' "); // if(!$rs_hour[no]) { // $query="insert into iot_hour // set // farm_no='{$rs_farm[no]}', // dong_no='{$rs_dong[no]}', // sensor_no='{$rs_sens[no]}', // temp='{$rs_tot[tem]}', // humi='{$rs_tot[hum]}', // anal='{$rs_tot[anl]}', // bat='{$rs_tot[vbat]}', // jdate='$jdate', // jhour='$div_hh', // uptime=now() // "; // if($rs_farm[no]) { // mysql_query($query) or die(mysql_error()); // } // } else { // $query="update iot_hour // set // temp='{$rs_tot[tem]}', // humi='{$rs_tot[hum]}', // anal='{$rs_tot[anl]}', // bat='{$rs_tot[vbat]}', // uptime=now() // where no='{$rs_hour[no]}' // "; // mysql_query($query) or die(mysql_error()); // } // $rs_tot2=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sens[no]}' and date(jtime)='$jdate' "); // $rs_date=RS("select * from iot_date where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sens[no]}' and jdate='$jdate' "); // if(!$rs_date[no]) { // $query="insert into iot_date // set // farm_no='{$rs_farm[no]}', // dong_no='{$rs_dong[no]}', // sensor_no='{$rs_sens[no]}', // temp='{$rs_tot2[tem]}', // humi='{$rs_tot2[hum]}', // anal='{$rs_tot2[anl]}', // bat='{$rs_tot2[vbat]}', // jdate='$jdate', // uptime=now() // "; // if($rs_farm[no]) { // mysql_query($query) or die(mysql_error()); // } // } else { // $query="update iot_date // set // temp='{$rs_tot2[tem]}', // humi='{$rs_tot2[hum]}', // anal='{$rs_tot2[anl]}', // bat='{$rs_tot2[vbat]}', // uptime=now() // where no='{$rs_date[no]}' // "; // mysql_query($query) or die(mysql_error()); // } // if($rs_sens[sensor_type]==1) { // $query="update farm_sensor // set // now_temper_value='$temper', // now_humi_value='$humi', // sens_uptime=now() // where no='{$rs_sens[no]}' // "; // mysql_query($query) or die(mysql_error()); // } //알람 // $rs_raw=RS("select * from iot_raw where no='$iot_raw_no' "); // 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 { // } // } // } // } // } //--알람 } /* if($mac=="5410eca0fcc5") { $result_sub=mysql_query("select * from farm_sensor where farm_no='{$rs_sens[farm_no]}' and mac != '$mac' order by dong_no asc ") or die(); while($rs_sub=mysql_fetch_array($result_sub)) { $temper = $temper_org+($rs_sub[bo_temp]); $humi = $humi_org+($rs_sub[bo_humi]); $rs_dong=RS("select * from farm_dong_info where no='{$rs_sub[dong_no]}' "); $query="insert into iot_raw set traid='', repid='', logid='', tstamp='', bat='', rssi='', snr='', power='1', temp='$temper', humi='$humi', adc_data='', firm='1.0', err_code='', farm_code='', farm_no='{$rs_sub[farm_no]}', wifi_code='', wifi_no='', dong_code='', dong_no='{$rs_sub[dong_no]}', sensor_code='', sensor_no='{$rs_sub[no]}', sensor_type='{$rs_sub[sensor_type]}', blackout_data='1', jtime=now(), regdate=now() "; mysql_query($query) or die(mysql_error()); $iot_raw_no=mysql_insert_id(); $rs_tot=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' and LPAD(hour(jtime),2,'0')='$div_hh' "); $rs_hour=RS("select * from iot_hour where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' and jhour='$div_hh' "); if(!$rs_hour[no]) { $query="insert into iot_hour set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', jdate='$jdate', jhour='$div_hh', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_hour set temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', uptime=now() where no='{$rs_hour[no]}' "; mysql_query($query) or die(mysql_error()); } $rs_tot2=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' "); $rs_date=RS("select * from iot_date where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' "); if(!$rs_date[no]) { $query="insert into iot_date set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', jdate='$jdate', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_date set temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', uptime=now() where no='{$rs_date[no]}' "; mysql_query($query) or die(mysql_error()); } if($rs_sub[sensor_type]==1) { $query="update farm_sensor set now_temper_value='$temper', now_humi_value='$humi', sens_uptime=now() where no='{$rs_sub[no]}' "; mysql_query($query) or die(mysql_error()); } } } else if($mac=="5410eca14173") { $result_sub=mysql_query("select * from farm_sensor where farm_no='{$rs_sens[farm_no]}' and mac != '$mac' order by dong_no asc ") or die(); while($rs_sub=mysql_fetch_array($result_sub)) { $temper = $temper_org+($rs_sub[bo_temp]); $humi = $humi_org+($rs_sub[bo_humi]); $rs_dong=RS("select * from farm_dong_info where no='{$rs_sub[dong_no]}' "); $query="insert into iot_raw set traid='', repid='', logid='', tstamp='', bat='', rssi='', snr='', power='1', temp='$temper', humi='$humi', adc_data='', firm='1.0', err_code='', farm_code='', farm_no='{$rs_sub[farm_no]}', wifi_code='', wifi_no='', dong_code='', dong_no='{$rs_sub[dong_no]}', sensor_code='', sensor_no='{$rs_sub[no]}', sensor_type='{$rs_sub[sensor_type]}', blackout_data='1', jtime=now(), regdate=now() "; mysql_query($query) or die(mysql_error()); $iot_raw_no=mysql_insert_id(); $rs_tot=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' and LPAD(hour(jtime),2,'0')='$div_hh' "); $rs_hour=RS("select * from iot_hour where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' and jhour='$div_hh' "); if(!$rs_hour[no]) { $query="insert into iot_hour set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', jdate='$jdate', jhour='$div_hh', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_hour set temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', uptime=now() where no='{$rs_hour[no]}' "; mysql_query($query) or die(mysql_error()); } $rs_tot2=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' "); $rs_date=RS("select * from iot_date where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' "); if(!$rs_date[no]) { $query="insert into iot_date set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', jdate='$jdate', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_date set temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', uptime=now() where no='{$rs_date[no]}' "; mysql_query($query) or die(mysql_error()); } if($rs_sub[sensor_type]==1) { $query="update farm_sensor set now_temper_value='$temper', now_humi_value='$humi', sens_uptime=now() where no='{$rs_sub[no]}' "; mysql_query($query) or die(mysql_error()); } } } else if($mac=="5410eca119eb") { $result_sub=mysql_query("select * from farm_sensor where farm_no='{$rs_sens[farm_no]}' and mac != '$mac' order by dong_no asc ") or die(); while($rs_sub=mysql_fetch_array($result_sub)) { $temper = $temper_org+($rs_sub[bo_temp]); $humi = $humi_org+($rs_sub[bo_humi]); $rs_dong=RS("select * from farm_dong_info where no='{$rs_sub[dong_no]}' "); $query="insert into iot_raw set traid='', repid='', logid='', tstamp='', bat='', rssi='', snr='', power='1', temp='$temper', humi='$humi', adc_data='', firm='1.0', err_code='', farm_code='', farm_no='{$rs_sub[farm_no]}', wifi_code='', wifi_no='', dong_code='', dong_no='{$rs_sub[dong_no]}', sensor_code='', sensor_no='{$rs_sub[no]}', sensor_type='{$rs_sub[sensor_type]}', blackout_data='1', jtime=now(), regdate=now() "; mysql_query($query) or die(mysql_error()); $iot_raw_no=mysql_insert_id(); $rs_tot=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' and LPAD(hour(jtime),2,'0')='$div_hh' "); $rs_hour=RS("select * from iot_hour where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' and jhour='$div_hh' "); if(!$rs_hour[no]) { $query="insert into iot_hour set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', jdate='$jdate', jhour='$div_hh', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_hour set temp='{$rs_tot[tem]}', humi='{$rs_tot[hum]}', anal='{$rs_tot[anl]}', bat='{$rs_tot[vbat]}', uptime=now() where no='{$rs_hour[no]}' "; mysql_query($query) or die(mysql_error()); } $rs_tot2=RS("select avg(temp) as tem , avg(humi) as hum , avg(adc_data) as anl, max(bat) as vbat from iot_raw where sensor_no='{$rs_sub[no]}' and date(jtime)='$jdate' "); $rs_date=RS("select * from iot_date where farm_no='{$rs_farm[no]}' and dong_no='{$rs_dong[no]}' and sensor_no='{$rs_sub[no]}' and jdate='$jdate' "); if(!$rs_date[no]) { $query="insert into iot_date set farm_no='{$rs_farm[no]}', dong_no='{$rs_dong[no]}', sensor_no='{$rs_sub[no]}', temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', jdate='$jdate', uptime=now() "; if($rs_farm[no]) { mysql_query($query) or die(mysql_error()); } } else { $query="update iot_date set temp='{$rs_tot2[tem]}', humi='{$rs_tot2[hum]}', anal='{$rs_tot2[anl]}', bat='{$rs_tot2[vbat]}', uptime=now() where no='{$rs_date[no]}' "; mysql_query($query) or die(mysql_error()); } if($rs_sub[sensor_type]==1) { $query="update farm_sensor set now_temper_value='$temper', now_humi_value='$humi', sens_uptime=now() where no='{$rs_sub[no]}' "; mysql_query($query) or die(mysql_error()); } } } */ $farmContract = RS("SELECT `no` FROM farm_contract WHERE farm_no = {$rs_farm['no']} AND contract_status = 1 AND ltms_status = 5 ORDER BY `no` DESC LIMIT 1"); if($farmContract) { $farmContractParts = RS("SELECT `no` FROM farm_contract_parts WHERE contract_no = {$farmContract['no']} AND is_magam = 0 ORDER BY `no` DESC LIMIT 1"); if($farmContractParts) { $ipchu = RS("SELECT *, DATEDIFF(CURDATE(), jdate) AS `day` FROM farm_ipchu_confirm_log WHERE parts_no = {$farmContractParts['no']} AND dong_no = {$rs_dong['no']}"); $isIpchu = 1; if($ipchu['day'] != 0 && $ipchu['day'] < 8){ $hightTemperature = 38.0; $lowTemperature = 26.0; $weekInfo = number_format($lowTemperature,1)." < 1주령 < ".number_format($hightTemperature,1); }else if ($ipchu['day'] > 7 && $ipchu['day'] < 15) { $hightTemperature = 36.0; $lowTemperature = 26.0; $weekInfo = number_format($lowTemperature,1)." < 2주령 < ".number_format($hightTemperature,1); }else if ($ipchu['day'] > 14 && $ipchu['day'] < 22) { $hightTemperature = 33.0; $lowTemperature = 24.0; $weekInfo = number_format($lowTemperature,1)." < 3주령 < ".number_format($hightTemperature,1); }else if ($ipchu['day'] > 21 && $ipchu['day'] < 29) { $hightTemperature = 30.0; $lowTemperature = 22.0; $weekInfo = number_format($lowTemperature,1)." < 4주령 < ".number_format($hightTemperature,1); }else if ($ipchu['day'] > 28) { $hightTemperature = 28.0; $lowTemperature = 20.0; $weekInfo = number_format($lowTemperature,1)." < 5주령 < ".number_format($hightTemperature,1); }else { $isIpchu = 0; } if(($rs_farm['set_alarm'] == 1) && ($temper > $hightTemperature || $temper < $lowTemperature) && ($isIpchu == 1) && ($temper != 0 && $temper != "") ) { $title=$temper > $hightTemperature ? "고온경보" : "저온경보"; $emoji = $temper > $hightTemperature ? " ♨️ " : " ❄️ "; $cont=$emoji.$rs_farm['farm_name']." ".$rs_dong['dong_name']." ".$emoji."현재온도 : ".number_format($temper,1) ." ".$emoji.$rs_dong['dong_name']." 온도 확인 요망 "; // 읽어주는 부분 $tts_cont=$re_dong['dong_name'].$temper." 온도 이상 발생"; $event_msg=$rs_dong['dong_name']." 이상 발생"; $mode="warning"; $is_sound=$rs_farm['set_alarm_sound']; $istts=$rs_farm['set_alarm_tts']; $isvib=$rs_farm['alarm_vibrate']; $ispopup=$rs_farm['alarm_popup']; $tokens = array(); $tokens[]=$rs_member['fcm_token']; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound,"tts" => $tts_cont,"istts" => $istts,"isvib" => $isvib,"ispopup" => $ispopup); send_notification($tokens, $message); // $ltman_query = mysql_query("SELECT FCD.* FROM farm_contract FC, farm_contract_damdang FCD WHERE FC.`no` = FCD.contract_no AND FC.farm_no = 295 AND FC.contract_status = 1 GROUP BY FCD.damdang_ltman_member_no"); // while($rs_ltman=mysql_fetch_array($ltman_query)) { // // 토큰 정보 // $ltman = RS("SELECT set_alarm, alarm_push, set_alarm_sms, alarm_popup, fcm_token FROM ltman_member WHERE `no` = {$rs_ltman['damdang_ltman_member_no']}"); // $ltman_tokens = array(); // $ltman_tokens[]=$ltman['fcm_token']; // $messages = array("message" => $cont,"title" => $title,"mode" => 'notice',"sound" => $is_sound,"tts" => $tts_cont,"istts" => $istts,"isvib" => $isvib,"ispopup" => $ispopup); // send_notification($ltman_tokens, $messages); // } } } } 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; } } // if($rs_sens[no]) { $yangdb=mysql_connect("erp.ppeople.net:7707","yanggyein","11qqaa..") or die(mysql_error()); mysql_select_db("yanggyein") or die(mysql_error()); $temperature = $_REQUEST['temper'] == 'NAN' ? '0': $_REQUEST['temper']; $humidity = $_REQUEST['humi'] == 'NAN' ? '0': $_REQUEST['humi']; $mac = $_REQUEST['mac'] == 'NAN' ? '0': $_REQUEST['mac']; // echo '온도 : '.$temperature.' '; // echo '습도 : '.$humidity.' '; // echo 'MAC : '.$mac.' '; mysql_query("set names 'utf8'"); $query = "select id, location from iot_sensors where mac = '$mac' "; $iotSensor = mysql_fetch_object(mysql_query($query)); $location = empty($iotSensor->location) ? '' : $iotSensor->location; $id = empty($iotSensor->id) ? '' : $iotSensor->id; $query = "insert into partition_iot (temperature, humidity, mac, location, sensor_id , created_at) values ('{$temperature}', '{$humidity}', '{$mac}', '{$location}', '{$id}', now())"; $data = mysql_query($query) or die(mysql_error()); // $arr_rst=array(); // $arr_rst['rst']='1'; // $arr_rst['data']='123.1'; // echo json_encode($arr_rst); // } ?>