mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Fix mDNS webserver port and expose prometheus service (#1389)
* Expose right webserver port using mDNS. 80 is the default value but can be changed in the config file. Add a new define for the port. Signed-off-by: Richard Weinberger <richard@nod.at> * Expose prometheus service via mDNS That way prometheus auto discovery features can find us. Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
parent
be16d10b7d
commit
765e641d08
3 changed files with 12 additions and 2 deletions
|
@ -18,5 +18,7 @@ CONFIG_SCHEMA = cv.Schema({
|
|||
def to_code(config):
|
||||
paren = yield cg.get_variable(config[CONF_WEB_SERVER_BASE_ID])
|
||||
|
||||
cg.add_define('USE_PROMETHEUS')
|
||||
|
||||
var = cg.new_Pvariable(config[CONF_ID], paren)
|
||||
yield cg.register_component(var, config)
|
||||
|
|
|
@ -36,6 +36,7 @@ def to_code(config):
|
|||
yield cg.register_component(var, config)
|
||||
|
||||
cg.add(paren.set_port(config[CONF_PORT]))
|
||||
cg.add_define('WEBSERVER_PORT', config[CONF_PORT])
|
||||
cg.add(var.set_css_url(config[CONF_CSS_URL]))
|
||||
cg.add(var.set_js_url(config[CONF_JS_URL]))
|
||||
if CONF_AUTH in config:
|
||||
|
|
|
@ -43,6 +43,10 @@ bool network_is_connected() {
|
|||
bool mdns_setup;
|
||||
#endif
|
||||
|
||||
#ifndef WEBSERVER_PORT
|
||||
static const uint8_t WEBSERVER_PORT = 80;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
void network_setup_mdns(IPAddress address, int interface) {
|
||||
// Latest arduino framework breaks mDNS for AP interface
|
||||
|
@ -65,12 +69,15 @@ void network_setup_mdns(IPAddress address, int interface) {
|
|||
MDNS.addServiceTxt("esphomelib", "tcp", "mac", get_mac_address().c_str());
|
||||
} else {
|
||||
#endif
|
||||
// Publish "http" service if not using native API.
|
||||
// Publish "http" service if not using native API nor the webserver component
|
||||
// This is just to have *some* mDNS service so that .local resolution works
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
MDNS.addService("http", "tcp", WEBSERVER_PORT);
|
||||
MDNS.addServiceTxt("http", "tcp", "version", ESPHOME_VERSION);
|
||||
#ifdef USE_API
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_PROMETHEUS
|
||||
MDNS.addService("prometheus-http", "tcp", WEBSERVER_PORT);
|
||||
#endif
|
||||
}
|
||||
void network_tick_mdns() {
|
||||
|
|
Loading…
Reference in a new issue