Simple REST calls with Arduino over WiFi
Just ported RestClient for Arduino to use WiFi instead of Ethernet. I specifically did this to make it easier for developers to use Intel Edison’s WiFi while doing REST API calls.
- intel-edison
- apis
Originally published at rexstjohn.com on August 11, 2015. Recovered from the Internet Archive.
Just ported RestClient for Arduino to use WiFi instead of Ethernet. I specifically did this to make it easier for developers to use Intel Edison’s WiFi while doing REST API calls.
I haven’t yet tested an integration but I believe aJSON or equivalent will be really useful for doing anything beyond very basic REST calls here. All I wanted was a way to make some basic REST calls with Edison over WiFi.
While I am short on time, if I get more time I might consider producing a version which support both WiFi and ethernet.
Installation
- In a terminal, browse to the directory in your OS where your Arduino IDE keeps it’s libraries (probably “/Documents/Arduino/libraries”)
- Run “git clone https://github.com/rexstjohn/arduino-restclient.git RestClient” to download the WiFi RestClient into your libraries
- Restart your Arduino IDE
- Use “File -> Examples -> RestClient -> simple_GET” to test it
/* RestClient simple GET request
*
* by Rex St John
*/
#include
#include
#include "RestClient.h"
char ssid[] = "YOUR_SSID"; // your network SSID (name)
char pass[] = "YOUR_WIFI_PW"; // your network password
char host[] = "jsonplaceholder.typicode.com"; // target for your REST queries
int status = WL_IDLE_STATUS; // the Wifi radio's status
// Create your WiFi RestClient, pass in the ssid and password.
RestClient client = RestClient(host, ssid, pass);
String response;
void setup() {
// Initiate Serial Connection
Serial.begin(9600);
Serial.println("Starting REST client over Wi-Fi");
if(client.connect() == WL_CONNECTED){
response = "";
int statusCode = client.get("/posts/1", &response);
Serial.print("Status code from server: ");
Serial.println(statusCode);
Serial.print("Response body from server: ");
Serial.println(response);
delay(1000);
}
}
void loop(){
//
}