How does my ESP8266/NodeMCU communicate with my GSM Module SIM800L?

4.8k views Asked by At

so I want to connect my SIM800L GSM Module to my NodeMCU. I bought a LM2596 DC-DC voltage regulator to convert the output voltage to ~4V for the SIM800L. Input voltage for the regulator is 9V/1A.

Everything is connected: RX from GSM to D5 (GPIO14), TX to D6 (GPIO12) and RST to D7 (GPIO13). The GPIOs are deliberately chosen, since I've read online, that the RX/TX Pins on the NodeMCU are used internally. I tried matching RX/TX pins before, but it's the same result (that's why I am certain, it has to be my code that is defect). A SIM card is also inserted in the GSM Module (with PIN).

I'm coding on the Arduino IDE and I'm using the GSMSim and SoftwareSerial libraries for connecting to the GSM Module. I've tried the example sketches from the GSMSim to communicate to the GSM Module, but I'm not getting any answer on my serial monitor.

I also tried manually sending commands to the GSM Module.

#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");

}

OUTPUT:

serial.begin
Sent AT

Another example with the modified GSMSim_HTTP sketch:

#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 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", "name=Erdem&surname=Arslan", "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:
}

OUTPUT:

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

I hope it's something obvious, since I am not familiar with AT commands at all.

Thanks!

0

There are 0 answers