BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk Cloud with PHP


#1

Hi
We are using Blynk in our school for tracking weather. Simple DHT11 is collecting data. We are planning to add barometric preassure sensor and anemometer. My students wanted to show results to their parents so i grab this code. It worked for me. ss

22.000 is temperature and 17 is humidity. This is not tidy and clever code but may be helpful

string replace function must be improved i guess

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://blynk-cloud.com/Auth/get/V8");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

$response = str_replace("\"","",$response);
$response = str_replace("[","", $response);
$response = str_replace("]","", $response);
// nem değerleri

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, "http://blynk-cloud.com/Auth/get/V9");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch2, CURLOPT_HEADER, FALSE);

$response2 = curl_exec($ch2);
curl_close($ch2);

$response2 = str_replace("\"","",$response2);
$response2 = str_replace("[","", $response2);
$response2 = str_replace("]","", $response2);
// nem değerleri

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, "http://blynk-cloud.com/Auth/isHardwareConnected");
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch3, CURLOPT_HEADER, FALSE);

$response3 = curl_exec($ch3);
curl_close($ch3);

$response3 = str_replace("\"","",$response3);
$response3 = str_replace("[","", $response3);
$response3 = str_replace("]","", $response3);
// nem değerleri

$t = "true";
$f = "false";

if($response3 == $t){
    $sistem = "Aktif";
} else{
    $sistem ="Pasif";
}
?>

<html>
    <head>
        <meta charset="utf-8">
        <title>İstek Meteoroloji</title>
    </head>
    <body style="background-color:efefef;">
        <center>
            <font face="arial" size="8">
                <br>
            <font size="10">İstek Kuşadası Okulları<br>
            <font size="6">Meteoroloji İstasyonu</font>
            </font>
            <hr>
            Hava Sıcaklığı:
            <?php echo $response; ?>
            <hr>
            
            Nem: %
            <?php echo $response2; ?>
            <hr>
            <font size="5">
            Sistem durumu: <?php echo $sistem; ?>
            </font>
        </center>
        </font>
    </body>
</html>


#2

To make this 100% foolproof you should ping blynk-cloud.com and put the resulting IP address in your API call instead of using blynk-cloud.com
This way, you won’t get any Geo DNS problems.

Pete.


#3

Thanks. Also i learned this data is kind of json so i can use

$response=json_decode($response,true);