mirror of
https://github.com/luc-github/ESP3D.git
synced 2025-10-31 11:56:48 -07:00
Update mDNS with latest version and display IP
Use M117 if any error
This commit is contained in:
@@ -19,6 +19,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//comment to disable
|
//comment to disable
|
||||||
|
//MDNS_FEATURE: this feature allow in Station mode to enter the name defined
|
||||||
|
//in web browser by default : http:\\esp8266.local and connect
|
||||||
|
//this feature does not work in AP mode
|
||||||
#define MDNS_FEATURE
|
#define MDNS_FEATURE
|
||||||
#define PROGMEM2CHAR progmem2char
|
#define PROGMEM2CHAR progmem2char
|
||||||
|
|
||||||
@@ -78,6 +81,7 @@ const long DEFAULT_BAUD_RATE = 9600;
|
|||||||
#ifdef MDNS_FEATURE
|
#ifdef MDNS_FEATURE
|
||||||
const char LOCAL_NAME[] PROGMEM = "esp8266";
|
const char LOCAL_NAME[] PROGMEM = "esp8266";
|
||||||
#endif
|
#endif
|
||||||
|
const char M117_[] PROGMEM = "M117 ";
|
||||||
#define DEFAULT_PHY_MODE PHY_MODE_11G
|
#define DEFAULT_PHY_MODE PHY_MODE_11G
|
||||||
#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T
|
#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T
|
||||||
#define DEFAULT_CHANNEL 11
|
#define DEFAULT_CHANNEL 11
|
||||||
|
|||||||
@@ -90,15 +90,20 @@ void setup() {
|
|||||||
web_interface->WebServer.begin();
|
web_interface->WebServer.begin();
|
||||||
data_server->begin();
|
data_server->begin();
|
||||||
data_server->setNoDelay(true);
|
data_server->setNoDelay(true);
|
||||||
|
|
||||||
|
#ifdef MDNS_FEATURE
|
||||||
|
// Check for any mDNS queries and send responses
|
||||||
|
if (wifi_get_opmode()==WIFI_STA )
|
||||||
|
{
|
||||||
|
wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//main loop
|
//main loop
|
||||||
void loop() {
|
void loop() {
|
||||||
#ifdef MDNS_FEATURE
|
|
||||||
// Check for any mDNS queries and send responses
|
|
||||||
wifi_config.Updatemdns();
|
|
||||||
#endif
|
|
||||||
//web requests
|
//web requests
|
||||||
web_interface->WebServer.handleClient();
|
web_interface->WebServer.handleClient();
|
||||||
//TODO use a method to handle serial also in class and call it instead of this one
|
//TODO use a method to handle serial also in class and call it instead of this one
|
||||||
|
|||||||
@@ -109,8 +109,11 @@ bool WIFI_CONFIG::Setup()
|
|||||||
apconfig.max_connection=DEFAULT_MAX_CONNECTIONS;
|
apconfig.max_connection=DEFAULT_MAX_CONNECTIONS;
|
||||||
apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL;
|
apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL;
|
||||||
//apply settings to current and to default
|
//apply settings to current and to default
|
||||||
if (!wifi_softap_set_config(&apconfig))Serial.println(F("Error Wifi AP"));
|
if (!wifi_softap_set_config(&apconfig) || !wifi_softap_set_config_current(&apconfig))
|
||||||
if (!wifi_softap_set_config_current(&apconfig))Serial.println(F("Error Wifi AP"));
|
{
|
||||||
|
Serial.println(F("M117 Error Wifi AP!"));
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
wifi_softap_dhcps_start();
|
wifi_softap_dhcps_start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -123,8 +126,17 @@ bool WIFI_CONFIG::Setup()
|
|||||||
byte i=0;
|
byte i=0;
|
||||||
//try to connect
|
//try to connect
|
||||||
while (WiFi.status() != WL_CONNECTED && i<40) {
|
while (WiFi.status() != WL_CONNECTED && i<40) {
|
||||||
|
|
||||||
|
switch(WiFi.status())
|
||||||
|
{
|
||||||
|
case 1:Serial.println(F("M117 No SSID found!"));
|
||||||
|
break;
|
||||||
|
case 4:Serial.println(F("M117 No Connection!"));
|
||||||
|
break;
|
||||||
|
default: Serial.println(F("M117 Connecting..."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.println(WiFi.status());
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,25 +158,18 @@ bool WIFI_CONFIG::Setup()
|
|||||||
else WiFi.config( local_ip, gateway, subnet);
|
else WiFi.config( local_ip, gateway, subnet);
|
||||||
}
|
}
|
||||||
#ifdef MDNS_FEATURE
|
#ifdef MDNS_FEATURE
|
||||||
|
// Set up mDNS responder:
|
||||||
|
if (wifi_get_opmode()==WIFI_STA )
|
||||||
|
if (!mdns.begin(PROGMEM2CHAR(LOCAL_NAME))) {
|
||||||
|
Serial.println(F("M117 Error with mDNS!"));
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//Get IP
|
//Get IP
|
||||||
if (wifi_get_opmode()==WIFI_STA)currentIP=WiFi.localIP();
|
if (wifi_get_opmode()==WIFI_STA)currentIP=WiFi.localIP();
|
||||||
else currentIP=WiFi.softAPIP();
|
else currentIP=WiFi.softAPIP();
|
||||||
// Set up mDNS responder:
|
Serial.print(PROGMEM2CHAR(M117_));
|
||||||
// - first argument is the domain name, in this example
|
Serial.println(currentIP);
|
||||||
// the fully-qualified domain name is "esp8266.local"
|
|
||||||
// - second argument is the IP address to advertise
|
|
||||||
// we send our IP address on the WiFi network
|
|
||||||
// Note: for AP mode we would use WiFi.softAPIP()!
|
|
||||||
if (!mdns.begin(PROGMEM2CHAR(LOCAL_NAME), currentIP)) {
|
|
||||||
Serial.println(F("Error setting up MDNS responder!"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#ifdef MDNS_FEATURE
|
|
||||||
void WIFI_CONFIG::Updatemdns()
|
|
||||||
{
|
|
||||||
if(current_mode==CLIENT_MODE)mdns.update();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
WIFI_CONFIG wifi_config;
|
WIFI_CONFIG wifi_config;
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class WIFI_CONFIG
|
|||||||
// multicast DNS responder feature
|
// multicast DNS responder feature
|
||||||
#ifdef MDNS_FEATURE
|
#ifdef MDNS_FEATURE
|
||||||
MDNSResponder mdns;
|
MDNSResponder mdns;
|
||||||
void Updatemdns();
|
|
||||||
#endif
|
#endif
|
||||||
byte current_mode;
|
byte current_mode;
|
||||||
int iweb_port;
|
int iweb_port;
|
||||||
|
|||||||
Reference in New Issue
Block a user