我的ESP8266 / NodeMCU如何与GSM模块SIM800L通信?

问题描述

所以我想将SIM800L GSM模块连接到NodeMCU。我购买了LM2596 DC-DC稳压器,将SIM800L的输出电压转换为约4V。稳压器的输入电压为9V / 1A。

所有设备均已连接:GSM到D5(GPIO14)的接收,RX到D6(GPIO12)的信号,以及RST到D7(GPIO13)的信号。自从我在线阅读以来,特意选择了GPIO,以确保内部使用NodeMCU上的RX / TX引脚。我之前尝试过匹配RX / TX引脚,但是结果是一样的(这就是为什么我确定,必须是我的代码有缺陷)。 SIM卡也已插入GSM模块(带有PIN)。

我正在Arduino IDE上进行编码,并且正在使用GSMSim和SoftwareSerial库连接到GSM模块。我已经尝试过从GSMSim提取示例草图以与GSM模块通信,但是在串行监视器上没有任何答案。

我还尝试过手动将命令发送到GSM模块。

#include <GSMSim.h>
#include <SoftwareSerial.h>

// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples,i used HardwareSerial. You can change it anymore.

#define RX 14
#define TX 12
#define RESET 13

SoftwareSerial serial(RX,TX);
GSMSim gsmModule(serial,RESET);

void setup() {
  serial.begin(115200); // If you dont change module baudrate,it comes with auto baudrate.
  while(!serial) ;
  Serial.begin(115200); // Serial for debug...
  while(!Serial) ;

  Serial.println("");
  Serial.println("serial begin");
  
    // Init module...
    gsmModule.init(); // use for reseting module. Use it if you dont have any valid reason.
  delay(100);

  gsmModule.sendATCommand("AT+GMR");
  if(serial.available()) Serial.println(serial.readString());
  Serial.println("Sent AT");

}

输出:

serial.begin
Sent AT

修改后的GSMSim_HTTP草图的另一个示例:

#include <GSMSim.h>
#include <SoftwareSerial.h>

// You can use any Serial interface. I recommended HardwareSerial. Please use the library with highiest baudrate.
// In examples,TX);
GSMSim http(serial,RESET);
static volatile int num = 0;

void setup() {
  serial.begin(115200); // If you dont change module baudrate,it comes with auto baudrate.

  while(!serial) {
    ; // wait for module for connect.
  }

  Serial.begin(115200); // Serial for debug...

  // Init module...
  http.init(); // use for init module. Use it if you dont have any valid reason.

  Serial.print("Set Phone Function... ");
  Serial.println(http.setPhoneFunc(1));
  //delay(1000);

  Serial.print("is Module Registered to Network?... ");
  Serial.println(http.isRegistered());
  //delay(1000);

  Serial.print("Signal Quality... ");
  Serial.println(http.signalQuality());
  //delay(1000);

  Serial.print("Operator Name... ");
  Serial.println(http.operatorNameFromSim());
  //delay(1000);


  //Serial.print("GPRS Init... ");
  //Serial.println(http.gprsInit("internet")); // Its optional. You can set apn,user and password with this method. Default APN: "internet" Default USER: "" Default PWD: ""
  //delay(1000);


  Serial.print("Connect GPRS... ");
  Serial.println(http.connect());
  //delay(1000);

  Serial.print("Get IP Address... ");
  Serial.println(http.getIP());
  delay(1000);
  
 
  Serial.print("Get... ");
  Serial.println(http.get("sera.erdemarslan.com/test.php"));
  delay(1000);

  Serial.print("Get with SSL and read returned data... ");
  Serial.println(http.getWithSSL("erdemarslan.com/test.php",true));
  delay(1000);

  Serial.print("Post... ");
  Serial.println(http.post("sera.erdemarslan.com/test.php","name=Erdem&surname=Arslan","application/x-www-form-urlencoded"));
  delay(1000);

  Serial.print("Post with SSL and read returned data... ");
  Serial.println(http.post("erdemarslan.com/test.php","application/x-www-form-urlencoded",true));
  delay(1000);

  Serial.print("Close GPRS... ");
  Serial.println(http.closeConn());
  //delay(1000);

  // For other methods please look at readme.txt file.

}

void loop() {
  
  // Use your Serial interface...
  if(serial.available()) {
      String buffer = "";
      buffer = Serial1.readString();
      num = num + 1;
      Serial.print(num);
      Serial.print(". ");
      Serial.println(buffer);
  }
  
  // put your main code here,to run repeatedly:
}

输出:

serial.begin
Set Phone Function... 0
is Module Registered to Network?... 0
Signal Quality... 99
Operator Name... NOT CONNECTED
Connect GPRS... 0
Get IP Address... 
Get module date time... ERROR:NOT_GET_DATETIME
Set timezone and time server... 0
Sync date time from server... AT_COMMAND_ERROR
Get module date time after sycn... ERROR:NOT_GET_DATETIME
Close GPRS... 0

我希望这很明显,因为我根本不熟悉AT命令。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...