Same hostname generation and customization as V3
This commit is contained in:
parent
7d0d07e928
commit
483622f430
7 changed files with 39 additions and 5 deletions
|
@ -36,8 +36,8 @@ void setupSoftAP()
|
|||
{
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
softAP_SSID = String("BTClock" + String(mac[5], 16) + String(mac[1], 16));
|
||||
WiFi.setHostname(softAP_SSID.c_str());
|
||||
softAP_SSID = getMyHostname().c_str();
|
||||
WiFi.setHostname(getMyHostname().c_str());
|
||||
softAP_password = base64::encode(String(mac[2], 16) + String(mac[4], 16) + String(mac[5], 16) + String(mac[1], 16)).substring(2, 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//#include <WiFiMulti.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "utils.hpp"
|
||||
#include "shared.hpp"
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "lib/epd.hpp"
|
||||
|
|
|
@ -41,3 +41,14 @@ std::string formatNumberWithSuffix(int64_t num) {
|
|||
return std::to_string(num);
|
||||
}
|
||||
}
|
||||
|
||||
String getMyHostname() {
|
||||
uint8_t mac[6];
|
||||
//WiFi.macAddress(mac);
|
||||
esp_efuse_mac_get_default(mac);
|
||||
char hostname[15];
|
||||
String hostnamePrefix = preferences.getString("hostnamePrefix", "btclock");
|
||||
snprintf(hostname, sizeof(hostname), "%s-%02x%02x%02x",
|
||||
hostnamePrefix, mac[3], mac[4], mac[5]);
|
||||
return hostname;
|
||||
}
|
|
@ -3,4 +3,5 @@
|
|||
#include "shared.hpp"
|
||||
|
||||
double getSupplyAtBlock(uint blockNr);
|
||||
std::string formatNumberWithSuffix(int64_t num);
|
||||
std::string formatNumberWithSuffix(int64_t num);
|
||||
String getMyHostname();
|
||||
|
|
|
@ -52,7 +52,7 @@ void setupWebserver()
|
|||
|
||||
// Start server
|
||||
server.begin();
|
||||
if (!MDNS.begin(HOSTNAME))
|
||||
if (!MDNS.begin(getMyHostname()))
|
||||
{
|
||||
Serial.println(F("Error setting up MDNS responder!"));
|
||||
while (1)
|
||||
|
@ -61,6 +61,9 @@ void setupWebserver()
|
|||
}
|
||||
}
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
MDNS.addServiceTxt("http", "tcp", "model", "BTClock");
|
||||
MDNS.addServiceTxt("http", "tcp", "version", "2.0");
|
||||
MDNS.addServiceTxt("http", "tcp", "rev", GIT_REV);
|
||||
Serial.println(F("Webserver should be running"));
|
||||
}
|
||||
|
||||
|
@ -184,7 +187,9 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
|||
root["rpcUser"] = preferences.getString("rpcUser", BITCOIND_RPC_USER);
|
||||
root["rpcHost"] = preferences.getString("rpcHost", BITCOIND_HOST);
|
||||
root["mempoolInstance"] = preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE);
|
||||
|
||||
root["hostnamePrefix"] = preferences.getString("hostnamePrefix", "btclock");
|
||||
root["hostname"] = getMyHostname();
|
||||
|
||||
#ifdef IS_BW
|
||||
root["epdColors"] = 2;
|
||||
#else
|
||||
|
@ -290,6 +295,14 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("hostnamePrefix", true))
|
||||
{
|
||||
AsyncWebParameter *hostnamePrefix = request->getParam("hostnamePrefix", true);
|
||||
|
||||
preferences.putString("hostnamePrefix", hostnamePrefix->value().c_str());
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
if (request->hasParam("ledBrightness", true))
|
||||
{
|
||||
AsyncWebParameter *ledBrightness = request->getParam("ledBrightness", true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue