-
Notifications
You must be signed in to change notification settings - Fork 13.3k
LEA_mDNSResponder #5358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LEA_mDNSResponder #5358
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,21 @@ class ClientContext | |
} | ||
_connect_pending = 1; | ||
_op_start_time = millis(); | ||
/*LEA*/ | ||
//Serial.print("\nClientContext::connect (A)"); | ||
uint32_t nextPrint = (_op_start_time + 100); | ||
while ((millis() < (_op_start_time + _timeout_ms)) && | ||
(state() != ESTABLISHED)) { | ||
yield(); | ||
if (millis() > nextPrint) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same millis issue. Plus, I'm not sure what the purpose of this as we're not going to be printing anything anyway... Would suggest going back to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, this is just a q&d solution for the connection problems with the existing implementation! Wasn‘t supposed to be committed here, sorry! Just remove if possible! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this interesting. Does the current implementation have an issue? Does this resolve it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation relies on a break of the delay based on a call to _connected. When experimenting with BearSSL to create an Apple Push Notification Service, I found, that the Client::connect call stalled the whole system (without any timeout) because the supposed break of this delay never happened... My q&d workaround solved this problem for me... |
||
//Serial.printf("."); | ||
nextPrint = (millis() + 100); | ||
} | ||
} | ||
//Serial.println("\nClientContext::connect (B)"); | ||
// This delay will be interrupted by esp_schedule in the connect callback | ||
delay(_timeout_ms); | ||
//delay(_timeout_ms); | ||
/*LEA*/ | ||
_connect_pending = 0; | ||
if (!_pcb) { | ||
DEBUGV(":cabrt\r\n"); | ||
|
@@ -139,6 +152,7 @@ class ClientContext | |
abort(); | ||
return 0; | ||
} | ||
//Serial.println("ClientContext::connect (C)"); | ||
return 1; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,14 @@ | |
|
||
/* | ||
* Include the MDNSResponder (the library needs to be included also) | ||
* As LEA_MDNSResponder is experimantal in the ESP8266 environment currently, the | ||
* As LEA MDNSResponder is experimantal in the ESP8266 environment currently, the | ||
* legacy MDNSResponder is defaulted in th include file. | ||
* There are two ways to access LEA_MDNSResponder: | ||
* There are two ways to access LEA MDNSResponder: | ||
* 1. Prepend every declaration and call to global declarations or functions with the namespace, like: | ||
* 'LEA_MDNSResponder::MDNSResponder::hMDNSService hMDNSService;' | ||
* 'LEAmDNS::MDNSResponder::hMDNSService hMDNSService;' | ||
* This way is used in the example. But be careful, if the namespace declaration is missing | ||
* somewhere, the call might go to the legacy implementation... | ||
* 2. Open 'ESP8266mDNS.h' and set LEA_MDNSResponder to default. | ||
* 2. Open 'ESP8266mDNS.h' and set LEAmDNS to default. | ||
* | ||
*/ | ||
#include <ESP8266mDNS.h> | ||
|
@@ -54,19 +54,19 @@ | |
* Global defines and vars | ||
*/ | ||
|
||
#define TIMEZONE_OFFSET 1 // CET | ||
#define DST_OFFSET 1 // CEST | ||
#define TIMEZONE_OFFSET 1 // CET | ||
#define DST_OFFSET 1 // CEST | ||
#define UPDATE_CYCLE (1 * 1000) // every second | ||
|
||
#define SERVICE_PORT 80 // HTTP port | ||
#define SERVICE_PORT 80 // HTTP port | ||
|
||
|
||
const char* ssid = "............"; | ||
const char* password = "............"; | ||
const char* ssid = "............"; | ||
const char* password = "............"; | ||
|
||
char* pcHostDomain = 0; // Negociated host domain | ||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain | ||
LEA_MDNSResponder::MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder | ||
char* pcHostDomain = 0; // Negociated host domain | ||
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain | ||
LEAmDNS::MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder | ||
|
||
// TCP server at port 'SERVICE_PORT' will respond to HTTP requests | ||
WiFiServer server(SERVICE_PORT); | ||
|
@@ -77,13 +77,13 @@ WiFiServer server(SERVICE_PORT); | |
*/ | ||
const char* getTimeString(void) { | ||
|
||
static char acTimeString[32]; | ||
static char acTimeString[32]; | ||
time_t now = time(nullptr); | ||
ctime_r(&now, acTimeString); | ||
size_t stLength; | ||
while (((stLength = os_strlen(acTimeString))) && | ||
('\n' == acTimeString[stLength - 1])) { | ||
acTimeString[stLength - 1] = 0; // Remove trailing line break... | ||
acTimeString[stLength - 1] = 0; // Remove trailing line break... | ||
} | ||
return acTimeString; | ||
} | ||
|
@@ -131,8 +131,8 @@ bool setStationHostname(const char* p_pcHostname) { | |
* This can be triggered by calling MDNS.announce(). | ||
* | ||
*/ | ||
bool MDNSDynamicServiceTxtCallback(LEA_MDNSResponder::MDNSResponder* p_pMDNSResponder, | ||
const LEA_MDNSResponder::MDNSResponder::hMDNSService p_hService, | ||
bool MDNSDynamicServiceTxtCallback(LEAmDNS::MDNSResponder* p_pMDNSResponder, | ||
const LEAmDNS::MDNSResponder::hMDNSService p_hService, | ||
void* p_pUserdata) { | ||
Serial.println("MDNSDynamicServiceTxtCallback"); | ||
(void) p_pUserdata; | ||
|
@@ -156,9 +156,9 @@ bool MDNSDynamicServiceTxtCallback(LEA_MDNSResponder::MDNSResponder* p_pMDNSResp | |
* restarted via p_pMDNSResponder->setHostname(). | ||
* | ||
*/ | ||
bool MDNSProbeResultCallback(LEA_MDNSResponder::MDNSResponder* p_pMDNSResponder, | ||
bool MDNSProbeResultCallback(LEAmDNS::MDNSResponder* p_pMDNSResponder, | ||
const char* p_pcDomainName, | ||
const LEA_MDNSResponder::MDNSResponder::hMDNSService p_hService, | ||
const LEAmDNS::MDNSResponder::hMDNSService p_hService, | ||
bool p_bProbeResult, | ||
void* p_pUserdata) { | ||
Serial.println("MDNSProbeResultCallback"); | ||
|
@@ -188,7 +188,7 @@ bool MDNSProbeResultCallback(LEA_MDNSResponder::MDNSResponder* p_pMDNSResponder, | |
} | ||
else { | ||
// Change hostname, use '-' as divider between base name and index | ||
if (LEA_MDNSResponder::MDNSResponder::indexDomain(pcHostDomain, "-", 0)) { | ||
if (LEAmDNS::MDNSResponder::indexDomain(pcHostDomain, "-", 0)) { | ||
p_pMDNSResponder->setHostname(pcHostDomain); | ||
} | ||
else { | ||
|
@@ -283,10 +283,10 @@ void setup(void) { | |
setClock(); | ||
|
||
// Setup MDNS responder | ||
LEA_MDNSResponder::MDNS.setProbeResultCallback(MDNSProbeResultCallback, 0); | ||
LEAmDNS::MDNS.setProbeResultCallback(MDNSProbeResultCallback, 0); | ||
// Init the (currently empty) host domain string with 'esp8266' | ||
if ((!LEA_MDNSResponder::MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || | ||
(!LEA_MDNSResponder::MDNS.begin(pcHostDomain))) { | ||
if ((!LEAmDNS::MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || | ||
(!LEAmDNS::MDNS.begin(pcHostDomain))) { | ||
Serial.println("Error setting up MDNS responder!"); | ||
while (1) { // STOP | ||
delay(1000); | ||
|
@@ -311,7 +311,7 @@ void loop(void) { | |
} | ||
|
||
// Allow MDNS processing | ||
LEA_MDNSResponder::MDNS.update(); | ||
LEAmDNS::MDNS.update(); | ||
|
||
// Update time (if needed) | ||
static unsigned long ulNextTimeUpdate = UPDATE_CYCLE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue w/millis wraparound here, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I‘ve only now learned, that a millis() roll over happens every 72 minutes... Is there any alternative way? Maybe some tick counter?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m getting confused ... is the millis() rollover really hard-connected to the micros() rollover?? Otherwise it would be a rollover time of about 6 weeks... (haven’t seen an ESP running that long without running out of memory and needs a restart :-( ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LaborEtArs millis() does a rollover, so you can't compare the value returned by millis() against a delta. Instead, you have to compare a delta against a value. A delta (i.e.: a millis() - op_start_time) considers the case of rollover, so the result is always correct if you happen to be caught in the middle of a rollover. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, got the problem! |
||
|
@@ -320,7 +320,7 @@ void loop(void) { | |
if (hMDNSService) { | ||
// Just trigger a new MDNS announcement, this will lead to a call to | ||
// 'MDNSDynamicServiceTxtCallback', which will update the time TXT item | ||
LEA_MDNSResponder::MDNS.announce(); | ||
LEAmDNS::MDNS.announce(); | ||
} | ||
ulNextTimeUpdate = (millis() + UPDATE_CYCLE); // Set update 'timer' | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=ESP8266mDNS | ||
version=1.0 | ||
author=multiple, see files | ||
maintainer=LaborEtArs | ||
sentence=Creates a mDNS responder. | ||
paragraph=Creates a mDNS responder to ensure host domain uniqueness in local networks and to allow for mDNS service discovery and announcment. | ||
category=Communication | ||
url= | ||
architectures=esp8266 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do millis() compare like this. Need to subtract now from the start millis and compare to the timeout value. OTW you'll end up with bad things when millis or millis + timeout rolls over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh... the ClientContext changes wasn‘t supposed to be part of this... sorry!