ostaquet / Arduino-SIM800L-driver

Arduino driver for GSM/GPRS module SIMCom SIM800L to make HTTP/S connections with GET and POST methods
MIT License
133 stars 61 forks source link
arduino arduino-driver arduino-library driver gprs gprssim800 http http-client https

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:

To know before starting...

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:

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