Arduino UNO & 调制解调器 Sim800L 无法编写设置命令向服务器发送数据。

问题描述 投票:0回答:2

我用的是arduino UNO板,带调制解调器sim800l,我想用它来发送数据到服务器,但问题是我不能写设置命令。

我到底做错了什么?我试过用不同的命令,结果都是一样的。

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);

  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(100);
  delay(1000);

  mySerial.println("AT+CMEE=2"); // Error mode 
  delay(100);
  updateSerial();

  mySerial.println("AT"); //Once the handshake test is successful, i t will back to OK
  delay(100);
  updateSerial();

  mySerial.println("AT+CFUN=1"); //Level "full functionality" 
  delay(100);
  updateSerial();

  mySerial.println("AT+CGATT?"); //attach or detach from GPRS service 
  delay(100);
  updateSerial();

  mySerial.println("AT+CSTT=\"net\",\"\",\"\""); //AT+CSTT AT command sets up the apn, user name and password for the PDP context.
  delay(2000);
  updateSerial();

  mySerial.println("AT+CSTT?"); //AT+CSTT show apn
  delay(2000);
  updateSerial();

  mySerial.println("AT+CIICR"); //  Brings up wireless connection
  delay(2000);
  updateSerial();

  mySerial.println("AT+CIFSR"); //  Get local IP address if connected
  delay(2000);
  updateSerial();
}

以下是Arduino IDE控制台的输出。

Initializing... 
AT+CHEE=2 
OK 
AT 
OK 
AT+CFUN=1 
OK 
AT+CGAIT? 
+CGATT: 1 
OK 
AT+CSTT="net","","" 
+CME ERROR: operation not allowed 
AT+CSTT? 
+CSTT: "CMNET","","" 

OK 
AT+CIICR 
+CME ERROR: operation not allowed 
AT+CIFSR 
+CME ERROR: operation not allowed 
tcp arduino gsm sim800 sim800l
2个回答
0
投票

我很同情你,我花了几个星期才让我的Arduino与网络对话。我认为你的问题发生在包含 "CSTT "的行,我认为SIM800L无法识别。

试试下面的设置,用 "SAPBR "代替。

SoftwareSerial gprsSerial(7, 8); // working here with Arduino ports 7 and 8
void setup() {
  gprsSerial.begin(19200);
  Serial.begin(19200);
  Serial.println("connect to GPRS");
  gprsSerial.println("AT");
  toSerial();
  gprsSerial.println("AT+CREG?");  
  toSerial();
  gprsSerial.println("AT+CGATT?");
  toSerial();
  gprsSerial.println("AT+CSQ ");
  toSerial();
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"" + String(APN) + "\"");
  delay(300);
  gprsSerial.println("AT+SAPBR=3,1,\"USER\",\"" + String(USER) + "\"");
  delay(300);
  gprsSerial.println("AT+SAPBR=3,1,\"PWD\",\"" + String(PWD) + "\"");
  delay(1000);
  toSerial();
  gprsSerial.println("AT+SAPBR=1,1");
  delay(2000);
  toSerial();
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
}

你的运行循环。

void loop(){
// Do your stuff
}

你的toSerial函数

void toSerial()
{
  delay(200);
  if(gprsSerial.available()>0){
    textMessage = gprsSerial.readString();
    delay(100);
    Serial.print(textMessage);    
  }
}

你的调用服务器函数应该是这样的

void callServer() {
  Serial.println("Calling server");
  gprsSerial.println("AT+CCLK?");
  toSerial();
  gprsSerial.println("AT+HTTPINIT");
  toSerial();
  gprsSerial.println("AT+HTTPPARA=\"CID\",1");
  toSerial();
  gprsSerial.println("AT+HTTPPARA=\"URL\",\"http:[YOURURL]") // NOTE: NOT HTTPS!
  delay(1000);
  toSerial();
  gprsSerial.println("AT+HTTPACTION=0");
  delay(3000);
  toSerial();
  gprsSerial.println("AT+HTTPREAD");
  delay(3000);
  toSerial();
}

0
投票

建立TCPIP连接的发送命令序列。

//Check the registration status
AT+CREG?

//Check attach status
AT+CGACT?

//Attach to the network
AT+CGATT=1

//Wait for Attach
WAIT=7

//Start task ans set the APN. Check your carrier APN
AT+CSTT="bluevia.movistar.es" // Here you havve net which I guess is not a NetworkAPN you have to use the APN from your provider (= sim card)

//Bring up the wireless connection
AT+CIICR

//Wait for bringup
WAIT=6

//Get the local IP address
AT+CIFSR

//Start a TCP connection to remote address. Port 80 is TCP.
AT+CIPSTART="TCP","74.124.194.252","80"

//Set prompt of '>' when module sends data
AT+CIPSPRT=1

//Send the TCP data
AT+CIPSEND

如果你想快速测试一个稳定的设置,就用这个吧 7天免费使用SIM800、SIM900的工具。 然后将成功的过程复制到代码中。

© www.soinside.com 2019 - 2024. All rights reserved.