Skip to content

Commit 344c449

Browse files
earlephilhowerdevyte
authored andcommitted
[SSDP] add schema(Print &) const (esp8266#6798)
* [SSDP] add `schema(Print &) const` Supercedes esp8266#2806 Make SSDP::schema(WiFiClient&) use a by-ref (reduce stack use) Add a SSDP::schema(Print&) From @Palatis' original PR: useful when using AsyncWebServer. * Use ip.toString, only export Print& schema interface Because WiFiClient inherits a Print interface, replace the ::schema(WiFiClient&) with ::schema(Print&) which is source compatible with existing code and allows the functionality requested in the initial PR. Use ip.toString() in the templates instead of breaking up the octets of the address. * Fix compile errors and backwards compatibility
1 parent 9b96f53 commit 344c449

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const char _ssdp_packet_template[] PROGMEM =
7373
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
7474
"USN: %s\r\n" // _uuid
7575
"%s: %s\r\n" // "NT" or "ST", _deviceType
76-
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
76+
"LOCATION: http://%s:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
7777
"\r\n";
7878

7979
static const char _ssdp_schema_template[] PROGMEM =
@@ -88,7 +88,7 @@ static const char _ssdp_schema_template[] PROGMEM =
8888
"<major>1</major>"
8989
"<minor>0</minor>"
9090
"</specVersion>"
91-
"<URLBase>http://%u.%u.%u.%u:%u/</URLBase>" // WiFi.localIP(), _port
91+
"<URLBase>http://%s:%u/</URLBase>" // WiFi.localIP(), _port
9292
"<device>"
9393
"<deviceType>%s</deviceType>"
9494
"<friendlyName>%s</friendlyName>"
@@ -247,7 +247,7 @@ void SSDPClass::_send(ssdp_method_t method) {
247247
_uuid,
248248
(method == NONE) ? "ST" : "NT",
249249
(_st_is_uuid) ? _uuid : _deviceType,
250-
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
250+
ip.toString().c_str(), _port, _schemaURL
251251
);
252252

253253
_server->append(buffer, len);
@@ -276,12 +276,12 @@ void SSDPClass::_send(ssdp_method_t method) {
276276
_server->send(remoteAddr, remotePort);
277277
}
278278

279-
void SSDPClass::schema(WiFiClient client) {
279+
void SSDPClass::schema(Print &client) const {
280280
IPAddress ip = WiFi.localIP();
281281
char buffer[strlen_P(_ssdp_schema_template) + 1];
282282
strcpy_P(buffer, _ssdp_schema_template);
283283
client.printf(buffer,
284-
ip[0], ip[1], ip[2], ip[3], _port,
284+
ip.toString().c_str(), _port,
285285
_deviceType,
286286
_friendlyName,
287287
_presentationURL,

libraries/ESP8266SSDP/ESP8266SSDP.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class SSDPClass{
6262
~SSDPClass();
6363
bool begin();
6464
void end();
65-
void schema(WiFiClient client);
65+
void schema(WiFiClient client) const { schema((Print&)std::ref(client)); }
66+
void schema(Print &print) const;
6667
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
6768
void setDeviceType(const char *deviceType);
6869

0 commit comments

Comments
 (0)