【问题标题】:Sending data to a PHP file on a server将数据发送到服务器上的 PHP 文件
【发布时间】:2019-09-30 17:21:28
【问题描述】:

我正在做一个将数据发送到我的网站的项目,使用 Arduino 和 SIM900,我刚刚制作了一个 AT 代码来将数据发送到网站并使用 PHP,但是我的 PHP 文件没有好像收到了SIM900 AT指令发送过来的值,为什么?我的另一个问题是,AT 命令可以安全地将数据发送到网站吗?感谢您的帮助,祝您有美好的一天。这是我目前拥有的代码:

这就是我现在的 sim900:

void setup(){
  //Inicialize Serial and SIM
  Serial.begin(19200);
  SIM900.begin(19200);

  delay(7000);

  // See if the SIM900 is ready
  SIM900.println("AT");
  ReceberEFim();                                 
  delay(4000);

  // SIM card inserted and unlocked?
  SIM900.println("AT+CPIN?");
  ReceberEFim();
  delay(500);              

  // Is the SIM card registered?
  SIM900.println("AT+CREG?");
  ReceberEFim();                            
  delay(500);

  // Is GPRS attached?
  SIM900.println("AT+CGATT?");
  ReceberEFim();                           
  delay(500);

  // Check signal strength - should be 9 or higher
  SIM900.println("AT+CSQ");
  ReceberEFim();                              
  delay(500);

  // Set connection type to GPRS
  SIM900.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  ReceberEFim();      
  delay(1000);

  // Set the APN - this will depend on your network/service provider
  SIM900.println("AT+SAPBR=3,1,\"APN\",\"claro.com.br\"");
  ReceberEFim();      
  delay(1000);

  // Enable GPRS - this will take a moment or two
  SIM900.println("AT+SAPBR=1,1");
  ReceberEFim();                      
  delay(3000);

  // Check to see if connection is correct and get your IP address
  SIM900.println("AT+SAPBR=2,1");
  ReceberEFim();                        
  delay(500);

  // Enable HTTP mode
  SIM900.println("AT+HTTPINIT");
  ReceberEFim();                        
  delay(2000);

  SIM900.println("AT+HTTPPARA=\"URL\",\"http://mywebsite.com/teste.php?s1=50\"");
  ReceberEFim();
  delay(2000);                               

  SIM900.println("AT+HTTPPARA=\"CID\",1");
  ReceberEFim();             
  delay(500);

  SIM900.println("AT+HTTPACTION=0");
  ReceberEFim();                   
  delay(500);

  // Close the HTTP connection
  SIM900.println("AT+HTTPTERM");
  ReceberEFim();

  // Disconnect the GPRS
  SIM900.println("AT+SAPBR=0,1");
  ReceberEFim();
}

这是 PHP 文件:

   <?php 
    $sensor1 = $_GET["s1"];
    $sensor2 = $_GET["s2"];
    $sensor3 = $_GET["s3"];

    echo "Sensor 1 = $sensor1";
    echo "</br>Sensor 2 = $sensor2";
    echo "</br>Sensor 3 = $sensor3";

  ?>

我希望能够通过 SIM900 向我的 PHP 文件发送多个数据。

【问题讨论】:

标签: php http arduino at-command sim900


【解决方案1】:

你的 url 中没有传递 s2 和 s3,所以你无法访问它,它会产生错误。

您可以动态检测 s{n} var 或尝试 isset 来检查 var 是否存在。

我认为出于安全原因和会话或令牌使用 https 会更好,以确保不是其他人试图向您的站点发送随机值。

希望对你有帮助

【讨论】:

  • 嘿,我尝试传递其他 2 个参数(s2 和 s3),但我收到了这个奇怪的错误,它确实允许我的 URL 完成打印,我添加了延迟,但它确实使任何区别。这就是我实现的: SIM900.print("AT+HTTPPARA=\"URL\",\"mywebsite.com.br/teste.php?s1=72&s2=32&s3=8\"");这是我得到的错误 AT+HTTPPARA="URL","mywebsite.com.br/…
猜你喜欢
  • 2011-11-28
  • 2016-02-10
  • 1970-01-01
  • 2012-07-14
  • 2012-07-19
  • 2011-07-28
  • 2014-04-27
  • 2015-01-05
  • 1970-01-01
相关资源
最近更新 更多