Summary of Control your MKR1000 with aREST Framework
This article demonstrates how to control an Arduino MKR1000 remotely using the aREST framework and a RESTful interface. The project connects two LEDs to the board, allowing users to toggle them via web browser commands by sending specific HTTP requests to the device's IP address. It details the necessary software installations, code modifications for compatibility, and the sketch logic required to expose functions and handle incoming WiFi connections.
Parts used in MKR1000 Remote Control Project:
- Arduino MKR1000
- LED (generic)
- Resistor 220 ohm
- Jumper wires (generic)
- Arduino IDE
- Wifi101 library
- aREST library
You can control your MKR1000 remotely with a RESTFUL interface.

Things used in this project
Story
It would be nice to communicate with an Arduino thru RESTFUL interface and I found this aREST framework. As described on its website (arest.io), the aREST framework is a complete solution to build powerful RESTful applications based on the Arduino & the Raspberry Pi platforms. It can handle all kind of communications via Serial, WiFi, Ethernet, and much more.
In this project, I will show how to setup MKR1000 with 2 LEDs and you can control the LEDs via REST API.
Steps to setup the dev environment
1. Setup the MKR100 using this Getting Started guide.
2. Install Wifi101 library using Sketch > Include Library > Manage Libraries …menu. (Note: I am using Wifi101 version 0.9.0)
3. Install aREST library. (Note: I am using aREST version 2.1.1)
4 Make the following changes to aREST.h:
- Change
WiFi_htoWIFI_H - Change the following
void addToBuffer(float toAdd) {
char number[10];
dtostrf(toAdd, 5, 2, number);
addToBuffer(number);
}
to
void addToBuffer(float toAdd) {
char number[10];
sprintf(number, "%5.2f", toAdd);
addToBuffer(number);
}
5. Copy the sketch from the code section below.
6. Setup the board and LEDs.
7. Compile and upload the sketch.
About the sketch
Creating a WiFiServer instance listening to port 80:
WiFiServer restServer(80);
Setting the device ID and name:
// Give name and ID to device
rest.set_id("008");
rest.set_name("mighty_cat");
The loop() is simple, just listening to port 80 and handling incoming connection:
void loop() {
// Handle REST calls
WiFiClient client = restServer.available();
rest.handle(client);
}
Exposing the custom function ledControl(String) within setup():
// Function to be exposed
rest.function("led",ledControl);
This is the ledControl(String) function:
// Custom function accessible by the API
int ledControl(String command) {
Serial.println(command);
// Get state from command
int state = command.toInt();
digitalWrite(5,state);
return 1;
}
Finally the printWifiStatus() function:
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
IPAddress subnet = WiFi.subnetMask();
Serial.print("Netmask: ");
Serial.println(subnet);
IPAddress gateway = WiFi.gatewayIP();
Serial.print("Gateway: ");
Serial.println(gateway);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Running the sketch
Open the Serial Monitor using Tools > Serial Monitor menu and note down the IP address shown.

Display the device ID and name:

To turn on pin 5, type the following to the web browser:
http://<ip-address>/digital/5/1

To turn off, type
http://<ip-address>/digital/5/0

To turn on using exposed function, type
http://<ip-address>/led?params=1

To Find out More About aREST
Refer to the aREST Arduino library page on GitHub
Schematics
Code
Source : Control your MKR1000 with aREST Framework
- How do I setup the development environment for this project?
You must setup the MKR1000 using the Getting Started guide, install the Wifi101 library version 0.9.0, and install the aREST library version 2.1.1. - What changes need to be made to the aREST.h file?
You must change WiFi_h to WIFI_H and replace the dtostrf function with sprintf in the addToBuffer method. - How can I turn on pin 5 of the MKR1000?
Type http:///digital/5/1 into your web browser to turn on pin 5. - Does the project support turning off the LED via API?
Yes, you can type http:///digital/5/0 into the web browser to turn off the LED. - What is the best way to use the exposed ledControl function?
Type http:///led?params=1 into the web browser to turn on the LED using the exposed function. - How do I find the IP address needed for the API calls?
Open the Serial Monitor using the Tools > Serial Monitor menu and note down the IP address shown there. - Can I customize the device name and ID in the sketch?
Yes, you can set the device ID and name using rest.set_id("008") and rest.set_name("mighty_cat"). - Which port does the WiFiServer listen to for REST calls?
The WiFiServer instance listens to port 80 as defined by WiFiServer restServer(80).







