Compare commits
2 Commits
truncated-
...
wifi-exper
Author | SHA1 | Date | |
---|---|---|---|
a402019e4d | |||
1d4f7e74de |
157
WiFi.h
Normal file
157
WiFi.h
Normal file
@ -0,0 +1,157 @@
|
||||
//#include <DNSServer.h>
|
||||
|
||||
//DNSServer dnsServer;
|
||||
|
||||
//const byte DNS_PORT = 53;
|
||||
|
||||
// AP mode password
|
||||
const char WiFiAPPSK[] = "";
|
||||
|
||||
// Wi-Fi network to connect to (leave blank to connect to saved network, or to start in AP mode)
|
||||
const char* ssid = "";
|
||||
const char* password = "";
|
||||
|
||||
#define HOSTNAME "ESP8266-" ///< Hostname. The initializeWiFi function adds the Chip ID at the end.
|
||||
|
||||
#define DEBUG_WIFI 1
|
||||
|
||||
WiFiMode mode = WIFI_STA; // connect to existing Wi-Fi network
|
||||
//WiFiMode mode = WIFI_AP; // act as an Access Point, creating a new Wi-Fi network
|
||||
//WiFiMode mode = WIFI_AP_STA; // act as both a client and Access Point (mesh mode)
|
||||
|
||||
template <typename Generic>
|
||||
void debugPrint(Generic text) {
|
||||
if (DEBUG_WIFI) {
|
||||
Serial.print(text);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Generic>
|
||||
void debugPrintln(Generic text) {
|
||||
if (DEBUG_WIFI) {
|
||||
Serial.println(text);
|
||||
}
|
||||
}
|
||||
|
||||
String getWiFiJson() {
|
||||
String hostname = String(HOSTNAME);
|
||||
hostname += String(ESP.getChipId(), HEX);
|
||||
|
||||
String json = "{";
|
||||
|
||||
json += "\"status\":\"" + String(WiFi.status()) + "\"";
|
||||
json += ",\"localIP\":\"" + WiFi.localIP().toString() + "\"";
|
||||
json += ",\"softAPIP\":\"" + WiFi.softAPIP().toString() + "\"";
|
||||
json += ",\"hostname\":\"" + hostname + "\"";
|
||||
json += ",\"ssid\":\"" + WiFi.SSID() + "\"";
|
||||
json += ",\"rssi\":\"" + String(WiFi.RSSI()) + "\"";
|
||||
|
||||
json += ",\"networks\":[";
|
||||
byte ssidCount = WiFi.scanNetworks();
|
||||
for (byte i = 0; i < ssidCount; i++) {
|
||||
if (i > 0)
|
||||
json += ",";
|
||||
|
||||
json += "{\"name\":\"" + WiFi.SSID(i) + "\",\"rssi\":\"" + String(WiFi.RSSI(i)) + "\"}";
|
||||
}
|
||||
|
||||
json += "]";
|
||||
|
||||
json += "}";
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
void initializeWiFi() {
|
||||
// Set Hostname.
|
||||
String hostname = String(HOSTNAME);
|
||||
hostname += String(ESP.getChipId(), HEX);
|
||||
WiFi.hostname(hostname);
|
||||
|
||||
// Print hostname.
|
||||
Serial.println("Hostname: " + hostname);
|
||||
|
||||
char hostnameChar[hostname.length() + 1];
|
||||
memset(hostnameChar, 0, hostname.length() + 1);
|
||||
|
||||
for (uint8_t i = 0; i < hostname.length(); i++)
|
||||
hostnameChar[i] = hostname.charAt(i);
|
||||
|
||||
// MDNS.begin(hostnameChar);
|
||||
|
||||
// Add service to MDNS-SD
|
||||
// MDNS.addService("http", "tcp", 80);
|
||||
|
||||
// attempt to connect; should it fail, fall back to AP mode
|
||||
// WiFi.mode(WIFI_STA);
|
||||
|
||||
String stored_ssid = WiFi.SSID();
|
||||
|
||||
if (ssid != NULL && password != NULL &&
|
||||
ssid != "" && password != "") {
|
||||
debugPrint("WiFi mode: ");
|
||||
debugPrintln(WIFI_STA);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
debugPrint("Connecting to hard-coded SSID: ");
|
||||
debugPrintln(stored_ssid);
|
||||
WiFi.begin(ssid, password);
|
||||
}
|
||||
else if (stored_ssid != NULL && stored_ssid != "") {
|
||||
debugPrint("WiFi mode: ");
|
||||
debugPrintln(WIFI_STA);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
debugPrint("Connecting to stored SSID: ");
|
||||
debugPrintln(stored_ssid);
|
||||
WiFi.begin();
|
||||
}
|
||||
else {
|
||||
debugPrintln("No stored SSID");
|
||||
debugPrint("Starting soft AP: ");
|
||||
debugPrintln(hostnameChar);
|
||||
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
if (WiFiAPPSK != NULL) {
|
||||
debugPrint(WiFi.softAP(hostnameChar, WiFiAPPSK) ? "ready" : "failed");
|
||||
} else {
|
||||
debugPrint(WiFi.softAP(hostnameChar) ? "ready" : "failed");
|
||||
}
|
||||
|
||||
debugPrint("Connect to Wi-Fi access point: ");
|
||||
debugPrintln(hostnameChar);
|
||||
|
||||
delay(500); // Without delay I've seen the IP address blank
|
||||
debugPrint("AP IP address: ");
|
||||
debugPrintln(WiFi.softAPIP());
|
||||
|
||||
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||
// dnsServer.start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
}
|
||||
|
||||
webServer.on("/wifi", HTTP_POST, []() {
|
||||
String ssid = webServer.arg("ssid");
|
||||
String password = webServer.arg("password");
|
||||
|
||||
char ssidChars[50];
|
||||
ssid.toCharArray(ssidChars, 50);
|
||||
|
||||
char passwordChars[50];
|
||||
password.toCharArray(passwordChars, 50);
|
||||
|
||||
debugPrint("Connecting to new SSID: ");
|
||||
debugPrintln(ssid);
|
||||
|
||||
WiFi.begin(ssidChars, passwordChars);
|
||||
|
||||
webServer.sendHeader("Location", "/wifi.htm");
|
||||
webServer.send(303);
|
||||
});
|
||||
|
||||
webServer.on("/wifi", HTTP_GET, []() {
|
||||
String json = getWiFiJson();
|
||||
webServer.send(200, "application/json", json);
|
||||
});
|
||||
}
|
||||
|
BIN
data/images/github.ico
Normal file
BIN
data/images/github.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
@ -13,7 +13,7 @@
|
||||
|
||||
<!-- request CSS from the ESP8266 web server -->
|
||||
<!-- <link rel="stylesheet" href="css/bootstrap.min.css"> -->
|
||||
<!-- <link rel="stylesheet" href="css/jquery.minicolors.min.css"> -->
|
||||
<!-- <link rel="stylesheet" href="css/minicolors.min.css"> -->
|
||||
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="https://evilgeniuslabs.org/images/atom.svg" style="width: 24px; height: 24px;" /></a>
|
||||
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="/images/atom196.png" style="width: 24px; height: 24px;" /></a>
|
||||
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank">Evil Genius Labs</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse" id="navbar-collapse-1">
|
||||
@ -40,11 +40,12 @@
|
||||
<li><a href="/simple.htm" target="_blank" title="Simple Mode">Simple</a></li>
|
||||
<li><a href="/edit.htm" target="_blank" title="Edit Files">Files</a></li>
|
||||
<li><a href="/update" target="_blank" title="Update Firmware">Firmware</a></li>
|
||||
<li><a href="/wifi.htm" target="_blank" title="Wi-Fi Settings">Wi-Fi</a></li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<a href="https://github.com/jasoncoon/esp8266-fastled-webserver">
|
||||
<img style="height: 16px;" src="https://assets-cdn.github.com/favicon.ico" />
|
||||
<img style="height: 16px;" src="/images/github.ico" />
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
@ -215,7 +216,7 @@
|
||||
</nav>
|
||||
|
||||
<!-- request js from internet CDN -->
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> -->
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-minicolors/2.2.4/jquery.minicolors.min.js" integrity="sha256-XAFQ9dZ6hy8p/GRhU8h/8pMvM1etymiJLZW1CiHV3bQ=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js" integrity="sha256-A4JwlcDvqO4JXpvEtvWY1RH8JAEMu5W21wP8GUXLUNs=" crossorigin="anonymous"></script>
|
||||
@ -223,7 +224,7 @@
|
||||
<!-- request js from the ESP8266 web server -->
|
||||
<!-- <script src="js/jquery-3.1.1.min.js"></script> -->
|
||||
<!-- <script src="js/bootstrap.min.js"></script> -->
|
||||
<!-- <script src="js/jquery.minicolors.min.js"></script> -->
|
||||
<!-- <script src="js/minicolors.min.js"></script> -->
|
||||
<!-- <script src="js/r-websocket.min.js"></script> -->
|
||||
|
||||
<script src="js/app.js"></script>
|
||||
|
@ -1,3 +1,8 @@
|
||||
// require ./jquery-3.1.1.min.js
|
||||
// require ./bootstrap.min.js
|
||||
// require ./minicolors.min.js
|
||||
// require ./r-websocket.min.js
|
||||
|
||||
// used when hosting the site on the ESP8266
|
||||
var address = location.hostname;
|
||||
var urlBase = "";
|
||||
|
4
data/js/bootstrap.min.js
vendored
4
data/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
95
data/wifi.htm
Normal file
95
data/wifi.htm
Normal file
@ -0,0 +1,95 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>ESP8266 + FastLED by Evil Genius Labs</title>
|
||||
|
||||
<!-- request CSS from internet CDN -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
|
||||
<!-- request CSS from the ESP8266 web server -->
|
||||
<!-- <link rel="stylesheet" href="css/bootstrap.min.css"> -->
|
||||
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
|
||||
<link rel="icon" href="images/atom196.png">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-default navbar-static-top" id="top" role="banner">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="/images/atom196.png" style="width: 24px; height: 24px;" /></a>
|
||||
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank">Evil Genius Labs</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse" id="navbar-collapse-1">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/">ESP8266 + FastLED <span class="sr-only">(current)</span></a></li>
|
||||
<li><a href="/simple.htm" target="_blank" title="Simple Mode">Simple</a></li>
|
||||
<li><a href="/edit.htm" target="_blank" title="Edit Files">Files</a></li>
|
||||
<li><a href="/update" target="_blank" title="Update Firmware">Firmware</a></li>
|
||||
<li class="active"><a href="/wifi.htm" target="_blank" title="Wi-Fi Settings">Wi-Fi</a></li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<a href="https://github.com/jasoncoon/esp8266-fastled-webserver">
|
||||
<img style="height: 16px;" src="/images/github.ico" />
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="container" class="container">
|
||||
|
||||
<form class="form-horizontal" id="form" action="/wifi" method="post">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputSSID" class="col-sm-2 control-label">SSID</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" autocorrect="off" autocapitalize="none"
|
||||
class="form-control" id="inputSSID" name="ssid" placeholder="SSID (Wi-Fi network name)">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-default">Connect</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- request js from internet CDN -->
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
|
||||
<!-- <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script> -->
|
||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js" integrity="sha256-A4JwlcDvqO4JXpvEtvWY1RH8JAEMu5W21wP8GUXLUNs=" crossorigin="anonymous"></script> -->
|
||||
|
||||
<!-- request js from the ESP8266 web server -->
|
||||
<!-- <script src="js/jquery-3.1.1.min.js"></script> -->
|
||||
<!-- <script src="js/bootstrap.min.js"></script> -->
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
@ -15,9 +15,9 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define FASTLED_ALLOW_INTERRUPTS 0
|
||||
//#define FASTLED_INTERRUPT_RETRY_COUNT 1
|
||||
|
||||
#define FASTLED_INTERRUPT_RETRY_COUNT 1
|
||||
//#define FASTLED_ALLOW_INTERRUPTS 0
|
||||
|
||||
#include <FastLED.h>
|
||||
FASTLED_USING_NAMESPACE
|
||||
@ -40,34 +40,25 @@ extern "C" {
|
||||
|
||||
#include "Field.h"
|
||||
|
||||
#define HOSTNAME "ESP8266-" ///< Hostname. The setup function adds the Chip ID at the end.
|
||||
|
||||
//#define RECV_PIN D4
|
||||
//IRrecv irReceiver(RECV_PIN);
|
||||
|
||||
//#include "Commands.h"
|
||||
|
||||
const bool apMode = false;
|
||||
|
||||
// AP mode password
|
||||
const char WiFiAPPSK[] = "";
|
||||
|
||||
// Wi-Fi network to connect to (if not in AP mode)
|
||||
const char* ssid = "";
|
||||
const char* password = "";
|
||||
|
||||
ESP8266WebServer webServer(80);
|
||||
WebSocketsServer webSocketsServer = WebSocketsServer(81);
|
||||
ESP8266HTTPUpdateServer httpUpdateServer;
|
||||
|
||||
#include "WiFi.h"
|
||||
|
||||
#include "FSBrowser.h"
|
||||
|
||||
#define DATA_PIN D5
|
||||
#define LED_TYPE WS2811
|
||||
#define LED_TYPE WS2812
|
||||
#define COLOR_ORDER RGB
|
||||
#define NUM_LEDS 32
|
||||
#define NUM_LEDS 50
|
||||
|
||||
#define MILLI_AMPS 2000 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA)
|
||||
#define MILLI_AMPS 3000 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA)
|
||||
#define FRAMES_PER_SECOND 120 // here you can control the speed. With the Access Point / Web Server the animations run a bit slower.
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
@ -255,57 +246,7 @@ void setup() {
|
||||
Serial.printf("\n");
|
||||
}
|
||||
|
||||
// Set Hostname.
|
||||
String hostname(HOSTNAME);
|
||||
hostname += String(ESP.getChipId(), HEX);
|
||||
WiFi.hostname(hostname);
|
||||
|
||||
char hostnameChar[hostname.length() + 1];
|
||||
memset(hostnameChar, 0, hostname.length() + 1);
|
||||
|
||||
for (uint8_t i = 0; i < hostname.length(); i++)
|
||||
hostnameChar[i] = hostname.charAt(i);
|
||||
|
||||
// MDNS.begin(hostnameChar);
|
||||
//
|
||||
// // Add service to MDNS-SD
|
||||
// MDNS.addService("http", "tcp", 80);
|
||||
|
||||
// Print hostname.
|
||||
Serial.println("Hostname: " + hostname);
|
||||
|
||||
if (apMode)
|
||||
{
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
// Do a little work to get a unique-ish name. Append the
|
||||
// last two bytes of the MAC (HEX'd) to "Thing-":
|
||||
uint8_t mac[WL_MAC_ADDR_LENGTH];
|
||||
WiFi.softAPmacAddress(mac);
|
||||
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
|
||||
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
|
||||
macID.toUpperCase();
|
||||
String AP_NameString = "ESP8266-" + macID;
|
||||
|
||||
char AP_NameChar[AP_NameString.length() + 1];
|
||||
memset(AP_NameChar, 0, AP_NameString.length() + 1);
|
||||
|
||||
for (int i = 0; i < AP_NameString.length(); i++)
|
||||
AP_NameChar[i] = AP_NameString.charAt(i);
|
||||
|
||||
WiFi.softAP(AP_NameChar, WiFiAPPSK);
|
||||
|
||||
Serial.printf("Connect to Wi-Fi access point: %s\n", AP_NameChar);
|
||||
Serial.println("and open http://192.168.4.1 in your browser");
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
Serial.printf("Connecting to %s\n", ssid);
|
||||
if (String(WiFi.SSID()) != String(ssid)) {
|
||||
WiFi.begin(ssid, password);
|
||||
}
|
||||
}
|
||||
initializeWiFi();
|
||||
|
||||
httpUpdateServer.setup(&webServer);
|
||||
|
||||
@ -476,6 +417,7 @@ void loop() {
|
||||
// Add entropy to random number generator; we use a lot of it.
|
||||
random16_add_entropy(random(65535));
|
||||
|
||||
// dnsServer.processNextRequest();
|
||||
webSocketsServer.loop();
|
||||
webServer.handleClient();
|
||||
|
||||
@ -554,7 +496,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
//void handleIrInput()
|
||||
//{
|
||||
// InputCommand command = readCommand();
|
||||
|
Reference in New Issue
Block a user