【问题标题】:Making a GET request using an Arduino Uno & Ciao使用 Arduino Uno & Ciao 发出 GET 请求
【发布时间】:2017-02-08 10:09:29
【问题描述】:

我正在使用 Arduino Uno Wifi,我想将传感器数据从我的 Uno 发送到 PHP 脚本,该脚本将数据保存到 MySQL 数据库中。对于 GET 请求,我使用 UnoWiFiDevEd.h 库中的 Ciao.write() 函数,因为我还没有找到另一种可能的方法(不使用屏蔽)。

这就是我的 Arduino 代码的样子:

#include <UnoWiFiDevEd.h>

void setup() {
  char* connector = "rest";
  char* server = "myserver/src/add_data.php?";
  char* method = "GET";
  String resource = "humidity=11&&temperature=22";

  Serial.begin(9600);
  Ciao.begin();

  doRequest(connector, server, resource, method);
}

void loop() {

}

void doRequest(char* conn, char* server, String command, char* method) {
  CiaoData data = Ciao.write(conn, server, command, method);
  if(!data.isEmpty()){
    Serial.println("Success");
  } else {
    Serial.println("FAILED");
  }  
}

这是我的 PHP 脚本 (get_data.php)

<?php
    // Connect to MySQL
    include("dbconnect.php");

    // Prepare the SQL statement
    $SQL = "INSERT INTO arduino_data (Humidity, Temperature) VALUES ('".$_GET["humidity"]."', '".$_GET["temperature"]."')";

    // Execute SQL statement
    mysql_query($SQL);
?>

如果我使用浏览器并将“myserver/src/add_data.php?humanity=60&&temperature=22”写入 url 栏,一切正常。

我想我可能会误解这个 Ciao.write 的工作原理,即使我查看了代码(在 CiaoData PassThroughRead 函数中)并认为我指定的一切都是正确的。 documentation 根本没有帮助。

作为参考,我使用了这个tutorial,它以某种方式完全工作。

【问题讨论】:

  • 不能解决问题,但是你通过两个GET参数在$SQL变量中进行了SQL注入
  • 你的意思是作为一个安全漏洞?现在这只是一种解决方法,直到我找到一种更好的方法,将传感器数据直接从我的 Arduino Uno Wifi 写入 MySQL 数据库

标签: php rest arduino wifi arduino-uno


【解决方案1】:

您需要使用 POST 而不是 GET 方法。我有确切的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2011-04-10
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多