Skip to content

Commit 8b27047

Browse files
sidohigrr
authored andcommitted
Put SSDP constants in progmem (#3142)
* Put constant strings in progmem * strlen -> strlen_P
1 parent 1d41859 commit 8b27047

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ static const IPAddress SSDP_MULTICAST_ADDR(239, 255, 255, 250);
5656

5757

5858

59-
static const char* _ssdp_response_template =
59+
static const char _ssdp_response_template[] PROGMEM =
6060
"HTTP/1.1 200 OK\r\n"
6161
"EXT:\r\n";
6262

63-
static const char* _ssdp_notify_template =
63+
static const char _ssdp_notify_template[] PROGMEM =
6464
"NOTIFY * HTTP/1.1\r\n"
6565
"HOST: 239.255.255.250:1900\r\n"
6666
"NTS: ssdp:alive\r\n";
6767

68-
static const char* _ssdp_packet_template =
68+
static const char _ssdp_packet_template[] PROGMEM =
6969
"%s" // _ssdp_response_template / _ssdp_notify_template
7070
"CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL
7171
"SERVER: Arduino/1.0 UPNP/1.1 %s/%s\r\n" // _modelName, _modelNumber
@@ -74,7 +74,7 @@ static const char* _ssdp_packet_template =
7474
"LOCATION: http://%u.%u.%u.%u:%u/%s\r\n" // WiFi.localIP(), _port, _schemaURL
7575
"\r\n";
7676

77-
static const char* _ssdp_schema_template =
77+
static const char _ssdp_schema_template[] PROGMEM =
7878
"HTTP/1.1 200 OK\r\n"
7979
"Content-Type: text/xml\r\n"
8080
"Connection: close\r\n"
@@ -201,9 +201,12 @@ void SSDPClass::_send(ssdp_method_t method){
201201
char buffer[1460];
202202
uint32_t ip = WiFi.localIP();
203203

204-
int len = snprintf(buffer, sizeof(buffer),
204+
char valueBuffer[strlen_P(_ssdp_notify_template)+1];
205+
strcpy_P(valueBuffer, (method == NONE)?_ssdp_response_template:_ssdp_notify_template);
206+
207+
int len = snprintf_P(buffer, sizeof(buffer),
205208
_ssdp_packet_template,
206-
(method == NONE)?_ssdp_response_template:_ssdp_notify_template,
209+
valueBuffer,
207210
SSDP_INTERVAL,
208211
_modelName, _modelNumber,
209212
_uuid,
@@ -240,7 +243,9 @@ void SSDPClass::_send(ssdp_method_t method){
240243

241244
void SSDPClass::schema(WiFiClient client){
242245
uint32_t ip = WiFi.localIP();
243-
client.printf(_ssdp_schema_template,
246+
char buffer[strlen_P(_ssdp_schema_template)+1];
247+
strcpy_P(buffer, _ssdp_schema_template);
248+
client.printf(buffer,
244249
IP2STR(&ip), _port,
245250
_deviceType,
246251
_friendlyName,

0 commit comments

Comments
 (0)