Sim900 AT + HTTPPARA缺少字符

时间:2018-02-05 04:16:26

标签: php arduino sim900

我正在做一个项目,我将两个变量发送到我的网站,我的网站将接收并显示它。

项目信息:Arduino + SIM900 + PHP(向网站发送数据)

我有代码将AT命令发送到我的SIM900并显示其回复。

我的问题是,当我在串行监视器中运行我的代码时,似乎URL上的最后一个引用没有被发送/打印到我的SIM900。

这是我的代码:

#include <SoftwareSerial.h>
SoftwareSerial GPRS(5, 6);
long duration;
int distance;
const int trigPin = 10;
const int echoPin = 11;

void setup() {
  powerUp();  
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  GPRS.begin(19200);
  Serial.begin(19200);

  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  GPRS.flush();
  Serial.flush();

  // See if the SIM900 is ready
  GPRS.println("AT");
  delay(1000);
  toSerial();
  GPRS.print("at+cmee=2\r");
  toSerial();
  // SIM card inserted and unlocked?
  GPRS.println("AT+CPIN?");
  delay(1000);
  toSerial();

  // Is the SIM card registered?
  GPRS.println("AT+CREG?");
  delay(1000);
  toSerial();

  // Is GPRS attached?
  GPRS.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  GPRS.println("AT+CSQ ");
  delay(1000);
  toSerial();

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

  // Set the APN
  GPRS.println("AT+SAPBR=3,1,\"APN\",\"internet\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  GPRS.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  GPRS.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
}

void loop() {
  delay(10000);
  sensor();
  GPRS.println("AT+HTTPINIT\r");
  delay(1000);
  toSerial();
  GPRS.println("AT+HTTPPARA=\"CID\",1\r");
  delay(1000);
  toSerial();
  GPRS.println("AT+HTTPPARA=\"URL\",\"aclc-onlineparkingtracker.000webhostapp.com/?id=1&sts=0\r"); <--- HERE
  delay(10000);
  toSerial();
  GPRS.println("AT+HTTPACTION=0\r");
  delay(7000);
  toSerial();
  GPRS.println("AT+HTTPTERM\r");
  toSerial();
}

void toSerial() {
  while(GPRS.available()!=0) {
    Serial.write(GPRS.read());
  }
}

void powerUp() {
  pinMode(9, OUTPUT);
  digitalWrite(9, LOW);
  delay(1000);
  digitalWrite(9, HIGH);
  delay(2000);
  digitalWrite(9,LOW);
  delay(3000);
}

这是我的串行监视器中的输出:

Con
Done!...
AT

OK
at+cmee=2
AT+CPIN?

OK
AT+CREG?

+CREG: 0,1

OK
AT+CGATT?

+CGATT: 0

OK
AT+CSQ 

+CSQ: 10,0

OK
AT+SAPBR=3,1,"Contype","GPRS"

OK
AT+SAPBR=3,1,"APN","internet"

OK
AT+SAPBR=1,1

OK
AT+SAPBR=2,1

+SAPBR: 1,1,"10.32.133.18"

OK
AT+HTTPINIT


OK
AT+HTTPPARA="CID",1


OK
AT+HTTPPARA="URL","aclc-onlineparkingtracker.000webhostapp.com/?id=1&st=1 <--HERE


+CME ERROR: operation not allowed

我尝试了什么:

  • 更改TX&amp;的缓冲区大小RX到256(SoftwareSerial.hHardwareSerial.h)。没用。

  • 添加了延迟。没用。

1 个答案:

答案 0 :(得分:0)

<强>更新

我更改了这一行:

Caused by: java.lang.RuntimeException: Unable to start service com.services.BackgroundPlayerService@95236fd with Intent { cmp=com.dev/com.services.BackgroundPlayerService launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND cat=[android.intent.category.LAUNCHER] typ=text/plain flg=0x10000001 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={text/plain T:Watch "CHVRCHES - Get Out (Preview)"

GPRS.println("AT+HTTPPARA=\"URL\",\"aclc-onlineparkingtracker.000webhostapp.com/?id=1&sts=0\r");

我删除了GPRS.println("AT+HTTPPARA=\"URL\",\"aclc-onlineparkingtracker.000webhostapp.com/?id=1&st=1\""); ,并在网址末尾添加了\r