dongyiba8082 2019-05-30 07:01
浏览 291

无法使用ESP8266和AT命令POST到本地Web服务器

I'm trying to send data to a local webserver running on Apache2 on a raspberry pi 3. The IP address is 192.168.0.16. I'm going to use a TIVA-C Launchpad to send POST requests to the server using a ESP8266-01 wifi module, however, before implementing everything I wanted to try and see if inputing the AT commands manually to the ESP8266-01 through UART (Using an FTDI and the arduino serial monitor) would work. At the end of the commands, the ESP returns:

> 
busy s...

Recv 180 bytes

SEND OK
CLOSED

But the database in phpMyAdmin never updates. What could be the matter?

This is the sequence of AT commands that I have tried so far but to no avail.

AT+CIPSTART="TCP","192.168.0.16",80
CONNECT

OK

AT+CIPSEND=162

OK

(I send the following POST request all in a single line)
POST /index.php HTTP/1.0

Host: 192.168.0.16

Accept:*/*
Content-Length: 40

Content-Type: application/x-www-form-urlencoded



idSensor=16555&ch1=1&ch2=0&ch3=0&ch4=1

>
busy s...

Recv 162 bytes
SEND OK
CLOSED

This is the code in my web server

<?php
header("Content-type: text/html; charset=\"utf-8\"");
$idSensor = 0;
$ch1 = 0;
$ch2 = 0;
$ch3 = 0;
$ch4 = 0;
//print_r($_POST);
if($_POST){
    $idSensor = $_POST['idSensor'];
    $ch1 = $_POST['ch1'];
    $ch2 = $_POST['ch2'];
    $ch3 = $_POST['ch3'];
    $ch4 = $_POST['ch4'];
    $conexion = mysqli_connect("localhost:3306","admin","admin4321", "Parqueo-matic");
    if(!$conexion){
        echo "Error: No se pudo conectar a MySQL.".PHP_EOL;
        echo "errno de depuración: ". mysqli_connect_errno().PHP_EOL;
        echo "error de depuración: ". mysqli_connect_error().PHP_EOL;

    }else{
        $query = "INSERT INTO `Datos` (`ID`, `Hora`, `ID_Sensor`, `P1`, `P2`, `P3`, `P4`) VALUES (NULL, CURRENT_TIMESTAMP, '$idSensor', '$ch1', '$ch2', '$ch3', '$ch4');";
        mysqli_query($conexion, $query);
        echo "Receiving data";

    }
    mysqli_close($conexion);
}

$conexion = mysqli_connect("localhost:3306","admin","admin4321", "Parqueo-matic");
if(!$conexion){
    echo "Error: No se pudo conectar a MySQL.".PHP_EOL;
    echo "errno de depuración: ". mysqli_connect_errno().PHP_EOL;
    echo "error de depuración: ". mysqli_connect_error().PHP_EOL;
}else{
    $query = "SELECT * FROM `Datos` ORDER BY ID DESC LIMIT 10";
    $result = mysqli_query($conexion,$query);
}
mysqli_close($conexion);

header("refresh: 1");

?>

<!DOCTYPE html>
<html lang='en'>
    <head>

        <!-- Required meta tags -->
        <meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
        <meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
        <title>PMatic</title>

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

        <!-- jQuery first, then Tether, then Bootstrap JS. -->
        <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>


    </head>

    <body class="container">
        <br>
        <h1><strong>Parqueo-Matic</strong></h1>
        <br>
        <table class="table">
            <thead class="bg-primary text-white">
                <tr>
                    <th>ID Sensor</th>
                    <th>Parqueo 1</th>
                    <th>Parqueo 2</th>
                    <th>Parqueo 3</th>
                    <th>Parqueo 4</th>
                </tr>
            </thead>
            <tbody> 
                <?php
                    while($row = mysqli_fetch_array($result)){
                      echo "<tr>
                                <td>".$row['ID_Sensor']."</td>
                                <td>".$row['P1']."</td>
                                <td>".$row['P2']."</td>
                                <td>".$row['P3']."</td>
                                <td>".$row['P4']."</td>
                           </tr>";       

                    }
                ?>
            </tbody>
        </table>
        <br>

    </body>

</html>

Is there any way to debug or know why my POST request is not producing any change in the database? Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学的三元一次方程求解
    • ¥20 iqoo11 如何下载安装工程模式
    • ¥15 本题的答案是不是有问题
    • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
    • ¥15 C++使用Gunplot
    • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题