Coder Social home page Coder Social logo

arduinosim800l's Introduction

Arduino SIM800L library

A smart HTTP library based on Seeeduino that implements the AT HTTP commands to perform GET and POST requests to a JSON API.

Support

  • Your board have to support the standard SoftwareSerial library. It doesn't work with HardwareSerial based boards for the moment.
  • The API response have to be a valid JSON.
  • The library has been tested again Arduino Uno and Arduino Nano

Instalation

Download the library and then import it.

Quick start!

Here's some code to perform a GET request! ๐Ÿ‘

unsigned int RX_PIN = 7;
unsigned int TX_PIN = 8;
unsigned int RST_PIN = 12;
HTTP http(9600, RX_PIN, TX_PIN, RST_PIN);
http.configureBearer("your.mobile.service.provider.apn");
http.connect();

char response[256];
Result result = http.get("your.api.com", response);

Serial.println(response);

http.disconnect();

Here's some code to perform a POST request! ๐Ÿ‘

unsigned int RX_PIN = 7;
unsigned int TX_PIN = 8;
unsigned int RST_PIN = 12;
HTTP http(9600, RX_PIN, TX_PIN, RST_PIN);
http.configureBearer("your.mobile.service.provider.apn");
http.connect();

char response[256];
Result result = http.post("your.api.com", "{\"date\":\"12345678\"}", response);

Serial.println(response);

http.disconnect();

I suggest the ArduinoJSON library for parsing the JSON response, then you can play with the values easily.

How it works?

In order to perform a request, the library follows these steps:

Configure Bearer:
  • AT+CREG? -> try until 0,1 (connected to the network)
  • AT+SAPBR=3,1,"Contype","GPRS" -> wait for OK
  • AT+SAPBR=3,1,"APN","movistar.es" -> wait for OK
  • AT+SAPBR=1,1 -> wait for OK
HTTP GET:
  • AT+HTTPINIT -> wait for OK
  • AT+HTTPPARA="CID",1 -> wait for OK
  • AT+HTTPPARA="URL","your.api.com"-> wait for OK
  • AT+HTTPSSL=0 -> wait for OK (1 when URL starts with "https://")
  • AT+HTTPACTION=0 -> wait for 200
  • AT+HTTPREAD -> read buffer and parse it
  • AT+HTTPTERM -> wait for OK
  • AT+SAPBR=0,1
HTTP POST:
  • AT+HTTPINIT -> wait for OK
  • AT+HTTPPARA="CID",1 -> wait for OK
  • AT+HTTPPARA="URL","your.api.com" -> wait for OK

For example, if we have this body: {"location_id": 238, "fill_percent": 90}

  • AT+HTTPPARA="CONTENT","application/json"
  • AT+HTTPDATA=strlen(body),10000 -> wait for DOWNLOAD, then write the body and wait 10000
  • AT+HTTPSSL=0 -> wait for OK (1 when URL starts with "https://")
  • AT+HTTPACTION=1 -> wait for ,200,
  • AT+HTTPREAD -> read buffer and parse it
  • AT+HTTPTERM -> wait for OK
  • AT+SAPBR=0,1

Future improvements

  • Support of HardwareSerial.
  • Support of more content types, not only JSON (application/json).

arduinosim800l's People

Contributors

carrascoacd avatar jaka87 avatar sandrocsimas avatar

Watchers

 avatar

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.