mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2025-12-13 19:12:10 +01:00
Increase the interval for SSDP keep alives.
This commit is contained in:
parent
01895d0ec5
commit
da551f3385
4 changed files with 28 additions and 24 deletions
|
|
@ -63,7 +63,7 @@ void Network::loop() {
|
||||||
}
|
}
|
||||||
if(settings.ssdpBroadcast) {
|
if(settings.ssdpBroadcast) {
|
||||||
if(!SSDP.isStarted) SSDP.begin();
|
if(!SSDP.isStarted) SSDP.begin();
|
||||||
SSDP.loop();
|
if(SSDP.isStarted) SSDP.loop();
|
||||||
}
|
}
|
||||||
else if(!settings.ssdpBroadcast && SSDP.isStarted) SSDP.end();
|
else if(!settings.ssdpBroadcast && SSDP.isStarted) SSDP.end();
|
||||||
mqtt.loop();
|
mqtt.loop();
|
||||||
|
|
@ -210,7 +210,7 @@ void Network::setConnected(conn_types connType) {
|
||||||
MDNS.addServiceTxt("espsomfy_rts", "tcp", "version", String(settings.fwVersion.name));
|
MDNS.addServiceTxt("espsomfy_rts", "tcp", "version", String(settings.fwVersion.name));
|
||||||
}
|
}
|
||||||
if(settings.ssdpBroadcast) {
|
if(settings.ssdpBroadcast) {
|
||||||
if(SSDP.begin()) Serial.println("SSDP Client Started...");
|
SSDP.begin();
|
||||||
}
|
}
|
||||||
else if(SSDP.isStarted) SSDP.end();
|
else if(SSDP.isStarted) SSDP.end();
|
||||||
this->emitSockets();
|
this->emitSockets();
|
||||||
|
|
|
||||||
42
SSDP.cpp
42
SSDP.cpp
|
|
@ -176,6 +176,10 @@ bool SSDPClass::begin() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this->bootId = Timestamp::epoch();
|
this->bootId = Timestamp::epoch();
|
||||||
|
if(this->bootId < 1000) {
|
||||||
|
this->isStarted = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this->configId = (settings.fwVersion.major * 100) + (settings.fwVersion.minor * 10) + settings.fwVersion.build;
|
this->configId = (settings.fwVersion.major * 100) + (settings.fwVersion.minor * 10) + settings.fwVersion.build;
|
||||||
_server.onPacket([](void * arg, AsyncUDPPacket& packet) { ((SSDPClass*)(arg))->_processRequest(packet); }, this);
|
_server.onPacket([](void * arg, AsyncUDPPacket& packet) { ((SSDPClass*)(arg))->_processRequest(packet); }, this);
|
||||||
if(!_server.listenMulticast(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT)) {
|
if(!_server.listenMulticast(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT)) {
|
||||||
|
|
@ -202,8 +206,10 @@ void SSDPClass::end() {
|
||||||
#ifdef DEBUG_SSDP
|
#ifdef DEBUG_SSDP
|
||||||
DEBUG_SSDP.printf(PSTR("SSDP end ...\n "));
|
DEBUG_SSDP.printf(PSTR("SSDP end ...\n "));
|
||||||
#endif
|
#endif
|
||||||
|
if(this->_server.connected()) {
|
||||||
this->_sendByeBye();
|
this->_sendByeBye();
|
||||||
this->_server.close();
|
this->_server.close();
|
||||||
|
}
|
||||||
this->isStarted = false;
|
this->isStarted = false;
|
||||||
// Clear out the last notified so if the user starts us up again it will notify
|
// Clear out the last notified so if the user starts us up again it will notify
|
||||||
// that we exist again.
|
// that we exist again.
|
||||||
|
|
@ -447,39 +453,37 @@ void SSDPClass::_sendResponse(IPAddress addr, uint16_t port, const char *buff) {
|
||||||
_server.writeTo((const uint8_t *)buff, strlen(buff), addr, port);
|
_server.writeTo((const uint8_t *)buff, strlen(buff), addr, port);
|
||||||
}
|
}
|
||||||
void SSDPClass::_sendNotify() {
|
void SSDPClass::_sendNotify() {
|
||||||
//Serial.printf("sendNotify %d\n", this->m_cdeviceTypes);
|
|
||||||
//if(!this->_server.connected()) return;
|
|
||||||
for(uint8_t i = 0; i < this->m_cdeviceTypes; i++) {
|
for(uint8_t i = 0; i < this->m_cdeviceTypes; i++) {
|
||||||
UPNPDeviceType *dev = &this->deviceTypes[i];
|
UPNPDeviceType *dev = &this->deviceTypes[i];
|
||||||
if(i == 0 && (strlen(dev->deviceType) == 0 || !dev->isActive)) Serial.printf("The device type is empty: %s\n", dev->isActive ? "true" : "false");
|
if(i == 0 && (strlen(dev->deviceType) == 0 || !dev->isActive)) Serial.printf("The device type is empty: %s\n", dev->isActive ? "true" : "false");
|
||||||
if(strlen(dev->deviceType) > 0 && dev->isActive) {
|
if(strlen(dev->deviceType) > 0 && dev->isActive) {
|
||||||
uint16_t elapsed = (millis() - dev->lastNotified);
|
unsigned long elapsed = (millis() - dev->lastNotified);
|
||||||
if(!dev->lastNotified || (elapsed * 4) > (this->_interval * 1000)) {
|
if(!dev->lastNotified || (elapsed * 5) > (this->_interval * 1000)) {
|
||||||
#ifdef DEBUG_SSDP
|
|
||||||
DEBUG_SSDP.print(dev->deviceType);
|
|
||||||
DEBUG_SSDP.print(" Time since last notified: ");
|
|
||||||
DEBUG_SSDP.print(elapsed);
|
|
||||||
DEBUG_SSDP.print("msec ");
|
|
||||||
DEBUG_SSDP.print(this->_interval);
|
|
||||||
DEBUG_SSDP.println("msec");
|
|
||||||
#endif
|
|
||||||
this->_sendNotify(dev, i == 0);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
else {
|
|
||||||
#ifdef DEBUG_SSDP
|
#ifdef DEBUG_SSDP
|
||||||
DEBUG_SSDP.print(dev->deviceType);
|
DEBUG_SSDP.print(dev->deviceType);
|
||||||
DEBUG_SSDP.print(" Time since last notified: ");
|
DEBUG_SSDP.print(" Time since last notified: ");
|
||||||
DEBUG_SSDP.print(elapsed/1000);
|
DEBUG_SSDP.print(elapsed/1000);
|
||||||
DEBUG_SSDP.print("msec ");
|
DEBUG_SSDP.print("sec ");
|
||||||
DEBUG_SSDP.print(this->_interval);
|
DEBUG_SSDP.print(this->_interval);
|
||||||
DEBUG_SSDP.println("msec -- SKIPPING");
|
DEBUG_SSDP.println("sec");
|
||||||
#endif
|
#endif
|
||||||
|
this->_sendNotify(dev, i == 0);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
#ifdef DEBUG_SSDP
|
||||||
|
DEBUG_SSDP.print(dev->deviceType);
|
||||||
|
DEBUG_SSDP.print(" Time since last notified: ");
|
||||||
|
DEBUG_SSDP.print(elapsed/1000);
|
||||||
|
DEBUG_SSDP.print("sec ");
|
||||||
|
DEBUG_SSDP.print(this->_interval);
|
||||||
|
DEBUG_SSDP.println("sec -- SKIPPING");
|
||||||
|
#endif
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void SSDPClass::_sendNotify(const char *msg) {
|
void SSDPClass::_sendNotify(const char *msg) {
|
||||||
//_server->append(msg, strlen(msg));
|
//_server->append(msg, strlen(msg));
|
||||||
//_server->send(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT);
|
//_server->send(IPAddress(SSDP_MULTICAST_ADDR), SSDP_PORT);
|
||||||
|
|
@ -528,7 +532,7 @@ void SSDPClass::_sendNotify(UPNPDeviceType *d, bool root) {
|
||||||
pbuff,
|
pbuff,
|
||||||
this->_interval,
|
this->_interval,
|
||||||
d->getUSN(response_types_t::uuid),
|
d->getUSN(response_types_t::uuid),
|
||||||
"NT", d->uuid,
|
"NT", d->getUSN(response_types_t::uuid),
|
||||||
ip[0], ip[1], ip[2], ip[3], _port, d->schemaURL, this->bootId, this->configId);
|
ip[0], ip[1], ip[2], ip[3], _port, d->schemaURL, this->bootId, this->configId);
|
||||||
this->_sendNotify(buffer);
|
this->_sendNotify(buffer);
|
||||||
// Send 1 for deviceType
|
// Send 1 for deviceType
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue