Skip to content

Commit

Permalink
Add MDNS.update()
Browse files Browse the repository at this point in the history
  • Loading branch information
boblemaire committed Apr 27, 2022
1 parent 3ba911c commit 86c366e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Firmware/IotaWatt/IotaWatt.h
Expand Up @@ -32,8 +32,7 @@
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include "ESP8266mDNS.h"
#include <ESP8266LLMNR.h>
// #include <ESP8266LLMNR.h>
#include <DNSServer.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
Expand Down Expand Up @@ -80,7 +79,6 @@ extern WiFiClient WifiClient;
extern WiFiManager wifiManager;
extern ESP8266WebServer server;
extern DNSServer DNS_server;
extern MDNSResponder MDNS;
extern IotaLog Current_log;
extern IotaLog History_log;
extern IotaLog *Export_log;
Expand Down
10 changes: 6 additions & 4 deletions Firmware/IotaWatt/WiFi.cpp
@@ -1,4 +1,6 @@
#include "IotaWatt.h"
#include "ESP8266mDNS.h"
#include <ESP8266LLMNR.h>

struct tcp_pcb {
uint32_t ip_pcba;
Expand All @@ -24,18 +26,16 @@ uint32_t WiFiService(struct serviceBlock* _serviceBlock) {
localIP = WiFi.localIP();
gatewayIP = WiFi.gatewayIP();
subnetMask = WiFi.subnetMask();
WiFi.hostname(deviceName);
log("WiFi connected. SSID=%s, IP=%s, channel=%d, RSSI %ddb", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str(), WiFi.channel(), WiFi.RSSI());
}
if( ! mDNSstarted){
if( !MDNS.isRunning()){
if (MDNS.begin(deviceName)) {
MDNS.addService("http", "tcp", 80);
log("MDNS responder started for hostname %s", deviceName);
mDNSstarted = true;
}
}
if( ! LLMNRstarted){
if (LLMNR.begin(deviceName)){
log("LLMNR responder started for hostname %s", deviceName);
LLMNRstarted = true;
}
}
Expand All @@ -46,6 +46,7 @@ uint32_t WiFiService(struct serviceBlock* _serviceBlock) {
trace(T_WiFi,2);
wifiConnectTime = 0;
lastDisconnect = UTCtime();
MDNS.close();
log("WiFi disconnected.");
}
else if((UTCtime() - lastDisconnect) >= restartInterval){
Expand All @@ -54,6 +55,7 @@ uint32_t WiFiService(struct serviceBlock* _serviceBlock) {
ESP.restart();
}
}
MDNS.update();

// Check for degraded heap.

Expand Down
1 change: 0 additions & 1 deletion Firmware/IotaWatt/common.cpp
Expand Up @@ -126,7 +126,6 @@

WiFiClient WifiClient;
DNSServer DNS_server;
MDNSResponder MDNS;
IotaLog Current_log(256,5,365,32); // current data log (1 year)
IotaLog History_log(256,60,3652,48); // history data log (10 years)
IotaLog *Export_log = nullptr; // Optional export log
Expand Down

0 comments on commit 86c366e

Please sign in to comment.