可以使用Arduino Uno,GSM SIM900和GPS模型将数据发送到000WEBH0ST服务器。错误是在AT+ cipsend

发布于 2025-02-04 18:05:29 字数 2180 浏览 5 评论 0原文

我想尝试将数据输入到000WebHost服务器中。在我的案例研究中,我使用Arduino Uno,GSM SIM900和GPS模块。一切顺利,GSM上没有错误。同样,GSP可以轻松获得纬度和经度。当您要将数据发送到服务器时,有一个错误是AT + CIPSEND。因此,数据无法输入000WebHost服务器。我的代码有问题吗?有我的Arduino IDE代码

void setup()
{
  Serial.begin(9600);   
  SIM900.begin(9600);  
  delay(100);
  Serial.println("Initializing...");
  delay(1000);
  SIM900.println("AT");
  updateSerial();
  SIM900.println("AT+CPIN?");
  updateSerial();
  SIM900.println("AT+CREG?");
  updateSerial();
  SIM900.println("AT+COPS?");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  updateSerial();
  SIM900.println("AT+CIPMUX=0");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CSTT=\"airtelgprs.com\"");
  updateSerial();
  SIM900.println("AT+CIICR");
  delay(2000);
  updateSerial();
  SIM900.println("AT+CIFSR");
  updateSerial();
  SIM900.println("AT+CIPSPRT=0");
  delay(3000);
  updateSerial();
  SIM900.println("AT+CIPSTART=\"TCP\",\"xxxxx.000webhostapp.com\",\"80\"");
  delay(3000);
  updateSerial();
  Serial.begin(9600);
 gpsSerial.begin(9600);
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    SIM900.write(Serial.read());
  } 
  while(SIM900.available()) 
  {
    Serial.write(SIM900.read());
  }
}
 
void loop()
{
    while(1)
  {
   while (gpsSerial.available() > 0)
    { gps.encode(gpsSerial.read()); }
      if (gps.location.isUpdated())
      {
       latitude=gps.location.lat();
       longitude=gps.location.lng();
       break;
      }
 }
   Serial.println("LATITUDE=" + String(latitude,6));
   Serial.println("LONGITUDE=" + String(longitude,6));
   delay(1000);
  SIM900.println("AT+CIPSEND");
  delay(10000);
  updateSerial();
  String str="GET /coba.php?latitude=" + String(latitude) + "&longitude=" +String(longitude);
  Serial.println(str);
  SIM900.println(str);
  updateSerial();
  SIM900.println(" HTTP/1.1\r\n");
  delay(4000);
  updateSerial();
  SIM900.println("Host: xxxx.000webhostapp.com");
  updateSerial();
  SIM900.println((char)26);
  delay(5000);
  SIM900.println();
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  delay(100);
} 

I want to try entering data into the 000webhost server. In my case study, I use arduino uno, GSM sim900, and GPS module. all went well and there was no error on the GSM. Likewise, the GSP can easily get the latitude and longitude. When you want to send data to the server there is an error is at AT + CIPSEND. So the data cannot enter the 000webhost server. Is there something wrong with my code? there is my arduino ide code

void setup()
{
  Serial.begin(9600);   
  SIM900.begin(9600);  
  delay(100);
  Serial.println("Initializing...");
  delay(1000);
  SIM900.println("AT");
  updateSerial();
  SIM900.println("AT+CPIN?");
  updateSerial();
  SIM900.println("AT+CREG?");
  updateSerial();
  SIM900.println("AT+COPS?");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  updateSerial();
  SIM900.println("AT+CIPMUX=0");
  updateSerial();
  SIM900.println("AT+CGATT?");
  updateSerial();
  SIM900.println("AT+CSTT=\"airtelgprs.com\"");
  updateSerial();
  SIM900.println("AT+CIICR");
  delay(2000);
  updateSerial();
  SIM900.println("AT+CIFSR");
  updateSerial();
  SIM900.println("AT+CIPSPRT=0");
  delay(3000);
  updateSerial();
  SIM900.println("AT+CIPSTART=\"TCP\",\"xxxxx.000webhostapp.com\",\"80\"");
  delay(3000);
  updateSerial();
  Serial.begin(9600);
 gpsSerial.begin(9600);
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    SIM900.write(Serial.read());
  } 
  while(SIM900.available()) 
  {
    Serial.write(SIM900.read());
  }
}
 
void loop()
{
    while(1)
  {
   while (gpsSerial.available() > 0)
    { gps.encode(gpsSerial.read()); }
      if (gps.location.isUpdated())
      {
       latitude=gps.location.lat();
       longitude=gps.location.lng();
       break;
      }
 }
   Serial.println("LATITUDE=" + String(latitude,6));
   Serial.println("LONGITUDE=" + String(longitude,6));
   delay(1000);
  SIM900.println("AT+CIPSEND");
  delay(10000);
  updateSerial();
  String str="GET /coba.php?latitude=" + String(latitude) + "&longitude=" +String(longitude);
  Serial.println(str);
  SIM900.println(str);
  updateSerial();
  SIM900.println(" HTTP/1.1\r\n");
  delay(4000);
  updateSerial();
  SIM900.println("Host: xxxx.000webhostapp.com");
  updateSerial();
  SIM900.println((char)26);
  delay(5000);
  SIM900.println();
  updateSerial();
  SIM900.println("AT+CIPSHUT");
  delay(100);
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2025-02-11 18:05:29

我的代码有问题吗?

是的,使用delay 非常非常,非常非常非常错误 < /a>。您必须阅读并解析调制解调器发送给您的所有内容。 其他任何人都不会可靠地起作用

没有解决这个基本问题,就不可能在失败方面推断出任何内容。

Is there something wrong with my code?

Yes, using delay like that is very, very, very, very wrong. You MUST read and parse everything the modem sends back to you. Nothing else will work reliably.

Without this fundamental issue resolved it is impossible to infer anything with regards to failures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文