Skip to content

Commit

Permalink
added support for official Ethernet board
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoschwartz committed May 5, 2014
1 parent 0fd2c18 commit f6f909c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ A simple library that implements a REST API for Arduino. It is designed to be un

The library is at the moment compatible with the following Arduino boards: Uno, Mega, Due, Teensy 3.0.

For the HTTP part, the library is compatible with most CC3000 breakout boards, and was tested with the Adafruit CC3000 breakout board and the CC3000 WiFi shield. It was also tested with the Tiny Circuit WiFi shield (but in that case, you will have to change the pins configuration inside the example WiFi sketch. See the Tiny Circuit WiFi shield documentation for more details).
For the WiFi part, the library is compatible with most CC3000 breakout boards, and was tested with the Adafruit CC3000 breakout board and the CC3000 WiFi shield. It was also tested with the Tiny Circuit WiFi shield (but in that case, you will have to change the pins configuration inside the example WiFi sketch. See the Tiny Circuit WiFi shield documentation for more details).

For the Ethernet part, the library is compatible with the official Arduino Ethernet shield.

For the Serial part, it has been tested with the direct USB serial connection on an Arduino Uno board, with the Adafruit BlueFruit EZ-Link Bluetooth module, and with XBee Series 1 devices.

Expand All @@ -35,14 +37,22 @@ The project has been tested with Chrome 33, Safari 7 and Firefox 27.

To install the library, simply clone this repository in the /libraries folder of your Arduino folder.

## Quick test (HTTP)
## Quick test (WiFi)

1. Connect a LED & resistor to pin number 8 of your Arduino board
2. Open the WiFi_CC3000 example sketch and modify the WiFi SSID, password & security
3. Upload the sketch
4. Go to a web browser and type arduino.local/mode/8/o to set the pin as an output
5. Now type arduino.local/digital/8/1 and the LED should turn on

## Quick test (Ethernet)

1. Connect a LED & resistor to pin number 8 of your Arduino board
2. Make sure your computer is connected via Ethernet to the board and has the IP address 192.168.2.x
3. Upload the sketch
4. Go to a web browser and type 192.168.2.2/mode/8/o to set the pin as an output
5. Now type 192.168.2.2/digital/8/1 and the LED should turn on

## Quick test (Serial)

1. Connect a LED & resistor to pin number 8 of your Arduino board
Expand Down
23 changes: 22 additions & 1 deletion aREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "Arduino.h"

#define NUMBER_VARIABLES 2
#define NUMBER_FUNCTIONS 2

Expand Down Expand Up @@ -53,6 +53,27 @@ void handle(Adafruit_CC3000_ClientRef client) {
}
}

void handle(EthernetClient client){

if (client.available()) {

// Handle request
handle_proto(client,true);

// Give the web browser time to receive the data
delay(5);

client.stop();

// Reset variables for the next command
answer = "";
command = "";
command_selected = false;
pin_selected = false;
state_selected = false;
}
}

void handle(HardwareSerial serial){

if (serial.available()) {
Expand Down
73 changes: 73 additions & 0 deletions examples/Ethernet/Ethernet.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
This a simple example of the aREST Library for Arduino (Uno/Mega/Due/Teensy)
using the Ethernet library (for example to be used with the Ethernet shield).
See the README file for more details.
Written in 2014 by Marco Schwartz under a GPL license.
*/

// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <Ethernet.h>
#include <aREST.h>

// MAC address of the board
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// IP address of the board
IPAddress ip(192,168,2,2);

// Ethernet server
EthernetServer server(80);

// Create aREST instance
aREST rest = aREST();

// Variables to be exposed to the API
int temperature;
int humidity;

void setup(void)
{
// Start Serial
Serial.begin(115200);

// Init variables and expose them to REST API
temperature = 24;
humidity = 40;
rest.variable("temperature",&temperature);
rest.variable("humidity",&humidity);

// Function to be exposed
rest.function("led",ledControl);

// Give name and ID to device
rest.set_id("008");
rest.set_name("dapper_drake");

// Start the Ethernet connection and the server
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {

// listen for incoming clients
EthernetClient client = server.available();
rest.handle(client);

}

// Custom function accessible by the API
int ledControl(String command) {

// Get state from command
int state = command.toInt();

digitalWrite(7,state);
return 1;
}
3 changes: 2 additions & 1 deletion examples/Serial/Serial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <Ethernet.h>
#include <aREST.h>

// Create ArduREST instance
// Create aREST instance
aREST rest = aREST();

// Variables to be exposed to the API
Expand Down
3 changes: 2 additions & 1 deletion examples/WiFi_CC3000/WiFi_CC3000.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Import required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <Ethernet.h>
#include <CC3000_MDNS.h>
#include <aREST.h>

Expand All @@ -19,7 +20,7 @@
// Create CC3000 instance
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
// Create ArduREST instance
// Create aREST instance
aREST rest = aREST();

// Your WiFi SSID and password
Expand Down

0 comments on commit f6f909c

Please sign in to comment.