Blynk Cloud with PHP

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>

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.

1 Like

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

$response=json_decode($response,true);