Skip to content

Commit ecb38eb

Browse files
committed
Add MDNS support.
1 parent 4b1817d commit ecb38eb

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

Firmware/RTK_Surveyor/Form.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ void startWebServer(bool startWiFi, int httpPort)
1717
if (wifiStartAP() == false) //Exits calling wifiConnect()
1818
return;
1919

20+
if (settings.mdnsEnable == true)
21+
{
22+
if (MDNS.begin("rtk") == false) //This should make the module findable from 'rtk.local' in browser
23+
log_d("Error setting up MDNS responder!");
24+
else
25+
MDNS.addService("http", "tcp", 80); //Add service to MDNS-SD
26+
}
27+
2028
incomingSettings = (char*)malloc(AP_CONFIG_SETTING_SIZE);
2129
memset(incomingSettings, 0, AP_CONFIG_SETTING_SIZE);
2230

@@ -836,6 +844,8 @@ void createSettingsString(char* newSettings)
836844
else
837845
stringRecord(newSettings, "minCNO", settings.minCNO_F9P);
838846

847+
stringRecord(newSettings, "mdnsEnable", settings.mdnsEnable);
848+
839849
//Add ECEF and Geodetic station data to the end of settings
840850
for (int index = 0; index < COMMON_COORDINATES_MAX_STATIONS ; index++) //Arbitrary 50 station limit
841851
{
@@ -1237,6 +1247,8 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
12371247
for (int i = strlen(settingValueStr); i < 5; i++)
12381248
settings.ntpReferenceId[i] = 0;
12391249
}
1250+
else if (strcmp(settingName, "mdnsEnable") == 0)
1251+
settings.mdnsEnable = settingValueBool;
12401252

12411253
//Unused variables - read to avoid errors
12421254
else if (strcmp(settingName, "measurementRateSec") == 0) {}

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ void recordSystemSettingsToFile(File * settingsFile)
401401
settingsFile->printf("%s=%d\r\n", "ntpRootDispersion", settings.ntpRootDispersion);
402402
settingsFile->printf("%s=%s\r\n", "ntpReferenceId", settings.ntpReferenceId);
403403
}
404+
405+
settingsFile->printf("%s=%d\r\n", "mdnsEnable", settings.mdnsEnable);
406+
404407
}
405408

406409
//Given a fileName, parse the file and load the given settings struct
@@ -1229,6 +1232,8 @@ bool parseLine(char* str, Settings *settings)
12291232
settings->updateZEDSettings = true;
12301233
}
12311234
}
1235+
else if (strcmp(settingName, "mdnsEnable") == 0)
1236+
settings->mdnsEnable = d;
12321237

12331238
//Check for bulk settings (WiFi credentials, constellations, message rates, ESPNOW Peers)
12341239
//Must be last on else list

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ char logFileName[sizeof("SFE_Facet_L-Band_230101_120101.ubx_plusExtraSpace")] =
191191
#include <WiFiClientSecure.h> //Built-in.
192192
#include <PubSubClient.h> //http://librarymanager/All#PubSubClient_MQTT_Lightweight by Nick O'Leary v2.8.0 Used for MQTT obtaining of keys
193193
#include "ESP32OTAPull.h" //http://librarymanager/All#ESP-OTA-Pull Used for getting latest firmware OTA
194+
#include <ESPmDNS.h> //Built-in.
194195

195196
#include "esp_wifi.h" //Needed for esp_wifi_set_protocol()
196197

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,13 @@ void wifiStop()
336336
systemPrintln("TCP Server offline");
337337
}
338338

339+
if (settings.mdnsEnable == true)
340+
MDNS.end();
341+
339342
wifiSetState(WIFI_OFF);
340343

341344
wifiConnectionAttempts = 0; //Reset the timeout
342345

343-
344346
//If ESP-Now is active, change protocol to only Long Range and re-start WiFi
345347
if (espnowState > ESPNOW_OFF)
346348
{
@@ -435,6 +437,17 @@ bool wifiConnect(unsigned long timeout)
435437
int wifiResponse = wifiMulti.run(timeout);
436438
if (wifiResponse == WL_CONNECTED)
437439
{
440+
if (settings.enableTcpClient == true || settings.enableTcpServer == true)
441+
{
442+
if (settings.mdnsEnable == true)
443+
{
444+
if (MDNS.begin("rtk") == false) //This should make the module findable from 'rtk.local' in browser
445+
log_d("Error setting up MDNS responder!");
446+
else
447+
MDNS.addService("http", "tcp", settings.wifiTcpPort); //Add service to MDNS
448+
}
449+
}
450+
438451
systemPrintln();
439452
return true;
440453
}

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ void menuWiFi()
409409
if (settings.enableTcpServer == true || settings.enableTcpClient == true)
410410
systemPrintf("p) WiFi TCP Port: %ld\r\n", settings.wifiTcpPort);
411411

412+
systemPrint("m) MDNS: ");
413+
systemPrintf("%s\r\n", settings.mdnsEnable ? "Enabled" : "Disabled");
414+
412415
systemPrintln("x) Exit");
413416

414417
byte incoming = getCharacterNumber();
@@ -473,6 +476,10 @@ void menuWiFi()
473476
}
474477
}
475478
}
479+
else if (incoming == 'm')
480+
{
481+
settings.mdnsEnable ^= 1;
482+
}
476483
else if (incoming == 'x')
477484
break;
478485
else if (incoming == INPUT_RESPONSE_GETCHARACTERNUMBER_EMPTY)

Firmware/RTK_Surveyor/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ typedef struct {
841841
uint16_t lbandFixTimeout_seconds = 180; //Number of seconds of no L-Band fix before resetting ZED
842842
int16_t minCNO_F9P = 6; //Minimum satellite signal level for navigation. ZED-F9P default is 6 dBHz
843843
int16_t minCNO_F9R = 20; //Minimum satellite signal level for navigation. ZED-F9R default is 20 dBHz
844+
bool mdnsEnable = false; //Allows locating of device from browser address 'rtk.local'
844845
} Settings;
845846
Settings settings;
846847
const Settings defaultSettings = Settings();

0 commit comments

Comments
 (0)