IoT System Design 3- Data Processing on the Web Server Side

IoT System Design 3- Data Processing on the Web Server Side

Request from Mcu as "iot.milivolt.com.tr/receive_data.php?deg1=xx&deg2=yy"
It is processed by the Web Server.

Description of receive_data.php file:

The file is written in PHP to retrieve data, insert it into the database, and return notification messages during operations.


The $servername, $username, $password, and $dbname variables contain information required to access the database.


The $_GET superglobal array receives data sent by HTTP GET request (deg1 and deg2).


A connection to the database is created with the new mysqli() function. If a connection error occurs, the die() function displays the error message and the process is terminated.


Data is added to the database with the INSERT INTO SQL statement. The $sql variable contains this SQL statement.


$conn->query($sql) === TRUE if the query was run successfully "Data was added successfully." message is displayed, otherwise error details are given with the error message.


The database connection is closed with the ->close() method.


This PHP file is used to save incoming temperature and humidity data to a database. When the request is made, this file adds data to the database and returns the result of the operation.

file content of receive_data.php:

<?php
// Database information
$servername = "localhost"; // Server name or IP address
$username = "milivoltcomtr_iot"; // Database username
$password = "123456789"; // Database user password
$dbname = "milivoltcomtr_iot"; // Database name

// Get incoming data with GET request
$deg1 = $_GET['deg1']; // Initial data (temperature)
$deg2 = $_GET['deg2']; // Second data (moisture)

// Create database connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
     die("Database connection error: " . $conn->connect_error);
}

// Add the data to the database
$sql = "INSERT INTO dht (temp, humd) VALUES ('$deg1', '$deg2')";

if ($conn->query($sql) === TRUE) {
     echo "Data successfully added."; // Return this message if data was added successfully
} else {
     echo "Error adding data: " . $conn->error; // Return error message if error occurred
}

$conn->close(); // Close the database connection
?>