[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=58Y36H29935PW&item_name=Support+me+to+continue+developing+features¤cy_code=EUR&source=url)
# Arduino SIM800L library
A smart HTTP & FTP library based on Seeeduino that implements the AT HTTP commands to perform GET and POST requests to a JSON API as well as FTP uploads.
## Support
* Your board has to support the standard SoftwareSerial library. It doesn't work with HardwareSerial based boards for the moment.
* The API response format has to be a valid JSON.
* The library has been tested against Arduino Uno and Arduino Nano.
## Instalation
Download the ZIP library and then import it: Sketch -> Include Library -> Add .ZIP Library ...
## Quick start!
How to do a GET request! :+1:
``` c++
unsigned int RX_PIN = 7;
unsigned int TX_PIN = 8;
unsigned int RST_PIN = 12;
const char BEARER[] PROGMEM = "gprs-service.com";
HTTP http(9600, RX_PIN, TX_PIN, RST_PIN);
http.connect(BEARER);
char response[256];
Result result = http.get("your.api.com", response);
Serial.println(response);
http.disconnect();
```
How to do a POST request! :+1:
``` c++
unsigned int RX_PIN = 7;
unsigned int TX_PIN = 8;
unsigned int RST_PIN = 12;
const char BEARER[] PROGMEM = "gprs-service.com";
HTTP http(9600, RX_PIN, TX_PIN, RST_PIN);
http.connect(BEARER);
char response[256];
Result result = http.post("your.api.com", "{\"date\":\"12345678\"}", response);
Serial.println(response);
http.disconnect();
```
How to do a FTP upload! :+1:
``` c++
unsigned int RX_PIN = 7;
unsigned int TX_PIN = 8;
unsigned int RST_PIN = 12;
const char BEARER[] PROGMEM = "gprs-service.com";
const char FTP_SERVER[] PROGMEM = "ftp.server";
const char FTP_USER[] PROGMEM = "user";
const char FTP_PASS[] PROGMEM = "pass";
FTP ftp(9600, RX_PIN, TX_PIN, RST_PIN);
ftp.putBegin(BEARER, "example.txt", FTP_SERVER, FTP_USER, FTP_PASS);
ftp.putWrite("hello!", sizeof("hello!"));
ftp.putEnd();
```
I suggest the [ArduinoJSON](https://github.com/bblanchon/ArduinoJson) library for parsing the JSON response, then you can play with the values easily.
## HTTP. 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).
## Development
- Lint: `cppcheck --enable=all .`
没有合适的资源?快使用搜索试试~ 我知道了~
ArduinoSIM800L:用于SIM800L的Arduino HTTP和FTP客户端SIM800板执行对JSON API的G...
共21个文件
h:11个
cpp:6个
ino:2个
需积分: 39 2 下载量 124 浏览量
2021-02-02
07:09:32
上传
评论
收藏 25KB ZIP 举报
温馨提示
ArduinoSIM800L:用于SIM800L的Arduino HTTP和FTP客户端SIM800板执行对JSON API的GET和POST请求以及FTP上传
资源详情
资源评论
资源推荐
收起资源包目录
ArduinoSIM800L-master.zip (21个子文件)
ArduinoSIM800L-master
Readme.md 3KB
src
GPRS.cpp 3KB
GPRS.h 1KB
Http.cpp 5KB
Ftp.cpp 5KB
Geo.cpp 1KB
Parser.h 1KB
Sim800.h 5KB
Geo.h 1KB
Ftp.h 2KB
Http.h 2KB
Sim800.cpp 5KB
Parser.cpp 2KB
Result.h 2KB
examples
utils
sensor.h 979B
logger.h 916B
valve.h 629B
arducam.h 3KB
HttpExample.ino 2KB
WeatherStationExample.ino 5KB
library.properties 448B
共 21 条
- 1
锦宣
- 粉丝: 18
- 资源: 4564
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0