mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-11-21 22:47:05 +00:00
Merge pull request #3770 from lihardyextreme/feature-mdns
feat: mDNS ESP32 - enable local network discovery over mDNS
This commit is contained in:
2 files changed
+34
No files matched your search
@@ -2,6 +2,11 @@
|
||||
#include <Mesh.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
#if defined(ENABLE_WIFI_INTERFACE) && defined(ENABLE_ESP_MDNS)
|
||||
#define HAS_ESP_MDNS
|
||||
#include <ESPmDNS.h>
|
||||
#endif
|
||||
|
||||
// Believe it or not, this std C function is busted on some platforms!
|
||||
static uint32_t _atoi(const char* sp) {
|
||||
uint32_t n = 0;
|
||||
@@ -270,6 +275,33 @@ void setup() {
|
||||
interface_manager.addInterface(InterfaceType::Ethernet, ðernet_interface);
|
||||
#endif
|
||||
|
||||
#ifdef HAS_ESP_MDNS
|
||||
String nodeName = the_mesh.getNodeName();
|
||||
String sanitizedNodeName;
|
||||
sanitizedNodeName.reserve(nodeName.length());
|
||||
for (size_t i = 0; i < nodeName.length(); ++i) {
|
||||
const char c = nodeName[i];
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') || c == '-' || c == '_') {
|
||||
sanitizedNodeName += c;
|
||||
}
|
||||
}
|
||||
|
||||
String mdnsName = "meshcore_";
|
||||
mdnsName += sanitizedNodeName;
|
||||
if (!MDNS.begin(mdnsName.c_str())) {
|
||||
WIFI_DEBUG_PRINTLN("mDNS failed to start!");
|
||||
} else {
|
||||
MDNS.addService("meshcore", "tcp", TCP_PORT);
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "node-name", the_mesh.getNodeName());
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "firmware-version", FIRMWARE_VERSION);
|
||||
String protocol; protocol+=FIRMWARE_VER_CODE;
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "protocol-version", protocol.c_str());
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "build-date", __DATE__);
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "build-time", __TIME__);
|
||||
}
|
||||
#endif
|
||||
|
||||
// add hardware serial interface
|
||||
#if defined(SERIAL_RX)
|
||||
companion_serial.setPins(SERIAL_RX, SERIAL_TX);
|
||||
|
||||
@@ -212,6 +212,7 @@ build_flags =
|
||||
-D BLE_DEBUG_LOGGING=1
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D ENABLE_WIFI_INTERFACE
|
||||
-D ENABLE_ESP_MDNS
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
; -D MESH_DEBUG=1
|
||||
build_src_filter = ${heltec_v4_oled.build_src_filter}
|
||||
@@ -231,6 +232,7 @@ build_flags =
|
||||
${heltec_v4_oled.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D ENABLE_WIFI_INTERFACE
|
||||
-D ENABLE_ESP_MDNS
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
|
||||
Reference in new issue
Block a user