如何从nodemcu的硬件中获取数据并将其保存到树莓派中的数据库?

时间:2019-05-04 15:29:34

标签: mysql raspberry-pi nodemcu

我已经使用nodemcu创建了一个具有多个传感器的硬件,现在我需要直接从该硬件将此数据发送到树莓派中的mysql。

我已使用以下代码将数据发送到树莓派,

    HTTPClient http;
    String url = "http://192.168.2.110/var/www/html/insert.php?status="+String(distance)+String(movement)+String(sound);
    Serial.println(url);     
    http.begin(url);

    //GET method
    int httpCode = http.GET();
    if(httpCode > 0)
    {
      Serial.printf("[HTTP] GET...code: %d\n", httpCode);
      if(httpCode == HTTP_CODE_OK)
      {
          String payload = http.getString();
          Serial.println(payload);
      }
    }
    else
       {
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
       }
          http.end();
          delay(3000);

    if (client.connected()){
        client.stop(); // Disconnect from server
    }

insert.php的代码是

<?php
    include("connect.php");

    $link=Connection();

    $distance=$_POST["distance"];
    $movement=$_POST["movement"];
   $sound=$_POST["sound"];

    $query = "INSERT INTO `home_activity` (`Sonar`, `PIR`,`Sound`) 
        VALUES ('".$distance."','".$movement."','".$sound"')"; 

    mysql_query($query,$link);
    mysql_close($link);

    header("Location: index.php");
?>

我没有收到任何错误,但是数据库中也没有保存任何数据

0 个答案:

没有答案