set configurable hostname

This commit is contained in:
Kevin Matz 2020-12-11 16:00:58 -05:00
parent fb8906aff0
commit 5d951eba47

View File

@ -44,13 +44,14 @@ const int reset_button = A1; // tie A1 to ground to reset preferances
device configuration
*/
struct config_ {
String ssid;
String pwd;
String ssid;
String pwd;
wifi_mode_t mode;
String ip;
String subnet;
String gateway;
String ip;
String subnet;
String gateway;
String hostname;
String osc_host;
uint16_t osc_port;
@ -59,11 +60,11 @@ struct config_ {
String osc_released_addr;
String osc_released_value;
bool button_enable;
int button_pin;
bool button_enable;
int button_pin;
bool strobe_enable;
int strobe_led_pin;
bool strobe_enable;
int strobe_led_pin;
uint16_t strobe_universe;
uint16_t strobe_address;
@ -80,6 +81,7 @@ struct config_ config;
Strobe *strobe;
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip;
ESPAsyncE131 *e131 = new ESPAsyncE131();
Preferences prefs;
//// Global button variables
bool pressed = false; // track button state
@ -127,6 +129,7 @@ bool loadConfig() {
config.ssid = prefs.getString("ssid", "WiFlash");
config.pwd = prefs.getString("pwd", "technologyismagic");
config.mode = (wifi_mode_t)prefs.getChar("wifi_mode", WIFI_AP);
config.hostname = prefs.getString("hostname", "WiFlash");
config.ip = prefs.getString("ip", "192.168.1.1");
config.subnet = prefs.getString("subnet", "255.255.255.0");
@ -173,6 +176,7 @@ void setup() {
// set IPv4
Serial.println("Starting WiFi.");
WiFi.mode(WIFI_STA);
WiFi.setHostname(config.hostname.c_str());
IPAddress ip_, gateway_, subnet_;
ip_.fromString(config.ip);
gateway_.fromString(config.gateway);