ESP8266无法将数据发送到本地数据库(XAMPP)

时间:2019-11-16 21:20:53

标签: php arduino xampp esp8266 at-command

我正在做一个项目,该项目的一个要素是将数据从esp8266发送到在xampp(也为本地服务器)上创建的数据库。首先,我想检查它的工作原理,因此我将esp连接到计算机,在ArduinoIDE上打开终端并编写了一些AT命令,以将其连接到与笔记本电脑相同的wi-fi,然后通过命令连接到xampp服务器(apache) :

AT+CIPSTART="TCP","192.168.1.15",80

我得到了连接的响应,所以我想通过GET函数发送一些数据

AT+CIPSEND=75
GET /dht.php?temperature=30&humidity=60 HTTP/1.1\r\nHost: 192.168.1.15\r\n

但是我在终端这样的响应:

> GET /dht.php?temperature=30&humidity=60 HTTP/1.1\r\nHost: 192.168.1.15\r\n
SEND OK

+IPD,883:HTTP/1.1 400 Bad Request
Date: Sat, 16 Nov 2019 21:11:36 GMT
Server: Apache/2.4.37 (Win32) OpenSSL/1.1.1 PHP/7.2.12
Vary: accept-language,accept-charset
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=utf-8
Content-Language: en
Expires: Sat, 16 Nov 2019 21:11:36 GMT

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bad request!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/ 
    body { color: #000000; background-color: #FFFFFF; }
    a:link { color: #0000CC; }
    p, address {margin-left: 3em;}
    span {font-size: smaller;}
/*]]>*/--></style>
</head>

<body>
<h1>Bad request!
OK

+IPD,399:</h1>
<p>


    Your browser (or proxy) sent a request that
    this server could not understand.

</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:postmaster@localhost">webmaster</a>.

</p>

<h2>Error 400</h2>
<address>
  <a href="/">localhost</a><br />
  <span>Apache/2.4.37 (Win32) OpenSSL/1.1.1 PHP/7.2.12</span>
</address>
</body>
</html>


OK
CLOSED

OK

您知道我做错了吗? 这也是我的dht.php代码,我将其放在xampp文件夹中的“ htdocs”文件夹中

<?php
class dht11{
 public $link='';
 function __construct($temperature, $humidity){
  $this->connect();
  $this->storeInDB($temperature, $humidity);
 }

 function connect(){
  $this->link = mysqli_connect('localhost','root','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'projekt_it') or die('Cannot select the DB');
 }

 function storeInDB($temperature, $humidity){
  $query = "insert into dht11 set humidity='".$humidity."', temperature='".$temperature."'";
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }

}
if($_GET['temperature'] != '' and  $_GET['humidity'] != ''){
 $dht11=new dht11($_GET['temperature'],$_GET['humidity']);
}
?>

PS。当我在浏览器http://localhost/dht.php?temperature=99&humidity=99中写信时 新值在我的数据库中,因此我认为此.php代码可以正常工作。

0 个答案:

没有答案