require_once"konmysqli.php";
if(isset($_GET['sensor'])){
$sensor = $_GET['sensor'];
$status = $_GET['status'];
$tanggal = date("Y-m-d");
$jam = date("H:i:s");
$catatan = "";
$NF=date("YmdHis");
$gambar="img-$NF.jpg";
//$file="C:\\Users\\USER\\Desktop\\IMGS\sent.jpg";
$file="D:\\ftp\image.jpg";
$newfile="C:\\xampp\\htdocs\\ap_ipcamera_keamanan\\ypathfile\\".$gambar;
$GB="http://192.168.0.123/ap_ipcamera_keamanan/ypathfile/".$gambar;
//$newfile="C:\\xampp\\htdocs\\_PROJECT_FINAL\\arduino\\ap_ipcamera_keamanan\\ypathfile\\".$gambar;
if(!copy($file,$newfile)){
$catatan= "failed to copy $gambar";
}
else{
$catatan= "copied $gambar success\n";
}
$sql="INSERT INTO `$tblog`
(`kode_log`, `sensor`, `tanggal`, `jam`,`catatan`, `status`, `gambar`) VALUES
('', '$sensor', '$tanggal', '$jam', '$catatan', '$status', '$gambar')";
$simpan=process($conn,$sql);
//TELEGRAM
$ada=0;
if($sensor == "terbuka"){
$ada=1;
echo $pesan = "Ada Gangguan..sialakndi cek.... \n $GB";
}
echo "sukses";
}
else{
echo "failed";
}
if($ada==1){
//notif telegram
echo $TOKEN = "883027477:AAFbkuJWd2RyB0_j2HYKMzRQIombn4NgUE4"; // ganti token ini dengan token bot
$chatid = "411787355"; // diganti dan disesuaikan
$method = "sendMessage";
$url = "https://api.telegram.org/bot" . $TOKEN . "/". $method;
$post = [
'chat_id' => $chatid,
// 'parse_mode' => 'HTML', // aktifkan ini jika ingin menggunakan format type HTML, bisa juga diganti menjadi Markdown
'text' => $pesan
];
$header = [
"X-Requested-With: XMLHttpRequest",
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
];
// hapus 1 baris ini:
//die('Hapus baris ini sebelum bisa berjalan, terimakasih.');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_REFERER, $refer);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$datas = curl_exec($ch);
$error = curl_error($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$debug['text'] = $pesan;
$debug['code'] = $status;
$debug['status'] = $error;
$debug['respon'] = json_decode($datas, true);
//print_r($debug);
}
?>
<?php
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if($rs){
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s=true;
}
}
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
?>
Tidak ada komentar:
Posting Komentar