Skip to content

Instantly share code, notes, and snippets.

@42Bots
Last active April 30, 2017 04:23
Show Gist options
  • Save 42Bots/f9008988e2bcee3b701ed13940bce7f4 to your computer and use it in GitHub Desktop.
Save 42Bots/f9008988e2bcee3b701ed13940bce7f4 to your computer and use it in GitHub Desktop.
ESP8266 WiFi Station Example with remote GPIO control
/* For more information see http://42bots.com
* Based on the "WiFIAccessPoint" example included with the ESP8266 board files
* for the Arduino IDE Original copyright below.
* ============================================================================
* Copyright (c) 2015, Majenko Technologies
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of Majenko Technologies nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ==============================================================================
*/
// Configure the ESP8266 unit as a Wi-Fi access point
// Set up a web-server on it to display a basic welcome message.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
/* Your WiFi settings */
const char* ssid = "ESP8266"; //type your ssid
const char* password = "ESP8266Test"; //type your password
ESP8266WebServer server(80);
// basic function to display a welcome HTML message on the web-server root IP address
void handleRoot() {
server.send(200, "text/html", "<h1>Hello! Welcome to the ESP8266 access point!</h1>");
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring WiFi access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.println("Access point ready!");
Serial.println("");
Serial.print("Connect to WiFi network: ");
Serial.println(ssid);
Serial.print("WiFi password: ");
Serial.println(password);
server.on("/", handleRoot);
server.begin();
Serial.println("");
Serial.println("HTTP server started.");
Serial.print("Open the address http://");
Serial.print(myIP);
Serial.println(" in a web-browser for a welcome message.");
}
void loop() {
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment