Git Product home page Git Product logo

arduino-sim800l-driver's Introduction

Arduino SIM800L HTTP connector

Arduino driver for GSM/GPRS module SIMCom SIM800L to make HTTP/S connections with GET and POST methods

GitHub GitHub release GitHub issues

⚠️ Project Status: No Longer Maintained ⚠️

Thank you for your interest in this project. Unfortunately, this project is no longer maintained as I no longer have a functionning SIM800L module. Additionally, the SIM800L doesn't support current security requirements which make it very difficult to use for real use cases. As a result, there will be no further updates, bug fixes, or support.

Thank you for your understanding. This project is kept opened for fork.

Introduction

This is a comprehensive Arduino library to make HTTP or HTTPS communication through the SIMCom SIM800L module. The library has been designed to limit the memory usage by working with the same shared buffer all the time.

The SIM800L is a GSM/GPRS module built by SIMCom. The communication with the SIM800L module relies on AT commands. The available AT commands are described in the SIM800 series AT Command Manual.

Supported features in this library:

  • Power management of the SIM800L module
  • Network registration and signal strengh measurement
  • GPRS connectivity and setup (APN with or without username and password)
  • HTTP and HTTPS (SSL based on in-built IP stack, see Security concerns)
  • GET and POST methods
  • SoftwareSerial and HardwareSerial links
  • Configurable debug serial
  • Limited memory usage

To know before starting...

  • The original module is working with an input voltage of 3.7V to 4.2V. So, don't connect the naked module directly on the Arduino. I personally use a module with voltage convertors from/to 5V like this one.
  • As the chipset can draw 2A maximum, it is better to use an external power source. Using the USB power through the computer is not enough while HTTP communication.
  • There are different firmware version of the SIM800L on the market. The HTTPS connectivity is available only for R14 and above. (You can check your version with the examples BasicTest_HardwareSerial or BasicTest_SoftSerial)
  • The firmware of the SIM800L is quite old and doesn't support the latest cryptographic protocols which could lead to some issues while connecting backends (typically errors 605 and 606). Read also the section below about security concerns.

How to install the library?

The easiest way to install the library is to go to the Library manager of the Arduino IDE and install the library.

  1. In the Arduino IDE, go into menu Tools -> Manage Libraries...
  2. Search for SIM800L
  3. Install SIM800L HTTP connector by Olivier Staquet

Examples

You will find examples in the repository to make HTTPS GET and HTTPS POST.

We are using the Postman Echo service to illustrate the communication with an external API. By the way, if you need a pretty cool tool to test and validate API, I recommend Postman. They make really API devlopment simple.

Usage

Initiate the driver and the module

First, you have to initiate the driver by telling him the serial link and the RESET pin. The next two parameters defined the size of the internal buffer and the size of the reception buffer. The size of the reception buffer is depending on the data you will receive from the web service/API. If the buffer is too small, you will receive only the first 512 bytes in the examples below. The driver has a buffer overflow protection.

To initiate with a SoftwareSerial link (on pin TX_PIN and RX_PIN):

SoftwareSerial* serial = new SoftwareSerial(TX_PIN, RX_PIN);
serial->begin(9600);
SIM800L* sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512);

To initiate with a hardware serial link (Serial1):

Serial1.begin(9600);
SIM800L* sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512);

Setup and check all aspects for the connectivity

Then, you have to initiate the basis for a GPRS connectivity.

The module has to be initalized and accept AT commands. You can test it and wait the module to be ready.

sim800l->isReady();

The GSM signal should be up. You can test the signed strenght and wait for a signal greater than 0.

sim800l->getSignal();

The module has to be registered on the network. You can obtain the registration status through a specific command and wait for a REGISTERED_HOME or REGISTERED_ROAMING depending on your operator and location.

sim800l->getRegistrationStatus();

Finally, you have to setup the APN for the GPRS connectivity. By example: Internet.be for Orange Belgium who is providing SIM cards dedicated for IoT.

sim800l->setupGPRS("Internet.be");

Connecting GPRS

Before making any connection, you have to open the GPRS connection. It can be done easily. When the GPRS connectivity is UP, the LED is blinking fast on the SIM800L module.

sim800l->connectGPRS();

HTTP communication GET

In order to make an HTTP GET connection to a server or the Postman Echo service, you just have to define the URL and the timeout in milli-seconds. The HTTP or the HTTPS protocol is set automatically depending on the URL. The URL should always start with http:// or https://.

sim800l->doGet("https://postman-echo.com/get?foo1=bar1&foo2=bar2", 10000);

or

sim800l->doGet("https://postman-echo.com/get?foo1=bar1&foo2=bar2", "Header-1:value1\\r\\nHeader-2:value2", 10000);

If the method returns 200 (HTTP status code for OK), you can obtain the size of the data received.

sim800l->getDataSizeReceived();

And you can obtain the data received through a char array.

sim800l->getDataReceived();

HTTP communication POST

In order to make an HTTP POST connection to a server or the Postman Echo service, you have to define a bit more information than the GET. Again, the HTTP or the HTTPS protocol is set automatically depending on the URL. The URL should always start with http:// or https://.

The arguments of the method are:

  • The URL (https://postman-echo.com/post)
  • (optional) Headers ("Header-1:value1\r\nHeader-2:value2")
  • The content type (application/json)
  • The content to POST ({"name": "morpheus", "job": "leader"})
  • The write timeout while writing data to the server (10000 ms)
  • The read timeout while reading data from the server (10000 ms)
sim800l->doPost("https://postman-echo.com/post", "application/json", "{\"name\": \"morpheus\", \"job\": \"leader\"}", 10000, 10000);

or with headers

sim800l->doPost("https://postman-echo.com/post", "Header-1:value1\\r\\nHeader-2:value2", "application/json", "{\"name\": \"morpheus\", \"job\": \"leader\"}", 10000, 10000);

If the method returns 200 (HTTP status code for OK), you can obtain the size of the data received.

sim800l->getDataSizeReceived();

And you can obtain the data recieved through a char array.

sim800l->getDataReceived();

Disconnecting GPRS

At the end of the connection, don't forget to disconnect the GPRS to save power.

sim800l->disconnectGPRS();

Security concerns

The SIM800L latest firmware update was in January 2016. It means that using the IP stack embedded on the SIM800L is convenient but not secure. The embedded IP stack should not be used for the transfer of critical data.

The embedded IP stack of the SIM800L only supports SSL2, SSL3 and TLS 1.0. These cryptographic protocols are considered deprecated for most of web browsers and the connection will be denied by modern backend (i.e. AWS). This will typically lead to an error 605 or 606 when you establish an HTTPS connection.

In order to check the cryptographic protocols offered by your server, you can use the free service Test TLS. In order to use the SIM800L, your server must accept the supported protocol.

In order to secure your connectivity to the backend, we strongly recommend using an up-to-date SSL library like WolfSSL.

Links

arduino-sim800l-driver's People

Contributors

kimi1991 avatar ostaquet avatar per1234 avatar ztaras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-sim800l-driver's Issues

HTTP GET error 606

I am running the HTTPS_GET_HardwareSerial with ESP32 TTGO board which has SIM800L module integrated.

Strangely the example works fine but I try another URL such as

https://jsonplaceholder.typicode.com/todos/1
I get the error

HTTP GET error 606

doGet(): just write without reading?

Hello,

I think I have a simple question:

Is it possible to call a website but not to read it out? (Just open it)
(In order to save data volume)

Thanks in advance

TexhFex

http request with login and password

It is great to have this library. It is worked.
I have a server cloud that use login and password for http request.

Do you know how to implement the login and password ?

Regards,

Problem of reading and processing a Json string

Hi there,

I want to get a json string, for example one from Openweathermap.
it works perfectly, but then I want to access parameters from the string with the ArduinoJson libary in order to use them further there is some trouble.

THE PROBLEM
I am almost certain that the problem is with the delivery of:

String input = sim800l->getDataReceived();

I would be very happy to receive suggestions for solutions.

greetings from Germany!


#include "SIM800L.h"

#include <stdio.h>
#include <stdlib.h>


#include <ArduinoJson.h>
#include <Arduino.h>

#define SIM800_RX_PIN 7
#define SIM800_TX_PIN 8
#define SIM800_RST_PIN 6

const char APN[] = "internet.eplus.de";
const char URL[] = "http://api.openweathermap.org/data/2.5/weather?id=2843729&appid=6fe64bb0ac0ac7504c1a2e56672416d4";

SIM800L* sim800l;


void setup() {  
  // Initialize Serial Monitor for debugging
  Serial.begin(9600);
  while(!Serial);

  // Initialize a SoftwareSerial
  SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);
  serial->begin(9600);
  delay(1000);
   
  // Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
  sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 600);

  // Equivalent line with the debug enabled on the Serial
  // sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);

  // Setup module for GPRS communication
  setupModule();
}
 
void loop() 

{
  // Establish GPRS connectivity (5 trials)
  bool connected = false;
  for(uint8_t i = 0; i < 5 && !connected; i++) {
    delay(1000);
    connected = sim800l->connectGPRS();
  }

  // Check if connected, if not reset the module and setup the config again
  if(connected) {
    Serial.print(F("GPRS connected with IP "));
    Serial.println(sim800l->getIP());
  } else {
    Serial.println(F("GPRS not connected !"));
    Serial.println(F("Reset the module."));
    sim800l->reset();
    setupModule();
    return;
  }

  Serial.println(F("Start HTTP GET..."));

  // Do HTTP GET communication with 10s for the timeout (read)
  uint16_t rc = sim800l->doGet(URL, 20000);
   if(rc == 200) {
    // Success, output the data received on the serial
    Serial.print(F("HTTP GET successful ("));
    Serial.print(sim800l->getDataSizeReceived());
    Serial.println(F(" bytes)"));
    Serial.print(F("Received : "));
    Serial.println(sim800l->getDataReceived());

    String input = sim800l->getDataReceived();                      
    
    DynamicJsonDocument doc(800);

    DeserializationError error = deserializeJson(doc, input);

    if (error) {
      Serial.print(F("deserializeJson() failed: "));
      Serial.println(error.f_str());
    return;
    }

   JsonObject main = doc["main"];
   float main_temp = main["temp"]; /
   float main_feels_like = main["feels_like"];   
   float main_temp_min = main["temp_min"];    
   float main_temp_max = main["temp_max"];    
   int main_pressure = main["pressure"];       
   int main_humidity = main["humidity"];     
   int main_sea_level = main["sea_level"];       
   int main_grnd_level = main["grnd_level"];      

   Serial.println(main_temp);
   
   }
 
 
  else {
    // Failed...
    Serial.print(F("HTTP GET error "));
    Serial.println(rc);
  }

  delay(1000);

  // Close GPRS connectivity (5 trials)
  bool disconnected = sim800l->disconnectGPRS();
  for(uint8_t i = 0; i < 5 && !connected; i++) {
    delay(1000);
    disconnected = sim800l->disconnectGPRS();
  }
  
  if(disconnected) {
    Serial.println(F("GPRS disconnected !"));
  } else {
    Serial.println(F("GPRS still connected !"));
  }

}

void setupModule() {
    // Wait until the module is ready to accept AT commands
  while(!sim800l->isReady()) {
    Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
    delay(1000);
  }
  Serial.println(F("Setup Complete!"));

  // Wait for the GSM signal
  uint8_t signal = sim800l->getSignal();
  while(signal <= 0) {
    delay(1000);
    signal = sim800l->getSignal();
  }
  Serial.print(F("Signal OK (strenght: "));
  Serial.print(signal);
  Serial.println(F(")"));
  delay(1000);

  // Wait for operator network registration (national or roaming network)
  NetworkRegistration network = sim800l->getRegistrationStatus();
  while(network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
    delay(1000);
    network = sim800l->getRegistrationStatus();
  }
  Serial.println(F("Network registration OK"));
  delay(1000);

  // Setup APN for GPRS configuration
  bool success = sim800l->setupGPRS(APN);
  while(!success) {
    success = sim800l->setupGPRS(APN);
    delay(5000);
  }
  Serial.println(F("GPRS config OK"));
}````

Unable to compile in Arduino IDE for WAVGAT UNO R3

Hi ostaquet!

First of all! thanks to sharing your code with the community!

Well, unfortunately, I don't know code in C++ so i can't help too much hahaha, but basically, I'm trying to compile the code to a clone of Arduino, however, when it tries to compile and upload the code, occurs some errors (below). Could you try to help me to figure out what's happening? It's my IDE? The Board? The libraries?

Thanks a lot!

Arduino: 1.8.9 (Mac OS X), Board: "WAVGAT UNO R3"

Warning: platform.txt from core 'Arduino AVR Boards' contains deprecated recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}", automatically converted to recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}". Consider upgrading this core.
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp: In constructor 'SIM800L::SIM800L(int, int, int, unsigned int, unsigned int, bool)':
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:35:26: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   internalBuffer = malloc(internalBufferSize);
                          ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:43:22: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   recvBuffer = malloc(recvBufferSize);
                      ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp: In member function 'int SIM800L::doPost(const char*, const char*, char*, unsigned int, unsigned int)':
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:65:32: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
   int initRC = initiateHTTP(url);
                                ^
In file included from /Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:8:0:
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.h:69:9: note:   initializing argument 1 of 'int SIM800L::initiateHTTP(char*)'
     int initiateHTTP(char* url);
         ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:71:54: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
   sendCommand("AT+HTTPPARA=\"CONTENT\",", contentType);
                                                      ^
In file included from /Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:8:0:
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.h:54:10: note:   initializing argument 2 of 'void SIM800L::sendCommand(char*, char*)'
     void sendCommand(char* command, char* parameter);
          ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:78:24: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   char* tmpBuf = malloc(30);
                        ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:158:27: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         if((recvBuffer == '\r') || (recvBuffer == '\n')) {
                           ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:158:51: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         if((recvBuffer == '\r') || (recvBuffer == '\n')) {
                                                   ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp: In member function 'int SIM800L::doGet(const char*, unsigned int)':
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:203:32: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
   int initRC = initiateHTTP(url);
                                ^
In file included from /Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:8:0:
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.h:69:9: note:   initializing argument 1 of 'int SIM800L::initiateHTTP(char*)'
     int initiateHTTP(char* url);
         ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:268:27: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         if((recvBuffer == '\r') || (recvBuffer == '\n')) {
                           ^
/Users/mac/Documents/Arduino/libraries/Arduino-SIM800L-driver-master/SIM800L.cpp:268:51: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
         if((recvBuffer == '\r') || (recvBuffer == '\n')) {
                                                   ^
exit status 1
Error compiling for board WAVGAT UNO R3.

HTTPS_GET_SoftSerial.ino and HTTPS_POST_SoftSerial.ino get stuck after successfull GET/POST requests

Dear ostaquet,

when I try out your example with a custom URL for writing data into my database, I get an issue of the code being stuck everytime I successfully realize a get request (Code 200).

Let me show you my changes compared to your example code:

#define SIM800_TX_PIN 12
#define SIM800_RX_PIN 13
#define SIM800_RST_PIN 2

const char APN[] = "internet.telekom";
const char URL[] = "https://url.com/a.php?t1=1.22&AvaBat=4.1&NosemBat=3.8&h1=4.4&t2=5.4&h2=9.4&a31=2.0&ab21=3.0&ad1=9.0&a32=10&ab22=5&to2=10&Ta3=9.4&Ta4=1.1&Ta5=14.12&Ta55=14.12";

// Equivalent line with the debug enabled on the Serial
  sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 256, 512, (Stream *)&Serial);

The real custom url is 36 characters long.

The output in debugging mode:

15:41:59.846 -> SIM800L : Reset
15:42:01.843 -> SIM800L : Prepare internal buffer of 256 bytes
15:42:01.843 -> SIM800L : Prepare reception buffer of 512 bytes
15:42:01.843 -> SIM800L : Send "AT"
15:42:06.836 -> SIM800L : Receive timeout
15:42:06.836 -> Problem to initialize AT command, retry in 1 sec
15:42:07.822 -> SIM800L : Send "AT"
15:42:07.857 -> SIM800L : End of transmission
15:42:07.857 -> SIM800L : Receive "AT

15:42:07.857 -> OK
15:42:07.857 -> "
15:42:07.857 -> Setup Complete!
15:42:07.857 -> SIM800L : Send "AT+CSQ"
15:42:07.889 -> SIM800L : End of transmission
15:42:07.889 -> SIM800L : Receive "AT+CSQ

15:42:07.889 -> +CSQ: 0,0
15:42:07.889 -> "
15:42:08.909 -> SIM800L : Send "AT+CSQ"
15:42:08.943 -> SIM800L : End of transmission
15:42:08.943 -> SIM800L : Receive "AT+CSQ

15:42:08.943 -> +CSQ: 0,0
15:42:08.943 -> "
15:42:09.964 -> SIM800L : Send "AT+CSQ"
15:42:09.998 -> SIM800L : End of transmission
15:42:09.998 -> SIM800L : Receive "AT+CSQ

15:42:09.998 -> +CSQ: 17,0
15:42:09.998 -> "
15:42:09.998 -> Signal OK (strenght: 17)
15:42:10.984 -> SIM800L : Send "AT+CREG?"
15:42:11.016 -> SIM800L : End of transmission
15:42:11.050 -> SIM800L : Receive "AT+CREG?

15:42:11.050 -> +CREG: 0,1
15:42:11.050 -> "
15:42:11.050 -> Network registration OK
15:42:12.038 -> SIM800L : Send "AT+SAPBR=3,1,"Contype","GPRS""
15:42:12.107 -> SIM800L : End of transmission
15:42:12.107 -> SIM800L : Receive "AT+SAPBR=3,1,"Contype","GPRS"

15:42:12.139 -> OK
15:42:12.139 -> "
15:42:12.139 -> SIM800L : Send "AT+SAPBR=3,1,"APN","internet.telekom""
15:42:12.208 -> SIM800L : End of transmission
15:42:12.208 -> SIM800L : Receive "AT+SAPBR=3,1,"APN","internet.telekom"

15:42:12.208 -> OK
15:42:12.208 -> "
15:42:12.208 -> GPRS config OK
15:42:13.224 -> SIM800L : Send "AT+SAPBR=1,1"
15:42:14.039 -> SIM800L : End of transmission
15:42:14.072 -> SIM800L : Receive "AT+SAPBR=1,1

15:42:14.072 -> OK
15:42:14.072 -> "
15:42:14.072 -> GPRS connected !
15:42:14.072 -> Start HTTP GET...
15:42:14.072 -> SIM800L : Send "AT+HTTPINIT"
15:42:14.106 -> SIM800L : End of transmission
15:42:14.106 -> SIM800L : Receive "AT+HTTPINIT

15:42:14.106 -> OK
15:42:14.106 -> "
15:42:14.106 -> SIM800L : Send "AT+HTTPPARA="CID",1"
15:42:14.140 -> SIM800L : End of transmission
15:42:14.140 -> SIM800L : Receive "AT+HTTPPARA="CID",1

15:42:14.173 -> OK
15:42:14.173 -> "
15:42:14.173 -> SIM800L : Send "AT+HTTPPARA="URL","https://url.com/a.php?t1=1.22&AvaBat=4.1&NosemBat=3.8&h1=4.4&t2=5.4&h2=9.4&a31=2.0&ab21=3.0&ad1=9.0&a32=10&ab22=5&to2=10&Ta3=9.4&Ta4=1.1&Ta5=14.12&Ta55=14.12""
15:42:14.615 -> SIM800L : End of transmission
15:42:14.615 -> SIM800L : Receive "AT+HTTPPARA="URL","https://url.com/a.php?t1=1.22&AvaBat=4.1&NosemBat=3.8&h1=4.4&t2=5.4&h2=9.4&a31=2.0&ab21=3.0&ad1=9.0&a32=10&ab22=5&to2=10&Ta3=9.4&Ta4=1.1&Ta5=14.12&Ta55=14.12"

15:42:14.649 -> OK
15:42:14.649 -> "
15:42:14.649 -> SIM800L : Send "ATI"
15:42:14.685 -> SIM800L : End of transmission
15:42:14.685 -> SIM800L : Receive "ATI

15:42:14.685 -> SIM800 R14.18
15:42:14.685 -> "
15:42:14.685 -> SIM800L : initiateHTTP() - Support of SSL enabled
15:42:14.685 -> SIM800L : Send "AT+HTTPSSL=1"
15:42:14.717 -> SIM800L : End of transmission
15:42:14.717 -> SIM800L : Receive "AT+HTTPSSL=1

15:42:14.752 -> OK
15:42:14.752 -> "
15:42:14.752 -> SIM800L : Send "AT+HTTPACTION=0"
15:42:14.786 -> SIM800L : End of transmission
15:42:14.786 -> SIM800L : Receive "AT+HTTPACTION=0

15:42:14.786 -> OK
15:42:14.786 -> "
15:42:21.721 -> SIM800L : End of transmission
15:42:21.721 -> SIM800L : Receive "
15:42:21.721 -> +HTTPACTION: 0,200,59
15:42:21.721 -> "
15:42:21.721 -> SIM800L : doGet() - HTTP status 200
15:42:21.721 -> SIM800L : doGet() - Data size received of 59 bytes
15:42:21.721 -> SIM800L : Send "AT+HTTPREAD"
15:42:21.756 -> SIM800L : End of transmission
15:42:21.788 -> SIM800L : Receive "AT+HTTPREAD

15:42:21.788 -> +HTTPREAD: 59
15:42:21.822 -> "

When I use your example code though without any custom changes, everything works fine:

16:06:54.253 -> SIM800L : Reset
16:06:56.253 -> SIM800L : Prepare internal buffer of 200 bytes
16:06:56.253 -> SIM800L : Prepare reception buffer of 512 bytes
16:06:56.253 -> SIM800L : Send "AT"
16:07:01.239 -> SIM800L : Receive timeout
16:07:01.239 -> Problem to initialize AT command, retry in 1 sec
16:07:02.252 -> SIM800L : Send "AT"
16:07:02.252 -> SIM800L : End of transmission
16:07:02.252 -> SIM800L : Receive "AT

16:07:02.252 -> OK
16:07:02.252 -> "
16:07:02.286 -> Setup Complete!
16:07:02.286 -> SIM800L : Send "AT+CSQ"
16:07:02.286 -> SIM800L : End of transmission
16:07:02.321 -> SIM800L : Receive "AT+CSQ

16:07:02.321 -> +CSQ: 0,0
16:07:02.321 -> "
16:07:03.302 -> SIM800L : Send "AT+CSQ"
16:07:03.335 -> SIM800L : End of transmission
16:07:03.335 -> SIM800L : Receive "AT+CSQ

16:07:03.335 -> +CSQ: 0,0
16:07:03.335 -> "
16:07:04.327 -> SIM800L : Send "AT+CSQ"
16:07:04.361 -> SIM800L : End of transmission
16:07:04.394 -> SIM800L : Receive "AT+CSQ

16:07:04.394 -> +CSQ: 15,0
16:07:04.394 -> "
16:07:04.394 -> Signal OK (strenght: 15)
16:07:05.378 -> SIM800L : Send "AT+CREG?"
16:07:05.414 -> SIM800L : End of transmission
16:07:05.414 -> SIM800L : Receive "AT+CREG?

16:07:05.447 -> +CREG: 0,2
16:07:05.447 -> "
16:07:06.429 -> SIM800L : Send "AT+CREG?"
16:07:06.463 -> SIM800L : End of transmission
16:07:06.463 -> SIM800L : Receive "AT+CREG?

16:07:06.463 -> +CREG: 0,1
16:07:06.463 -> "
16:07:06.463 -> Network registration OK
16:07:07.481 -> SIM800L : Send "AT+SAPBR=3,1,"Contype","GPRS""
16:07:07.548 -> SIM800L : End of transmission
16:07:07.548 -> SIM800L : Receive "AT+SAPBR=3,1,"Contype","GPRS"

16:07:07.548 -> OK
16:07:07.548 -> "
16:07:07.548 -> SIM800L : Send "AT+SAPBR=3,1,"APN","internet.telekom""
16:07:07.650 -> SIM800L : End of transmission
16:07:07.650 -> SIM800L : Receive "AT+SAPBR=3,1,"APN","internet.telekom"

16:07:07.650 -> OK
16:07:07.650 -> "
16:07:07.650 -> GPRS config OK
16:07:08.633 -> SIM800L : Send "AT+SAPBR=1,1"
16:07:09.389 -> SIM800L : End of transmission
16:07:09.389 -> SIM800L : Receive "AT+SAPBR=1,1

16:07:09.422 -> OK
16:07:09.422 -> "
16:07:09.422 -> GPRS connected !
16:07:09.422 -> Start HTTP GET...
16:07:09.422 -> SIM800L : Send "AT+HTTPINIT"
16:07:09.456 -> SIM800L : End of transmission
16:07:09.456 -> SIM800L : Receive "AT+HTTPINIT

16:07:09.456 -> OK
16:07:09.456 -> "
16:07:09.456 -> SIM800L : Send "AT+HTTPPARA="CID",1"
16:07:09.490 -> SIM800L : End of transmission
16:07:09.524 -> SIM800L : Receive "AT+HTTPPARA="CID",1

16:07:09.524 -> OK
16:07:09.524 -> "
16:07:09.524 -> SIM800L : Send "AT+HTTPPARA="URL","https://postman-echo.com/get?foo1=bar1&foo2=bar2""
16:07:09.660 -> SIM800L : End of transmission
16:07:09.660 -> SIM800L : Receive "AT+HTTPPARA="URL","https://postman-echo.com/get?foo1=bar1&foo2=bar2"

16:07:09.694 -> OK
16:07:09.694 -> "
16:07:09.694 -> SIM800L : Send "ATI"
16:07:09.728 -> SIM800L : End of transmission
16:07:09.728 -> SIM800L : Receive "ATI

16:07:09.728 -> SIM800 R14.18
16:07:09.728 -> "
16:07:09.728 -> SIM800L : initiateHTTP() - Support of SSL enabled
16:07:09.728 -> SIM800L : Send "AT+HTTPSSL=1"
16:07:09.762 -> SIM800L : End of transmission
16:07:09.762 -> SIM800L : Receive "AT+HTTPSSL=1

16:07:09.762 -> OK
16:07:09.762 -> "
16:07:09.762 -> SIM800L : Send "AT+HTTPACTION=0"
16:07:09.797 -> SIM800L : End of transmission
16:07:09.830 -> SIM800L : Receive "AT+HTTPACTION=0

16:07:09.830 -> OK
16:07:09.830 -> "
16:07:16.315 -> SIM800L : End of transmission
16:07:16.315 -> SIM800L : Receive "
16:07:16.315 -> +HTTPACTION: 0,200,291
16:07:16.315 -> "
16:07:16.315 -> SIM800L : doGet() - HTTP status 200
16:07:16.349 -> SIM800L : doGet() - Data size received of 291 bytes
16:07:16.349 -> SIM800L : Send "AT+HTTPREAD"
16:07:16.383 -> SIM800L : End of transmission
16:07:16.417 -> SIM800L : Receive "AT+HTTPREAD

16:07:16.417 -> +HTTPREAD: 291
16:07:16.417 -> "
16:07:16.689 -> SIM800L : End of transmission
16:07:16.689 -> SIM800L : Receive "
16:07:16.689 -> OK
16:07:16.689 -> "
16:07:16.689 -> SIM800L : doGet() - Received from HTTP GET : {"args":{"foo1":"bar1","foo2":"bar2"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f199993-bfa167b0750c371416e9e0d5","accept":"*/*","user-agent":"SIMCOM_MODULE"},"url":"https://postman-echo.com/get?foo1=bar1&foo2=bar2"}
16:07:16.723 -> SIM800L : Send "AT+HTTPTERM"
16:07:16.757 -> SIM800L : End of transmission
16:07:16.757 -> SIM800L : Receive "AT+HTTPTERM

16:07:16.757 -> OK
16:07:16.757 -> "
16:07:16.757 -> HTTP GET successful (35 bytes)
16:07:16.757 -> Received : {"args":{"foo1":"bar1","foo2":"bar2"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f199993-bfa167b0750c371416e9e0d5","accept":"*/*","user-agent":"SIMCOM_MODULE"},"url":"https://postman-echo.com/get?foo1=bar1&foo2=bar2"}
16:07:16.792 -> SIM800L : Send "AT+SAPBR=0,1"
16:07:16.999 -> SIM800L : End of transmission
16:07:16.999 -> SIM800L : Receive "AT+SAPBR=0,1

16:07:16.999 -> OK
16:07:16.999 -> "
16:07:16.999 -> GPRS disconnected !
16:07:16.999 -> SIM800L : Send "AT+CFUN?"
16:07:17.033 -> SIM800L : End of transmission
16:07:17.033 -> SIM800L : Receive "AT+CFUN?

16:07:17.067 -> +CFUN: 1
16:07:17.067 -> "
16:07:17.067 -> SIM800L : Send "AT+CFUN=0"
16:07:17.067 -> SIM800L : Send "AT+CFUN?"
16:07:17.101 -> SIM800L : End of transmission
16:07:17.101 -> SIM800L : Receive "AT+CFUN=0
AT+CFUN?

16:07:17.135 -> +CFUN: 0
16:07:17.135 -> "
16:07:17.135 -> Module in low power mode

I've looked through your SIM800L.cpp file, but couldnt really find a solution. Maybe it's related to this bit, but I'm not sure:

// Read number of bytes defined in the dataSize
    for(uint16_t i = 0; i < dataSize && i < recvBufferSize; i++) {
      while(!stream->available());
      if(stream->available()) {
        // Load the next char
        recvBuffer[i] = stream->read();
        // If the character is CR or LF, ignore it (it's probably part of the module communication schema)
        if((recvBuffer[i] == '\r') || (recvBuffer[i] == '\n')) {
          i--;
        }
      }
    }

I've thought about removing this bit, but I don't know if it's necessary for the rest of the code. It looks like it's only important, when you are interested in seeing, what you receive after a successfull data transmission. Please correct me, if I'm wrong. I'm only really interested in the 200 response. In the case, I don't get 200 back, I know I have to repeat my GET request, because I want the data on my database.

These modules are tricky and I appreciate the work you've put into that driver.

Kind regards

SciWax

HTTP error 408 - problem with power supply during the transmission

Hello ostaquet,

Im having a problem with ur driver, all the time i have an error 408 when i try to Post to my server dat its located into my laptop, i configure the server and my router and i can get the url outside my network, i try with my phone and with other laptop with postman, all work fine, but when i used sim800l all the time i have an error 408.

This is my code:

#include <SoftwareSerial.h>
/*SIM 800L**************************************************************/
#include "SIM800L.h"
#define SIM800_TX_PIN 11
#define SIM800_RX_PIN 10
#define SIM800_RST_PIN 6
static const int ledPINSIM800 = 52;
static const char APN[] = "em";
static const char URL[] = "http://1xx.xx.xx.xx:7313/getSIM800L";
static const char CONTENT_TYPE[] = "application/json";
const char PAYLOAD[] = "{\"name\": \"morpheus\", \"job\": \"leader\"}";
SIM800L *sim800l;

void setup()
{
  // Initialize Serial Monitor for debugging
  Serial.begin(9600);
  while (!Serial)
    ;
  // Setup module for SIM800 communication
   setupSIM800();
  
  // Setup module for DHT
  //setupDHT();
  // Setup module for GPS
  //setupGPS();
}
void loop()
{

  if(isGPRSconnect(false)){
Serial.println("GPRS conectado");
  Serial.println("Esperamos 5 segundos");
  delay(5000);
  Serial.println("Hecho");
  Serial.println("Esperamos 20 segundos post");
  postData();
  Serial.println("20 segundos pasados");
  resetSIM();
  }
  
}
void setupSIM800()
{
  //pinMode(ledPINSIM800 , OUTPUT);
  // Wait until the module is ready to accept AT commands
  initSim800();
  // Wait for the GSM signal
  initSignal();
  // Wait for operator network registration (national or roaming network)
  initOpertatorNetwork();
  // Setup APN for GPRS configuration
  initGPRS();
  //digitalWrite(ledPINSIM800 , HIGH);   // poner el Pin en HIGH
}
void initSim800()
{
  // Initialize a SoftwareSerial
  SoftwareSerial *serial = new SoftwareSerial(SIM800_TX_PIN, SIM800_RX_PIN);
  serial->begin(9600);
  delay(1000);
  // Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
  sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 1024, 1024);
  sim800l->reset();
  while (!sim800l->isReady())
  {
    Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
    delay(1000);
  }
  Serial.println(F("Setup Complete!"));
}
void initSignal()
{
  uint8_t signal = sim800l->getSignal();
  while (signal <= 0)
  {
    delay(1000);
    signal = sim800l->getSignal();
  }
  Serial.print(F("Signal OK (strenght: "));
  Serial.print(signal);
  Serial.println(F(")"));
  delay(1000);
}
void initOpertatorNetwork()
{
  NetworkRegistration network = sim800l->getRegistrationStatus();
  while (network != REGISTERED_HOME && network != REGISTERED_ROAMING )
  {
    delay(5000);
    network = sim800l->getRegistrationStatus();
  }
  Serial.print(F("NETWORK OK"));
  

}
void initGPRS()
{
  bool success = sim800l->setupGPRS(APN);
  while (!success)
  {
    success = sim800l->setupGPRS(APN);
    delay(5000);
  }
  Serial.println(F("GPRS config OK"));
}
bool isGPRSconnect(bool connected)
{
  for (uint8_t i = 0; i < 10 && !connected; i++)
  {
    delay(1000);
    connected = sim800l->connectGPRS();
  }
  return connected;
}
void startDisconnectGPRS(bool connected)
{
  bool disconnected = sim800l->disconnectGPRS();
  for (uint8_t i = 0; i < 5 && !connected; i++)
  {
    delay(1000);
    disconnected = sim800l->disconnectGPRS();
  }

  if (disconnected)
  {
    Serial.println(F("GPRS disconnected !"));
  }
  else
  {
    Serial.println(F("GPRS still connected !"));
  }
}
void postData()
{
  Serial.println(F("Start HTTP POST..."));
  uint16_t rc = sim800l->doPost(URL, CONTENT_TYPE, PAYLOAD, 20000, 20000);
  if (rc == 200)
  {
    // Success, output the data received on the serial
    Serial.print(F("HTTP POST successful ("));
    Serial.print(sim800l->getDataSizeReceived());
    Serial.println(F(" bytes)"));
    Serial.print(F("Received : "));
    Serial.println(sim800l->getDataReceived());
  }
  else
  {
    // Failed...
    Serial.print(F("HTTP POST error "));
    Serial.println(rc);
  }
}
void resetSIM()
{
    sim800l->reset();
    delay(5000);
    setupSIM800();

}
void goLowModeSIM()
{
  sim800l->setPowerMode(MINIMUM);
}
void goHighModeSIM(){
  sim800l->setPowerMode(NORMAL);
}

Support other modules e.g. SIM7070G or SIM7600E

Hi there,

First of all, great library!

Currently im working with a sim800L but Im upgrading the module to a different one SIM7070G or SIM7600E. Does the library also support other modules other than the SIM800L?

let me know.

Issue with custom url with GET request

hey , I am using the lib for sending data over http it was successful with your example ling i.e https://postman-echo.com/get?foo1=bar1&foo2=bar2. but I am unable to post to my custom provided url which is working on postman and I am able to open it on browser.
since today morning the api used by your example isn't working for me.

Error code I am receiving : 400 , 408 and 601

please let me know anything further needed from my side.

I would really appreciate your help.

Thanks in advance.

HTTP GET error 701

Hello, i hope i can describe my problem well enough:

I use the example HTTP GET script to write data to my website (PHP $_GET ...). Every time i start my script the first pass is successful with Error 705 (it sends the data and does not hand back a site). But now on the next passes i get the Error 701.
My program:

...
void setup(){
   setupModul();
}

void loop(){
messure data ...
setPowerMode NORMAL ...
GPRS connect ...
doGET(xyz) ...
setPowerMode MINIMUM;
wait for 30 seconds ...
}

Did I forget to activate something or do I have to clear the cache somehow?
I hope you understand my problem.
Thanks in advance

Felix

sim800l->doPost Limit Size

Hi.

i use this library and it works fine. the function of sim800l->doPost is using data type char for sending the payload, and in esp32 limit char is 4000bytes, can I send 25.000 bytes of data json in one post, or I must split the json to post the data,

I was using String type data for handle the 25.000 bytes of data, but it can't fit to functions sim800l->doPost.

maybe you have a suggestion
Thanks :D

Command echo

My SIM800L module had command output disabled on "AT" returns "OK" instead of "AT\nOK"

So after isReady you should set "ATE1&W" to enable command echo

I mention it for other users that may have similar problem

WolfSSL for SIM800L

Dear ostaquet,

first thanks for your library. I have a problem with the security in regards of a modern backend of a server, which you've mentioned here: https://github.com/ostaquet/Arduino-SIM800L-driver#security-concerns

I get the error 606, when I want to send my data to a webserver (Putting all my data into an URL and trying to write them with a php-script into a database). That technique works with another webserver, but not with a certain one I have to use. I've potentially found information about how to get the WolfSSL library on the Arduino. I guess I also have to put a new certificate on the SIM800L? There is some information about how to do it potentially, but which certificate do I have to use? One which is provided by WolfSSL I guess?

Did you personally already try to make a SIM800L work with WolfSSL, when 606 or 605 pops up?

I've got the version:

14:19:22.162 -> AT+GSV

14:19:22.196 -> SIMCOM_Ltd
14:19:22.196 -> SIMCOM_SIM800L
14:19:22.196 -> Revision:1418B04SIM800L24

Unable to compile in Arduino IDE for ESP8266

Hi!
Using the arduino compiler I am not able to compile the example sketches. I have attached below the error message. The library looks pretty well written, certainly a lot better than my own mess, so I would love to use it.

Arduino:1.8.9 (Windows 10), Board:"NodeMCU 1.0 (ESP-12E Module), 160 MHz, Flash, Disabled, Basic SSL ciphers (lower ROM use), 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 256000"

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp: In constructor 'SIM800L::SIM800L(int, int, int, unsigned int, unsigned int, bool)':

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:35:45: error: invalid conversion from 'void*' to 'char*' [-fpermissive]

   internalBuffer = malloc(internalBufferSize);

                                             ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:43:37: error: invalid conversion from 'void*' to 'char*' [-fpermissive]

   recvBuffer = malloc(recvBufferSize);

                                     ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp: In member function 'int SIM800L::doPost(const char*, const char*, char*, unsigned int, unsigned int)':

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:65:32: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   int initRC = initiateHTTP(url);

                                ^

In file included from C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:8:0:

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.h:69:9: error:   initializing argument 1 of 'int SIM800L::initiateHTTP(char*)' [-fpermissive]

     int initiateHTTP(char* url);

         ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:71:54: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   sendCommand("AT+HTTPPARA=\"CONTENT\",", contentType);

                                                      ^

In file included from C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:8:0:

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.h:54:10: error:   initializing argument 2 of 'void SIM800L::sendCommand(char*, char*)' [-fpermissive]

     void sendCommand(char* command, char* parameter);

          ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:78:27: error: invalid conversion from 'void*' to 'char*' [-fpermissive]

   char* tmpBuf = malloc(30);

                           ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:158:27: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

         if((recvBuffer == '\r') || (recvBuffer == '\n')) {

                           ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:158:51: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

         if((recvBuffer == '\r') || (recvBuffer == '\n')) {

                                                   ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp: In member function 'int SIM800L::doGet(const char*, unsigned int)':

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:203:32: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   int initRC = initiateHTTP(url);

                                ^

In file included from C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:8:0:

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.h:69:9: error:   initializing argument 1 of 'int SIM800L::initiateHTTP(char*)' [-fpermissive]

     int initiateHTTP(char* url);

         ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:268:27: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

         if((recvBuffer == '\r') || (recvBuffer == '\n')) {

                           ^

C:\Users\user\Documents\Arduino\libraries\Arduino-SIM800L-driver-master\SIM800L.cpp:268:51: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

         if((recvBuffer == '\r') || (recvBuffer == '\n')) {

                                                   ^

Meerdere bibliotheken gevonden voor "SoftwareSerial.h"
Gebruikt: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SoftwareSerial
Niet gebruikt: C:\Users\user\Documents\Arduino\libraries\EspSoftwareSerial
exit status 1
Fout bij het compileren voor board NodeMCU 1.0 (ESP-12E Module)

Dit rapport zou meer informatie bevatten met
"Uitgebreide uitvoer weergeven tijden compilatie"
optie aan in Bestand -> Voorkeuren.

HTTP SSL error on SIM800L R13.08

Hi Olivier, I also tried your library with a SIM800L chip.

Specifically the chips is: SIM800L V2 EVB chip.https://www.ebay.com/p/23023423047

I am trying to send data via Software Serial to a server with https requests, and it returned a 702 error. See details below.

Also does the SIM800L chip support SSL? When I talk to the chip with "AT" commands and issue the command : AT+HTTPSSL=? it returns an "ERROR". It does not exist?

Do AT+HTTPSSL commands exist on the SIM800L V2 chip?

I used the code from your existing library examples. " https_get_softserial".

The reponse I get:

Setup Complete!
Signal OK (strenght: 12)
Network registration OK
GPRS config OK
GPRS connected !
Start HTTP GET...
HTTP GET error 702
GPRS disconnected !
Module in low power mode

Any help appreciated Olivier. Thank you

See the screen shot below:
Screenshot 2020-05-01 at 11 46 32
error.

Originally posted by @chiggs002 in #9 (comment)

Multiline responses from server suspends doGet() and doPost() procedures

I tried examples from the library. I want to use it in a simple IoT device.
Everything works fine as long as the server sends a one-line response.
However, if it sends more lines, the program stops working after the AT_CMD_HTTPREAD command.

I found the problem in lines :
// If the character is CR or LF, ignore it (it's probably part of the module communication schema)
if((recvBuffer[i] == '\r') || (recvBuffer[i] == '\n')) {
i--;
}

index decrementing causing that index never reach dataSize value and program stay cycling in
while(!stream->available());
that is empty

After comenting these lines works all right. I think is not need to remove these chars or empty lines. They can be removed later if needed.
Otherwise nice work. Thank you.

Inherit from Client class

I was wondering if it was possible to make SIM800L inherit from the Arduino Client class. That way it would be possible to use SSLClient to have a more secure SSL implementation.

I have not done any project with the SIM800L yet, but was wondering if you @ostaquet think it would be feasible to do something like this?

If yes, I would be happy to help implement this 'feature'

Newbie: 'setupModule' was not declared in this scope

I'm newbie from Vietnam. I would like to setup an irrigation project with Arduino Uno and module SIM800A, the users will control via website (internet). First I am test module with Uno through the AT command -> ok.
Then I downloaded the SIM800L library, and testing with the HTTPS_GET_SoftSerial example (code). I have 02 issues:

  • sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512); --> I don't know where SIM800_RST_PIN on my Module SIM800A?
  • After copying the code, I try to compile but it announce:" Arduino: 1.8.10 (Windows 7), Board: "Arduino Uno"
    C:\Users\Vaio\Documents\Innovation_club\Iot\Irrigration_System\Arduino\sketch_oct15a\GMS_V1\GMS_V1.ino: In function 'void setup()':
    GMS_V1:30:3: error: 'setupModule' was not declared in this scope
    setupModule();
    Multiple libraries were found for "SoftwareSerial.h"
    Used: C:\Users\Vaio\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\SoftwareSerial
    Multiple libraries were found for "SIM800L.h"
    Used: C:\Users\Vaio\Documents\Arduino\libraries\Arduino-SIM800L-driver-1.8.0
    exit status 1
    'setupModule' was not declared in this scope
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

Could you help us to solve this? Thank you so much

Communication problem with another module

Hello everyone,

So i want to make a car tracking system and i am using atmega328P as my controller. But i have communication issues with my modules. Let me show what i want to combine;

#include "SIM800L.h"

#define SIM800_RST_PIN 6
#define gpsPort Serial

const char APN[] = "internet";
const char URL[] = "http://ptsv2.com/t/duimr-1601369993/post";
const char CONTENT_TYPE[] = "application/json";
const char PAYLOAD[] = "{\"name\": \"morpheus\", \"job\": \"leader\"}";

SIM800L* sim800l;

void setup() {
  Serial.begin(115200);
  while(!Serial);

  gpsPort.begin(9600);
  delay(200);
   
  // Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
  sim800l = new SIM800L((Stream *)&gpsPort, SIM800_RST_PIN, 200, 512);

  setupModule();
}
 
void loop() {
  // Establish GPRS connectivity (5 trials)
  bool connected = false;
  for(uint8_t i = 0; i < 5 && !connected; i++) {
    delay(1000);
    connected = sim800l->connectGPRS();
  }

  // Check if connected, if not reset the module and setup the config again
  if(connected) {
    Serial.println(F("GPRS connected !"));
  } else {
    Serial.println(F("GPRS not connected !"));
    Serial.println(F("Reset the module."));
    sim800l->reset();
    setupModule();
    return;
  }

  Serial.println(F("Start HTTP POST..."));

  // Do HTTP POST communication with 10s for the timeout (read and write)
  uint16_t rc = sim800l->doPost(URL, CONTENT_TYPE, PAYLOAD, 10000, 10000);
   if(rc == 200) {
    // Success, output the data received on the serial
    Serial.print(F("HTTP POST successful ("));
    Serial.print(sim800l->getDataSizeReceived());
    Serial.println(F(" bytes)"));
    Serial.print(F("Received : "));
    Serial.println(sim800l->getDataReceived());
  } else {
    // Failed...
    Serial.print(F("HTTP POST error "));
    Serial.println(rc);
  }

  // Close GPRS connectivity (5 trials)
  bool disconnected = sim800l->disconnectGPRS();
  for(uint8_t i = 0; i < 5 && !connected; i++) {
    delay(1000);
    disconnected = sim800l->disconnectGPRS();
  }
  
  if(disconnected) {
    Serial.println(F("GPRS disconnected !"));
  } else {
    Serial.println(F("GPRS still connected !"));
  }

  // Go into low power mode
  bool lowPowerMode = sim800l->setPowerMode(MINIMUM);
  if(lowPowerMode) {
    Serial.println(F("Module in low power mode"));
  } else {
    Serial.println(F("Failed to switch module to low power mode"));
  }

  // End of program... wait...
  while(1);
}

void setupModule() {
    // Wait until the module is ready to accept AT commands
  while(!sim800l->isReady()) {
    Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
    delay(1000);
  }
  Serial.println(F("Setup Complete!"));

  // Wait for the GSM signal
  uint8_t signal = sim800l->getSignal();
  while(signal <= 0) {
    delay(1000);
    signal = sim800l->getSignal();
  }
  Serial.print(F("Signal OK (strenght: "));
  Serial.print(signal);
  Serial.println(F(")"));
  delay(1000);

  // Wait for operator network registration (national or roaming network)
  NetworkRegistration network = sim800l->getRegistrationStatus();
  while(network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
    delay(1000);
    network = sim800l->getRegistrationStatus();
  }
  Serial.println(F("Network registration OK"));
  delay(1000);

  // Setup APN for GPRS configuration
  bool success = sim800l->setupGPRS(APN);
  while(!success) {
    success = sim800l->setupGPRS(APN);
    delay(5000);
  }
  Serial.println(F("GPRS config OK"));
}

This is simple hardware post from this repository.

My gps code;

#include <NMEAGPS.h>
#include <GPSport.h>

NMEAGPS  gps; // This parses the GPS characters
gps_fix  fix; // This holds on to the latest values

void setup()
{
  Serial.begin(9600);
  while (!Serial);
  gpsPort.begin(9600);
}

//--------------------------

void loop()
{
  while (gps.available( gpsPort )) {
    fix = gps.read();

    Serial.print( F("Location: ") );
    if (fix.valid.location) {
      Serial.print( fix.latitude(), 6 );
      Serial.print( ',' );
      Serial.print( fix.longitude(), 6 );
    }

    Serial.print( F(", Altitude: ") );
    if (fix.valid.altitude)
      Serial.print( fix.altitude() );

    Serial.println();
  }
}// time will be added

//knots = 1.8*km

I want to combine this 2 codes. I am using NeoGPS library with using AltsoftSerial. Please dont too harsh on me, imma newbie :/

Tracker connections

You can see the connections here but imagine reverse of the 8-9 and rx-tx pins.

Any help will be appreciated.

Watchdog triggered during usage on ESP8266

Now getting:


wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
Test sketch

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
Test sketch

Hi I just tried your latest update. It compiles fine now! just getting a watchdog reset. This is a thing related to the wifi capabilities of the ESP. If you do not call yield() or delay() for 3 (?) seconds the ESP will reset.
This is from the HTTPS_GET test sketch, adding delay or yield in a loop should be an easy fix.

Originally posted by @Bartvelp in #2 (comment)

MQTT protocol implementation

Hi Olive! Yes! Is compiling with no problem! Amazing!

Now the issue is my SIM800L hahaha, but i will figure out what's is going on!

Again, thank you very much mate!

Just a suggestion: Could you try to work with MQTT protocol?

Cheers!

Originally posted by @grfbr in #3 (comment)

get and post in single code is not working

i have written a code to get and post some data when i comment either get or post related functions indivdually they were working good but when i run both functions one after other code stucks at HTTPACTION0 in get function forever can i get some directions on this

Thank you

getSimCardNumber into a variable

Hi there, I'm trying to do the following:

void generatePayload(char * coordinates, char * payload)
{
  sprintf(payload, "{\"sn\":\"%s\", ", getImeiNum());
  ...
}
char* getImeiNum()
{
  char* imei = sim->getSimCardNumber();
  delay(100);
  return imei;
}

And it does execute the command on the module and return the ID but when I print the payload it is blank

Generating payload
SIM800L : Send "AT+CCID"
SIM800L : End of transmission
SIM800L : Receive "AT+CCID
89354600000001419885

{"sn":"", 

I hope you can help me. Thank you

how send var using get?

For example send 'acak'

 gsm.println("AT+HTTPINIT");
  toSerial();
  delay(1000);
  int acak = random(11111, 99999);

  //masukan url website
  gsm.print("AT+HTTPPARA=\"URL\",\"http://iot.mywebsite.com/sim800/get.php?val=" + String(acak) + "&");
  gsm.println("\"");
  toSerial();
  delay(1000);

HTTPS_POST_SoftSerial.ino debug enabled mode output gets stuck

Dear ostaquet,

I've wanted to try out your POST request example and encountered an issue, which only comes up, when I try to see more information through the debug mode.

I've only changed my pins and my APN:

#define SIM800_TX_PIN 12
#define SIM800_RX_PIN 13
#define SIM800_RST_PIN 2

const char APN[] = "Internet.telekom";

when I let the default version of the script run:

// Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
  sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512);

The output:

19:11:20.696 -> Problem to initialize AT command, retry in 1 sec
19:11:21.720 -> Setup Complete!
19:11:23.826 -> Signal OK (strenght: 18)
19:11:24.878 -> Network registration OK
19:11:26.031 -> GPRS config OK
19:11:27.964 -> GPRS connected !
19:11:27.964 -> Start HTTP POST...
19:11:35.053 -> HTTP POST successful (150 bytes)
19:11:35.053 -> Received : {"args":{},"data":{"name":"morpheus","job":"leader"},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5f1b1647-7261b4780fcf68c4762d1724","content-length":"37","accept":"*/*","content-type":"application/json","user-agent":"SIMCOM_MODULE"},"json":{"name":"morpheus","job":"leader"},"url":"https://postman-echo.com/post"}
19:11:35.293 -> GPRS disconnected !
19:11:35.463 -> Module in low power mode

If I put on the debug output in the same script the output gets stuck early on :

// Equivalent line with the debug enabled on the Serial
  sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);
19:12:45.050 -> SIM800L : Reset
19:12:47.050 -> SIM800L : Prepare internal buffer of 200 bytes
19:12:47.050 -> SIM800L : Prepare reception buffer of 512 bytes
19:12:47.050 -> SIM800L : Send "AT"

How to comunicate with modul manualy ?

Hi Olivier.
I would like to ask you one question. I want use your library for GPRS communication because for me is this library the best but I need read and send SMS as well.
I am trying comunicate manualy with modul over you library but I do not know how to send AT command and then read answer from buffer. Can you point me please?

Thanks

Dynamic Allocation of data to the payload(in this case, a json string)

I am reading sensor data and it is being periodically posted to a server after 15 minutes. The challenge I am encountering is how to dynamically initialise a JSON object to the PAYLOAD considering the PAYLOAD has to be initialised during setup and it is declared as a const char array.

Access to low level functions to communicate with the SIM800L module

Hello Ostaquet, I would like to make use of the low-level functions to be able to consult the location provided by the sim with the command AT + CIPGSMLOC = 1,1 or with the command AT + CLBS = 1,1.

I see that they are in the .cpp of the library but when implementing them it does not work for me, in the following image i show you what's says the arduino IDE

On the other hand, if I want to use the library and I have a PHP base application, can I use the post you have there or would it only be useful for Postman?

THANKS !

image

hang when try connectGPRS (AT+SAPBR=1,1)

If I send the command manually:
"AT+SAPBR=1,1"

works fine,
but when i send command:

connected = sim800l->connectGPRS();

the data print in serial monitor stuck or hang forever

HTTP GET time out

The HTTP GET may suspend the application, If there is a problem with the HTTP page(for example bad ending),
So, is it possible to define HTTP GET time out in order to prevent program suspension?

Problem with reading SMS

I am using the example "HTTPS_GET_SoftSerial" to read data from a server and it works fine.
But when I try to read the SMS message, sending the following configuration beforehand, the SMS bytes come in with problems.

void configGSM() {
   Sim800l.print("AT+CMGF=1\n;AT+CNMI=2,2,0,0,0\n;ATX4\n;AT+COLP=1\n"); 
}

If I use only the SMS reading code, it will also work well.

The curious thing is that the HTTPS routine does not run in my code. I put the following line:

if (false) {uint16_t rc = sim800l-> doGet (URL, 10000); }

That is, the interference between functions occurs only because the code is compiled.

void ReadGSM()
{
  static String textoRec = "";
  static unsigned long delay1 = 0;
  static int count=0;  
  static unsigned char buffer[200];
  
delay(10);
  if (Sim800l.available()) {            
 
     while(Sim800l.available()) {         
   
        buffer[count++] = Sim800l.read();     
        if(count == 200)break;
     }

     textoRec += (char*)buffer;
     delay1   = millis();
     
     for (int i=0; i<count; i++) {
         buffer[i]=NULL;
     } 
     count = 0;                       
  }


  if ( ((millis() - delay1) > 100) && textoRec != "" ) {
    Serial.print("GSMRead = ");Serial.println(textoRec);

     if ( textoRec.substring(2,7) == "+CMT:" ) {SMS_Received = true; }
     

     if (SMS_Received) 
     {
            
        telefoneSMS = "";
        dataHoraSMS = "";
        mensagemSMS = "";

        byte linha = 0;  
        byte aspas = 0;
        for (int nL=1; nL < textoRec.length(); nL++) 
        {

            if (textoRec.charAt(nL) == '"') {
               aspas++;
               continue;
            }                        
          
            if ( (linha == 1) && (aspas == 1) ) {
               telefoneSMS += textoRec.charAt(nL);
            }

            if ( (linha == 1) && (aspas == 5) ) {
               dataHoraSMS += textoRec.charAt(nL);
            }

            if ( linha == 2 ) {
               mensagemSMS += textoRec.charAt(nL);
            }

            if (textoRec.substring(nL - 1, nL + 1) == "\r\n") {
               linha++;
            }
        }
     } 
     
     else 
     {
       comandoGSM = textoRec;
       comandoGSM.trim();
       Serial.print("comandoGSM = ");Serial.println(comandoGSM);
       if ( comandoGSM == "RING"  )       {Call_Received = true; Call_Finished = false; }
       if ( comandoGSM == "NO CARRIER"  ) {Call_Finished = true; }


       
     }
     
     textoRec = "";  
  }     
}

Gprs connection credentials

Hey, I'm playing with the library and I can't connect because there is missing 2 values in the library, my isp is using apn, user and password
My question is how I can add USR and PWD to gprs connection ?
Thanks

Relatively smallest internal buffer size for get

This is not issue and rather a question. Apparently, the doGet function uses a pointer instead of copying the entire field. For doPost, it is necessary to set a large enough internal buffer for Url. What is the smallest internal buffer size when using doGet ()? The default value in the constructor is 128 but that is quite a lot for me. Is it possible to reduce this value by half, for example, 64? Thanks!

Library working with TTGO T-Call ESP32 with SIM800 module

Hello
I'm trying your code HTTPS_POST_SoftSerial with an ESP32 with SIM800L embed (TTGO T-Call)
I set correctly my PINS and My APN
#define SIM800_TX_PIN 27
#define SIM800_RX_PIN 26
#define SIM800_RST_PIN 5
But I have always this error:
Problem to initialize AT command, retry in 1 sec
Have you suggestions for me?
Thanks

How to construct correct HTTP Headers for SIM800L-driver library

Dear Sir,

Please advise how to correctly construct headers which are consist from more than one parameter?

I'm trying to make GET request with two auth headers (X-Parse-Application-Id and X-Parse-REST-API-Key) to PARSE backend but getting 702 error. If I switch on extensive logging - getting the following error:

13:46:58.916 -> SIM800L : initiateHTTP() - Unable to define Headers
13:46:58.916 -> HTTP GET error 702

Now my string headers looks like this:

const char HEADERS_BACK4END[] = "X-Parse-Application-Id: MY_KEY_HERE\r\nX-Parse-REST-API-Key: MY_KEY_HERE";

I use \r\n to move second parameter on new line ))

Bet it is wrong, please advise correct way to send two headers to your library.
Thank you very much in advance

Dmitry

Getting 703 error, but still HTTP Post is successful if gprs is not disconnected.

Hi,
I was using the sim800L library and it was going all well. Since last week, the return value for most of the HTTP Posts (doPost) was 703 (Unable to initiate HTTP Post). However if I do not disconnect GPRS after the failure, or have a delay before disconnecting the GPRS, the HTTP Post is successful. (I am able to see the request in my AWS log).

Even though the Http post is initiated, I am getting 703 as the response to the doPost method. I tried changing the timeout to 10/15 seconds.

Add feature to get location information

Happy to find a maintained SIM800 lib. I just tried it and would like to ask if it would be possible to add some extra functionality, not sure if that is in the scope of this lib but I need a location information (GPRS not GPS) so I added the following function:

const char AT_CMD_CLBS[] PROGMEM = "AT+CLBS=1,1";	// Get approximate location
[...]
void SIM800L::getLocation(char* lat, char* lng) {
  sendCommand_P(AT_CMD_CLBS);
  if (readResponse(DEFAULT_TIMEOUT)) {
  
    int16_t idxLatStart = strIndex(internalBuffer, "+CLBS: ");
    int16_t idxLatEnd = strIndex(internalBuffer, ",", idxLatStart + 9);
    int16_t idxLngStart = idxLatEnd + 1;
    int16_t idxLngEnd = strIndex(internalBuffer, ",", idxLngStart);
    
    int index = 0;
    for(int16_t i = (idxLatStart + 9); i < (idxLatEnd); i++) {
	lat[index++] = internalBuffer[i];
    }
    lat[index] = '\0';
	
    index = 0;
    for(int16_t i = (idxLngStart); i < (idxLngEnd); i++) {
	lng[index++] = internalBuffer[i];
    }
    lng[index] = '\0';
  }
}

My c++ skills are quite poor so I believe it is not a candidate for a pull request, however maybe you could consider adding the location to status functions?

dtmf

Detection of DTMF tones - SIM800L module.

I get "OK" when I send 'AT+DDET=1,1000,1,1* ' over uart .
But it doesnt seem to detect anything afterwards.
Perhaps I am doing something wrong.
Would appreciate some feedback.

regards
Atul
ref : *SIM800 Series_AT Command Manual_V1.09

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.