1

I'm using Arduino IDE 1.6 nightly with Generic ESP8266 Board.

Why this code runs in mesh mode instead of simply connecting to my wifi? My goal is to test out MDNS, but so far I found this:

To my understanding such code should just connect to my wifi and I would then be able to navigate to http://esp8266-webupdate.local/update, am I missing something?

output (note STA+AP)

Booting Sketch...
......
Connected, IP address: 192.168.1.20
Mode: STA+AP
PHY mode: N
Channel: 10
AP id: 0
Status: 5
Auto connect: 1

code

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
const char* host = "esp8266-webupdate";
const char* ssid = "myhomeap";
const char* password = "blabla";
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
void setup(void){
 Serial.begin(115200);
 Serial.println();
 Serial.println("Booting Sketch...");
 WiFi.mode(WIFI_AP_STA);
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }
 Serial.println();
 Serial.print("Connected, IP address: ");
 Serial.println(WiFi.localIP());
 WiFi.printDiag(Serial);
 MDNS.begin(host);
 httpUpdater.setup(&httpServer);
 httpServer.begin();
 MDNS.addService("http", "tcp", 80);
 Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
}
void loop(void){
 httpServer.handleClient();
}
asked Jun 9, 2018 at 4:14
7
  • 1
    because of the WiFi.mode(WIFI_AP_STA); line? Commented Jun 9, 2018 at 4:42
  • the mdns propagation is not instant. wait some time Commented Jun 9, 2018 at 4:44
  • thanks, do you happen to know if is it necessary to go into this mode for mdns to work? this code was taken from examples Commented Jun 9, 2018 at 5:11
  • mdns works as expected in STA mode. only sometimes it takes time until the mdns name appears in IDE Port menu. (I use Eclipse and there I can type the address if it is still not found by mdns service) Commented Jun 9, 2018 at 5:15
  • 1
    STA only yes. and it doesn't need mdns. you can use the IP address. for Upload from IDE use ArduinoOTA library Commented Jun 9, 2018 at 6:35

1 Answer 1

3

It goes into STA+AP mode because your code is telling it to do that.

If you want it to just go into STA mode then your line:

WiFi.mode(WIFI_AP_STA);

should be

WiFi.mode(WIFI_STA);

answered Jun 9, 2018 at 5:01
2
  • thanks, the code was taken from examples, do you know if going into AP mode is necessary for MDNS to work at all? Commented Jun 9, 2018 at 5:10
  • In theory MDNS should work in any mode, but of course would only be visible on networks that the ESP was actually connected to. There are several issues filed on the MDNS code that show other people having trouble with STA+AP mode. There was a fix checked in but it's not clear that it really resolved the problem. So you're not the only one with problems with it; I wouldn't expect it to definitely work, unfortunately. Commented Jun 9, 2018 at 15:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.