· 6 years ago · Mar 17, 2020, 09:04 PM
1//Acesse https://pastebin.com/z4GnChhc para conferir o codigo do arduino
2$servername = "localhost";
3$dbname = "db";
4$username = "user";
5$password = "paaswd";
6
7$api_key_value = "0ZLO0XeiUR";
8
9
10if ($_SERVER["REQUEST_METHOD"] == "POST") {
11 $api_key = test_input($_POST["api_key"]);
12 if($api_key == $api_key_value) {
13 $humid = test_input($_POST["humid"]);
14 $temp = test_input($_POST["temp"]);
15 $fogo = test_input($_POST["fogo"]);
16 $erro = test_input($_POST["erro"]);
17
18 $conn = new mysqli($servername, $username, $password, $dbname);
19
20 if ($conn->connect_error) {
21 die("Connection failed: " . $conn->connect_error);
22 }
23
24 $sql = "INSERT INTO sensores (humid, temp, fogo, erro)
25 VALUES ($humid , $temp,$fogo , $erro)";
26
27 if ($conn->query($sql) === TRUE) {
28 echo "New record created successfully";
29 }
30 else {
31 echo "Error: " . $sql . "<br>" . $conn->error;
32 }
33
34 $conn->close();
35 }
36 else {
37 echo "Wrong API Key provided.";
38 }
39
40}
41else {
42 echo "No data posted with HTTP POST.";
43}
44
45function test_input($data) {
46 $data = trim($data);
47 $data = stripslashes($data);
48 $data = htmlspecialchars($data);
49 return $data;
50}