Friday, May 22, 2020

grab the data with the script

Step 1:

Plug in the Heltec Wifi 32 into the computer

Step 2:

Open the serial monitor in the Arduino IDE. Record the ip adress.
e.g. 10.0.0.7

Step 3:

Enter "http://" prefixing the ip address in the browser.

e.g. "http://10.0.0.7" .




Step 4:

"hello from esp8266!" should be displayed in the browser window.

Step 5:

Turn on the LoRa transmitter board (heltec cubecell) and refresh the browser.

"hello from esp8266!Hello world number9 lumens: -1610612736"


Step 6:

look for a PHP script that does an HTTP GET

grab the data with the script:
(find different ways to do this)
/var/www/html/testcode/get_data$get_data_short.php

"
<?php

$url = "http://10.0.0.7";

$opts = array('http' =>
    array(
        'method' => 'GET',
        'max_redirects' => '0',
        'ignore_errors' => '1'
    )
);

$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);

// header information as well as meta data
// about the stream
//var_dump(stream_get_meta_data($stream));

// actual data at $url
$str = var_dump(stream_get_contents($stream));
fclose($stream);

echo "hai monkey boy";
// parse the string the get lumens

// Recommended
parse_str($str, $output);
var_dump($output);
//echo $output['first'];  // value
//echo $output['arr'][0]; // foo bar
//echo $output['arr'][1]; // baz


?>
"

or see also:

~/Downloads/php-tests5_new$test4_reactphp_httpclient.ph

"
<?php

require "vendor/autoload.php";

use React\HttpClient\Client;

$loop = React\EventLoop\Factory::create();
$client = new React\HttpClient\Client($loop);

$request = $client->request('GET', 'http://10.0.0.12');
$request->on('response', function ($response) {
        $response->on('data', function ($chunk) {
        echo "start of string";
        echo "\r\n";
        echo $chunk;
        echo "\r\n";
        echo "end of new string";
        echo "\r\n";
    });
    $response->on('end', function() {
            echo 'DONE';
            echo "\r\n";
    });
});
$request->on('error', function (\Exception $e) {
    echo $e;
});
$request->end();
$loop->run()

?>
"

Step 7:

Parse string from get request . (followed in code in step 6)

Step 8:

insert the reading into the database table.

/var/www/html/testcode/previous_attempts$connect3f3.php

"
<?php
$mysqli = new mysqli("localhost", "user", "password", "database_name");


/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$dt = date("Y-m-d H:i:s");
$id = 7;

// I need to create a value for ID that prints the next value
$query = "INSERT INTO BH1750 VALUES (NULL, 23,"."'$dt'".")";
$mysqli->query($query);

/* close connection */
$mysqli->close();
?>
"



No comments:

Post a Comment