added mDNS

This commit is contained in:
Martin Bauer 2020-08-15 18:18:54 +02:00
parent ae341f91b3
commit 92e7399fe4
2 changed files with 34 additions and 10 deletions

View File

@ -10,9 +10,10 @@
// ------------------------------------------ WiFi ---------------------------------------------------------------------------------
const char *CONFIG_WIFI_SSID = "WLAN";
//const char *CONFIG_WIFI_SSID = "RepeaterWZ";
//const char *CONFIG_WIFI_SSID = "MartinHandy";
const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN";
const char *CONFIG_HOSTNAME = "smartswim";
//const char *CONFIG_WIFI_PASSWORD = "35cbbd203afe";
const char *CONFIG_HOSTNAME = "swimtracker";
// ------------------------------------- Hardware & Measurement Settings ------------------------------------------------------------

View File

@ -18,6 +18,7 @@
#include "WebsocketServer.h"
#include "esp_https_ota.h"
#include "ESPmDNS.h"
using Session_T = SimpleMeasurementSession<MeasurementT, CONFIG_SESSION_MAX_SIZE>;
SessionManager<Session_T> sessionManager(CONFIG_SCALE_DOUT_PIN, CONFIG_SCALE_SCK_PIN, CONFIG_TARE_AVG_COUNT);
@ -207,6 +208,32 @@ String getIdSuffix()
return String(baseMacChr);
}
void mdnsSetup(const String &fullHostname)
{
if (!MDNS.begin(fullHostname.c_str()))
{
Serial.println("Error setting up MDNS responder!");
while (1)
{
delay(1000);
}
}
Serial.printf("mDNS started %s\n", fullHostname.c_str());
MDNS.addService("_swimtracker", "tcp", 80);
/*
// mDNS
esp_err_t err = mdns_init();
if (err)
Serial.printf("MDNS Init failed: %d\n", err);
else {
Serial.printf("Setting up zeroconf hostname %s\n", fullHostname.c_str());
mdns_hostname_set(fullHostname.c_str());
mdns_service_add(NULL, "_swimtracker", "_tcp", 81, NULL, 0);
mdns_instance_name_set("SwimTracker by bauer.tech");
}
*/
}
void setup()
{
// Serial
@ -244,17 +271,13 @@ void setup()
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
Serial.println("Running version new24!"); // todo
mdnsSetup(fullHostname);
// Session
sessionManager.begin();
// HTTP & Websocket server
httpSetup(&sessionManager);
Serial.printf("Offset %d\n", sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t));
Serial.printf("Size %d\n", sizeof(esp_app_desc_t));
webSocketServer.begin();
}