Chat freely about anything...

User avatar
By DavidS
#43758 Hi all, first time poster here.
I'm trying to do a project that broadcasts a wifi network, and then serves anyone who connects a simple html or txt page.
Is this possible to do with an esp8266, 12e or F variant?
Also, what do I need to get started programming it? I have some experience with Arduino already.
User avatar
By Geert
#43808 Hey welcome

First make sure that you installed the last version of Arduino and
Start Arduino and open Preferences window.
Enter http://arduino.esp8266.com/stable/packa ... index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).

This is the example that you need:

It starts an AP with the name: ESPap
and the password thereisnospoon

When someone connects to the IP of the acces point (192.168.4.1), they will get the website within the handleRoot() function.
You are connected

[s]If you want to respond to every ip adress or domain name than you need some tweaking in the DNS Library viewtopic.php?f=32&t=3618 [/s]

Source: https://github.com/esp8266/Arduino/blob ... sPoint.ino
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/* Set these to your desired credentials. */
const char *ssid = "ESPap";
const char *password = "thereisnospoon";
ESP8266WebServer server(80);
/* Just a little test message. Go to  http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
server.send(200, "text/html", "<h1>You are connected</h1>");
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring 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.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}


This is the code if you want to respond to every request, doesn't matter if the user tries to reach google.com or facebook.com he will always get your page...
Code: Select all#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String responseHTML = ""
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
"be redirected here.</p></body></html>";
void setup() {
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("DNSServer CaptivePortal example");
// if DNSServer is started with "*" for domain name, it will reply with
// provided IP to all DNS request
dnsServer.start(DNS_PORT, "*", apIP);
// replay to all requests with same HTML
webServer.onNotFound([]() {
webServer.send(200, "text/html", responseHTML);
});
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
}
User avatar
By DavidS
#43811 Hey Geert, thanks for the reply!
What do I need in terms of hardware? The Arduinos I've used so far have had USB ports. Can I use one of them or do I need something else?
User avatar
By Geert
#43831 Get a nodeMCU than you have a USB port on board, that one works the most reliable from the family for me

[url]http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2047675.m570.l1313.TR0.TRC0.H0.XnodeMCU.TRS0&_nkw=nodeMCU&_sacat=0
[/url]
[url]http://www.dx.com/p/nodemcu-esp8266-esp-12-deleopment-board-lua-wi-fi-module-w-built-in-antennas-385190#.VvHTceIrKWg
[/url]