Skip to content

Commit 971bd9b

Browse files
author
Eric Wilkison
committed
Change addServiceTxt to key/val pair
1 parent 758107f commit 971bd9b

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

libraries/ESP8266mDNS/ESP8266mDNS.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ void MDNSResponder::update() {
145145

146146

147147

148-
bool MDNSResponder::addServiceTxt(char *name, char *proto, char *txt){
148+
bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){
149149
MDNSService* servicePtr;
150150

151151
//DEBUG Serial.printf("Starting addServiceTxt(name=%s,proto=%s,txt=%s)\n", name,proto,txt);
152152
//DEBUG delay(20);
153-
uint8_t txtLen = os_strlen(txt) + 1; //One accounts for length byte added when building the txt responce
153+
uint8_t txtLen = os_strlen(key) + os_strlen(value) + 1; // Add one for equals sign
154+
txtLen+=1; //accounts for length byte added when building the txt responce
154155
if ( txtLen > 128) return false;
155156
//Find the service
156157
for (servicePtr = _services; servicePtr; servicePtr = servicePtr->_next) {
@@ -161,7 +162,9 @@ bool MDNSResponder::addServiceTxt(char *name, char *proto, char *txt){
161162
//DEBUG Serial.printf("found match service name=%s,proto=%s\n", servicePtr->_name,servicePtr->_proto);
162163
//DEBUG delay(20);
163164
struct MDNSTxt *newtxt = (struct MDNSTxt*)(os_malloc(sizeof(struct MDNSTxt)));
164-
os_strcpy(newtxt->_txt, txt);
165+
os_strcpy(newtxt->_txt, key);
166+
os_strcat(newtxt->_txt, "=");
167+
os_strcat(newtxt->_txt, value);
165168
newtxt->_next = 0;
166169
if(servicePtr->_txts == 0) { //no services have been added
167170
servicePtr->_txts = newtxt;
@@ -469,19 +472,19 @@ void MDNSResponder::_parsePacket(){
469472

470473
void MDNSResponder::enableArduino(uint16_t port, bool auth){
471474

472-
char boardName[64];
473-
const char *boardExtra = "board=";
474-
os_sprintf(boardName, "%s%s", boardExtra, ARDUINO_BOARD);
475+
// char boardName[64];
476+
// const char *boardExtra = "board=";
477+
// os_sprintf(boardName, "%s%s", boardExtra, ARDUINO_BOARD);
475478

476-
char authUpload[16];
477-
const char *authUploadExtra = "auth_upload=";
478-
os_sprintf(authUpload, "%s%s", authUploadExtra, (auth) ? "yes":"no");
479+
// char authUpload[16];
480+
// const char *authUploadExtra = "auth_upload=";
481+
// os_sprintf(authUpload, "%s%s", authUploadExtra, (auth) ? "yes":"no");
479482

480483
addService("arduino", "tcp", port);
481-
addServiceTxt("arduino", "tcp", "tcp_check=no");
482-
addServiceTxt("arduino", "tcp", "ssh_upload=no");
483-
addServiceTxt("arduino", "tcp", (const char*)boardName);
484-
addServiceTxt("arduino", "tcp", (const char*)authUpload);
484+
addServiceTxt("arduino", "tcp", "tcp_check", "no");
485+
addServiceTxt("arduino", "tcp", "ssh_upload", "no");
486+
addServiceTxt("arduino", "tcp", "board", ARDUINO_BOARD);
487+
addServiceTxt("arduino", "tcp", "auth_upload", (auth) ? "yes":"no");
485488
}
486489

487490
void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint16_t port){

libraries/ESP8266mDNS/ESP8266mDNS.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class MDNSResponder {
8585
addService(service.c_str(), proto.c_str(), port);
8686
}
8787

88-
bool addServiceTxt(char *name, char *proto, char *txt);
89-
void addServiceTxt(const char *name, const char *proto, const char *txt){
90-
addServiceTxt((char *)name, (char *)proto, (char *)txt);
88+
bool addServiceTxt(char *name, char *proto, char * key, char * value);
89+
void addServiceTxt(const char *name, const char *proto, const char *key,const char * value){
90+
addServiceTxt((char *)name, (char *)proto, (char *)key, (char *)value);
9191
}
92-
void addServiceTxt(String name, String proto, String txt){
93-
addServiceTxt(name.c_str(), proto.c_str(), txt.c_str());
92+
void addServiceTxt(String name, String proto, String key, String value){
93+
addServiceTxt(name.c_str(), proto.c_str(), key.c_str(), value.c_str());
9494
}
9595

9696
void enableArduino(uint16_t port, bool auth=false);

0 commit comments

Comments
 (0)