Created
November 1, 2017 19:12
-
-
Save yakutozcan/a45d05394f78d22b8248336d65aa2b40 to your computer and use it in GitHub Desktop.
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 a simple example of the aREST UI Library for the ESP8266. | |
See the README file for more details. | |
Written in 2014-2016 by Marco Schwartz under a GPL license. | |
*/ | |
// Import required libraries | |
#include <ESP8266WiFi.h> | |
#include <aREST.h> | |
#include <aREST_UI.h> | |
//yakutozcan.blogspot.com.tr | |
// Create aREST instance | |
aREST_UI rest = aREST_UI(); | |
// WiFi parameters | |
const char* ssid = "wifiadi"; | |
const char* password = "wifisifre"; | |
// The port to listen for incoming TCP connections | |
#define LISTEN_PORT 80 | |
// Create an instance of the server | |
WiFiServer server(LISTEN_PORT); | |
void setup(void) { | |
// Start Serial | |
Serial.begin(115200); | |
pinMode(LED_BUILTIN, OUTPUT); | |
// Set the title | |
rest.title("aREST UI Led"); | |
// Function to be exposed | |
// Give name and ID to device | |
rest.set_id("1"); | |
rest.set_name("esp8266"); | |
// Connect to WiFi | |
WiFi.begin(ssid, 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() { | |
// Handle REST calls | |
WiFiClient client = server.available(); | |
if (!client) { | |
return; | |
} | |
while (!client.available()) { | |
delay(1); | |
} | |
rest.handle(client); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment