Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

use mDNS to access web UI with usb.nugg #85

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/RubberNugget/RubberNugget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <WiFiClient.h>
#include <WebServer.h>

#include <ESPmDNS.h>
#include <DNSServer.h>

#include "webUI/index.h"

#include "src/utils.h"
Expand All @@ -20,6 +23,7 @@ const char *ssid = "Nugget AP";
const char *password = "nugget123";

WebServer server(80);
DNSServer dns;

TaskHandle_t webapp;
TaskHandle_t nuggweb;
Expand Down Expand Up @@ -100,6 +104,7 @@ void webrunlive() {

void webserverInit(void *p) {
while (1) {
dns.processNextRequest();
server.handleClient();
vTaskDelay(2);
}
Expand Down Expand Up @@ -129,6 +134,12 @@ void setup() {
Serial.print("AP IP address: ");
Serial.println(myIP);

dns.setErrorReplyCode(DNSReplyCode::NoError);
dns.start(53, "*", myIP);

MDNS.begin("usb.nugget");
Serial.println("mDNS responder started");

server.on("/", handleRoot);
server.on("/payloads", getPayloads);
server.on("/savepayload", HTTP_POST, websave);
Expand All @@ -139,6 +150,8 @@ void setup() {

server.begin();

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

xTaskCreate(webserverInit, "webapptask", 12 * 1024, NULL, 5, &webapp); // create task priority 1
nuggetInterface = new NuggetInterface;
NuggetScreen* dirScreen = new DirScreen("/");
Expand Down