forked from marcoschwartz/aREST
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for official Ethernet board
- Loading branch information
1 parent
0fd2c18
commit f6f909c
Showing
5 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters