Last active
March 27, 2016 20:06
-
-
Save LarsBergqvist/72e3c2f6d6c4dfc1340c to your computer and use it in GitHub Desktop.
Using an Adafruit Feather Huzzah to control relays via aRest
This file contains hidden or 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 is an example sketch on using aREST with an Adafruit Feather Huzzah board | |
| * The sketch starts a web server and handles requests as REST calls via aREST | |
| * The board uses two relays on pins 12 and 13 that can be toggled via the REST API | |
| * Examples: | |
| * HuzzahIP/digital/12 -> returns the state of relay 1 | |
| * HuzzahIP/digital/13 -> returns the state of relay 2 | |
| * HuzzahIP/digital/12/0 -> turns relay 1 off | |
| * HuzzahIP/digital/12/1 -> turns relay 1 on | |
| * HuzzahIP/digital/13/0 -> turns relay 2 off | |
| * HuzzahIP/digital/13/1 -> turns relay 2 on | |
| */ | |
| #include <ESP8266WiFi.h> | |
| #include <aREST.h> | |
| // WiFi parameters | |
| #define SSID "YOUR_SSID" | |
| #define WIFI_PASSWORD "YOUR_WIFI_PWD" | |
| aREST rest = aREST(); | |
| #define LISTEN_PORT 80 | |
| WiFiServer server(LISTEN_PORT); | |
| #define RELAY1_PIN 12 | |
| #define RELAY2_PIN 13 | |
| void setup(void) | |
| { | |
| Serial.begin(115200); | |
| pinMode(RELAY1_PIN,OUTPUT); | |
| pinMode(RELAY2_PIN,OUTPUT); | |
| rest.set_id(""); | |
| rest.set_name("Lars' Feather Huzzah"); | |
| // Connect to WiFi | |
| WiFi.begin(SSID, WIFI_PASSWORD); | |
| while (WiFi.status() != WL_CONNECTED) | |
| { | |
| delay(500); | |
| Serial.print("."); | |
| } | |
| Serial.println(""); | |
| Serial.println("WiFi connected"); | |
| // Start the server | |
| server.begin(); | |
| Serial.println("Server started"); | |
| // Print the IP address | |
| Serial.println(WiFi.localIP()); | |
| } | |
| void loop() | |
| { | |
| WiFiClient client = server.available(); | |
| if (!client) | |
| { | |
| return; | |
| } | |
| while(!client.available()) | |
| { | |
| delay(10); | |
| } | |
| rest.handle(client); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment