HTTP Request library for Arduino and the WiFi shield. I modified the original Ethernet-only version to use on Intel Edison, should work fine with other Arduino WiFi devices though.
I think aJSON would be really helpful to integrate as a next step.
Clone (or download and unzip) the repository to ~/Documents/Arduino/libraries
where ~/Documents/Arduino
is your sketchbook directory.
> cd ~/Documents/Arduino
> mkdir libraries
> cd libraries
> git clone https://github.com/rexstjohn/arduino-restclient.git RestClient
You need to have the WiFi
library already included.
#include <WiFi.h>
#include <SPI.h>
#include "RestClient.h"
Constructor to create an RestClient object to make requests against.
Use domain name and default to port 80, add your WiFi SSID and password:
RestClient client = RestClient("google.com", SSID, PW);
Sets up WiFiClient
using the provided SSID and PW
client.connect()
Note: you can have multiple RestClient objects but only need to call this once.
Note: if you have multiple Arduinos on the same network, you'll need to give each one a different mac address.
It just wraps the WiFiClient
call to begin
and connects.
All methods return an HTTP status code or 0 if there was an error.
Start making requests!
int statusCode = client.get("/"));
Pass in a string by reference for the response:
String response = "";
int statusCode = client.get("/", &response);
String response = "";
int statusCode = client.post("/", &response);
statusCode = client.post("/", "foo=bar");
response = "";
statusCode = client.post("/", "foo=bar", &response);
String response = "";
int statusCode = client.put("/", &response);
statusCode = client.put("/", "foo=bar");
response = "";
statusCode = client.put("/", "foo=bar", &response);
String response = "";
int statusCode = client.del("/", &response);