Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>REST API</title>
- </head>
- <body>
- <?php
- $gas = $_GET['gas'];
- if (isset($gas)) {
- sendDb();
- sendNetpie();
- if ($gas >= 50.0){ //Alert Val
- sendLine();
- sendIFTTT();
- }else{
- echo "Val";
- }
- }
- function sendDb(){
- $gas = $_GET['gas'];
- $dbcon = mysqli_connect('localhost','root','','gasdb');
- mysqli_set_charset($dbcon,'utf8');
- $query = "INSERT INTO data (gas) VALUES ('$gas')";
- $result = mysqli_query($dbcon,$query);
- mysqli_close($dbcon);
- }
- function sendNetpie(){
- $url = 'https://api.netpie.io/topic/GAS/HOME/LED?retain';
- $username = "Y99FEk47zUqcwes";
- $password = "1UmlGSWmEtn9SCQXVFDqy3z7N";
- $data = $_GET['gas'];
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- $response = curl_exec($ch);
- }
- function sendLine(){
- $api = "https://notify-api.line.me/api/notify";
- $token = "SvUDJlRNIPC25mLn31idNlEupAEIdXRPQIOFHfDMAAr";
- $msg = "ขณะนี้ GAS มีค่า".$_GET['gas']." หน่วย";
- $ch = curl_init($api);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded","Authorization: Bearer " .$token));
- curl_setopt($ch, CURLOPT_POSTFIELDS,"message=$msg");
- $response = curl_exec($ch);
- }
- function sendIFTTT(){
- $api = "https://maker.ifttt.com/trigger/TEST/with/key/nTw8bZmfR-dtgOgl4TvUqO1U12mv9o7XQbYZmn5k_5O";
- $data = '{"value1":"'.$_GET['gas'].'"}';
- $ch = curl_init($api);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
- $response = curl_exec($ch);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement