tcp - Arduino UNO 和调制解调器 Sim800L 无法编写设置命令将数据发送到服务器
问题描述
我正在使用带有调制解调器 sim800l 的 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/IP 连接的发送命令序列:
//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 的工具,然后将成功的过程复制到代码中。
推荐阅读
- reactjs - 在 ag-Grid 的单元格中添加 selectize.js 下拉列表的问题
- git - 删除特定分支文件夹后进行合并时是否会发生冲突?
- javascript - 如何遍历字符串数组,为每个项目创建一个对象?
- c - 逐行读取字符串导致缓冲区溢出
- javascript - Twitter Bootstrap - 放置一个大的 Popover 以覆盖屏幕的中心
- open-policy-agent - 是否可以在开放策略代理策略中使用外部程序的输出
- java - 如何用 PDActionJavaScript 替换 PDAnnotationLink 的默认操作?
- python - 如何在 Pyspark 中编写 for 循环或情节
- java - 如何重新排列一个整数,以便将其重新排列为 Java 中的最高可能值?
- delphi - 无法在 Delphi 中更改 TEdit 文本