Skip to content
Permalink
Browse files

URL wifi.duck as alternative to 192.168.4.1

  • Loading branch information...
spacehuhn committed Nov 16, 2019
1 parent f16d04f commit 69922223e5a130d4955eec500aa72e54e1f864ed
Showing with 13 additions and 5 deletions.
  1. +4 −1 esp_duck/config.h
  2. +9 −4 esp_duck/webserver.cpp
  3. BIN img/usage.png
@@ -40,6 +40,9 @@
#define WIFI_PASSWORD "wifiduck"
#define WIFI_CHANNEL "1"

#define HOSTNAME "wifiduck"
#define URL "wifi.duck"

/*! ========== Safty checks ========== */
#if !defined(ENABLE_I2C) && !defined(ENABLE_SERIAL)
#define ENABLE_I2C
@@ -62,4 +65,4 @@

#if defined(ENABLE_I2C) && defined(ENABLE_SERIAL) && (I2C_SDA==1 || I2C_SDA==3 || I2C_SCL==1 || I2C_SCL==3)
#error I2C pins overlap with RX and TX pins. Disable serial debugging or change the I2C pins.
#endif /* if !defined(ENABLE_I2C) && !defined(ENABLE_I2C) */
#endif /* if !defined(ENABLE_I2C) && !defined(ENABLE_I2C) */
@@ -8,6 +8,7 @@

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <DNSServer.h>
#include <ArduinoOTA.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
@@ -34,10 +35,10 @@ namespace webserver {
AsyncWebSocket ws("/ws");
AsyncEventSource events("/events");

const char* host_name = "wifiduck";

AsyncWebSocketClient* currentClient { nullptr };

DNSServer dnsServer;

bool reboot = false;

void wsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
@@ -79,7 +80,8 @@ namespace webserver {
// ===== PUBLIC ===== //
void begin() {
// Access Point
WiFi.hostname(host_name);
WiFi.hostname(HOSTNAME);

// WiFi.mode(WIFI_AP_STA);
WiFi.softAP(settings::getSSID(), settings::getPassword(), settings::getChannelNum());
debugf("Started Access Point \"%s\":\"%s\"\n", settings::getSSID(), settings::getPassword());
@@ -114,7 +116,7 @@ namespace webserver {
else if (error == OTA_RECEIVE_ERROR) events.send("Recieve Failed", "ota");
else if (error == OTA_END_ERROR) events.send("End Failed", "ota");
});
ArduinoOTA.setHostname(host_name);
ArduinoOTA.setHostname(HOSTNAME);
ArduinoOTA.begin();

events.onConnect([](AsyncEventSourceClient* client) {
@@ -155,6 +157,8 @@ namespace webserver {

MDNS.addService("http", "tcp", 80);

dnsServer.start(53, URL, IPAddress(192, 168, 4, 1));

// Websocket
ws.onEvent(wsEvent);
server.addHandler(&ws);
@@ -167,6 +171,7 @@ namespace webserver {
void update() {
ArduinoOTA.handle();
if (reboot) ESP.restart();
dnsServer.processNextRequest();
}

void send(const char* str) {
BIN +2.33 KB (100%) img/usage.png
Binary file not shown.

0 comments on commit 6992222

Please sign in to comment.
You can’t perform that action at this time.