-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-esp-data-b.php
73 lines (58 loc) · 2.07 KB
/
post-esp-data-b.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/*
post-esp-data-b.php
This module is to be inserted into the /var/www/html directory stored on the Raspberry
Pi. Its purpose is to receive data from the AIO PV Sensor at Panel B and store it in
its respective database.
Created by UCF Senior Design Spring 2022 - Summer 2022 Group 6
Released on June 30th, 2022
*/
$servername = "localhost";
// REPLACE with your Database name
$dbname = "esp_data_b";
// REPLACE with Database user
$username = "root";
// REPLACE with Database user password
$password = "sdouc";
$api_key_value = "uc7LkiKar7";
$api_key= $sensor = $location = $value1 = $value2 = $value3 = $value4 = $value5 = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$api_key = test_input($_POST["api_key"]);
if($api_key == $api_key_value) {
$sensor = test_input($_POST["sensor"]);
$location = test_input($_POST["location"]);
$value1 = test_input($_POST["value1"]);
$value2 = test_input($_POST["value2"]);
$value3 = test_input($_POST["value3"]);
$value4 = test_input($_POST["value4"]);
$value5 = test_input($_POST["value5"]);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO SensorDataB (sensor, location, value1, value2, value3, value4, value5)
VALUES ('" . $sensor . "', '" . $location . "', '" . $value1 . "', '" . $value2 . "', '" . $value3 . "', '" . $value4 . "', '" . $value5 . "')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
else {
echo "Wrong API Key provided.";
}
}
else {
echo "No data posted with HTTP POST.";
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>