mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-15 11:52:12 +01:00
Move the hostname settings around #172
This commit is contained in:
parent
d851ae1ea4
commit
b64afd6796
3 changed files with 15 additions and 7 deletions
|
|
@ -119,7 +119,7 @@ class SecuritySettings: BaseSettings {
|
||||||
class MQTTSettings: BaseSettings {
|
class MQTTSettings: BaseSettings {
|
||||||
public:
|
public:
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
char hostname[65] = "";
|
char hostname[65] = "ESPSomfyRTS";
|
||||||
char protocol[10] = "mqtt://";
|
char protocol[10] = "mqtt://";
|
||||||
uint16_t port = 1883;
|
uint16_t port = 1883;
|
||||||
char username[33] = "";
|
char username[33] = "";
|
||||||
|
|
|
||||||
20
Network.cpp
20
Network.cpp
|
|
@ -228,6 +228,10 @@ bool Network::connectWired() {
|
||||||
else
|
else
|
||||||
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
WiFi.onEvent(this->networkEvent);
|
WiFi.onEvent(this->networkEvent);
|
||||||
|
if(settings.hostname[0] != '\0') ETH.setHostname(settings.hostname);
|
||||||
|
Serial.print("Set hostname to:");
|
||||||
|
Serial.println(ETH.getHostname());
|
||||||
|
|
||||||
if(!ETH.begin(settings.Ethernet.phyAddress, settings.Ethernet.PWRPin, settings.Ethernet.MDCPin, settings.Ethernet.MDIOPin, settings.Ethernet.phyType, settings.Ethernet.CLKMode)) {
|
if(!ETH.begin(settings.Ethernet.phyAddress, settings.Ethernet.PWRPin, settings.Ethernet.MDCPin, settings.Ethernet.MDIOPin, settings.Ethernet.phyType, settings.Ethernet.CLKMode)) {
|
||||||
Serial.println("Ethernet Begin failed");
|
Serial.println("Ethernet Begin failed");
|
||||||
if(settings.connType == conn_types::ethernetpref) {
|
if(settings.connType == conn_types::ethernetpref) {
|
||||||
|
|
@ -257,7 +261,6 @@ bool Network::connectWired() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Network::connectWiFi() {
|
bool Network::connectWiFi() {
|
||||||
if(settings.hostname[0] != '\0') WiFi.hostname(settings.hostname);
|
|
||||||
if(settings.WIFI.ssid[0] != '\0') {
|
if(settings.WIFI.ssid[0] != '\0') {
|
||||||
if(WiFi.status() == WL_CONNECTED && WiFi.SSID().compareTo(settings.WIFI.ssid) == 0) {
|
if(WiFi.status() == WL_CONNECTED && WiFi.SSID().compareTo(settings.WIFI.ssid) == 0) {
|
||||||
this->disconnected = 0;
|
this->disconnected = 0;
|
||||||
|
|
@ -275,17 +278,22 @@ bool Network::connectWiFi() {
|
||||||
else Serial.println("Connecting to AP");
|
else Serial.println("Connecting to AP");
|
||||||
this->connectAttempts++;
|
this->connectAttempts++;
|
||||||
this->connectStart = millis();
|
this->connectStart = millis();
|
||||||
Serial.print("Set hostname to:");
|
WiFi.setSleep(false);
|
||||||
Serial.println(WiFi.getHostname());
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
|
|
||||||
|
|
||||||
if(!settings.IP.dhcp) {
|
if(!settings.IP.dhcp) {
|
||||||
if(!WiFi.config(settings.IP.ip, settings.IP.gateway, settings.IP.subnet, settings.IP.dns1, settings.IP.dns2))
|
if(!WiFi.config(settings.IP.ip, settings.IP.gateway, settings.IP.subnet, settings.IP.dns1, settings.IP.dns2))
|
||||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
WiFi.setSleep(false);
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
// There is also another method simply called hostname() but this is legacy for esp8266.
|
||||||
|
if(settings.hostname[0] != '\0') WiFi.setHostname(settings.hostname);
|
||||||
|
Serial.print("Set hostname to:");
|
||||||
|
Serial.println(WiFi.getHostname());
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(settings.WIFI.ssid, settings.WIFI.passphrase);
|
WiFi.begin(settings.WIFI.ssid, settings.WIFI.passphrase);
|
||||||
delay(100);
|
delay(100);
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
|
|
@ -304,7 +312,7 @@ bool Network::connectWiFi() {
|
||||||
Serial.print("*");
|
Serial.print("*");
|
||||||
break;
|
break;
|
||||||
case WL_CONNECTED:
|
case WL_CONNECTED:
|
||||||
WiFi.hostname(settings.hostname);
|
//WiFi.hostname(settings.hostname);
|
||||||
this->ssid = WiFi.SSID();
|
this->ssid = WiFi.SSID();
|
||||||
this->mac = WiFi.BSSIDstr();
|
this->mac = WiFi.BSSIDstr();
|
||||||
this->strength = WiFi.RSSI();
|
this->strength = WiFi.RSSI();
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue