Skip to content
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

add support for TXT records in query responses #3107

Closed
wants to merge 8 commits into from

Conversation

mblythe86
Copy link
Contributor

Needed this functionality for a project I'm working on, figured I'd contribute it back.

Not sure whether all of the txt record accessor functions are necessary...I'll let you folks be the judge.

@igrr
Copy link
Member

igrr commented May 8, 2017

@me-no-dev if you can spare a bit of time to take a look at this, that would be great!

@philbowles
Copy link

Perfect Timing, this is EXACTLY what I need for my latest: to allow my IOT H/W to autoconfigure. However, I think you may have a bug in there...

So - I'm a bit of a newbie with github and how it works, so be kind...anyway I grabbed your .h and .cpp files and replaced the standard implemetation and recompiled after adding #define MDNS_DEBUG RX

I have a NODE-RED bonjour announcement on "_toiiot._tcp" it has two TXT records, "basename":"lapique","version":"1.0" which are seen by bonjour browser etc they are there!

I tried using the snippet from your example which iterates over the TXT by index, but no joy. It appears that the txt String pointers are null.

OTOH "by keyword" works fine. So I'm verry happy and shall continue with that method, as its what I wanted anyway, and it works for me, but I thought youd like to know. Many thanks for this, it has saved me days of probable late nights and swearing!

The failing code:


    Serial.print("\nConnected to ");
    Serial.print(WiFi.gatewayIP());
    Serial.print(" as ");
    Serial.println(WiFi.localIP());
//
// find mqtt host
    int n=MDNS.queryService("toiiot", "tcp");
    if(n==1){ //all ok
      Serial.print("Chez ToiioT Controller: ");
      Serial.println(MDNS.hostname(0));
      Serial.println(MDNS.IP(0));
      Serial.println(MDNS.port(0));
      // now get basename etc:
      Serial.print("USING MBLYTHE86 'fork' of mDNS");

      int num = MDNS.numTxt(0);
      Serial.print("  nTXT=");
      Serial.println(num);
      Serial.println("by keyword works");
      Serial.println(MDNS.txt(0,"basename"));
      Serial.println(MDNS.txt(0,"version"));
      Serial.println("by index doesn't");
      Serial.println(MDNS.txt(0,0));
      Serial.println(MDNS.txt(0,1));
      Serial.println("String ptrs  are null");
      Serial.printf(" 0: %s ?\n",MDNS.txt(0,0).c_str());
      Serial.printf(" 1: %s ?\n",MDNS.txt(0,1).c_str());
     int i=0;
     
        for(int j=0; j < num; j++){
          Serial.printf("%d ",j);
          Serial.println(MDNS.txt(i,j));
          }
        Serial.println("  ENDTXT");

And the ouput:

.....MDNS listening

Reading answers RX: REQ, ID:0, Q:0, A:5, NS:0, ADD:0
7 _toiiot
found matching service: toiiot
4 _tcp
5 local
type: 000c rdlength: 40
PTR 40 %Chez ToiioT controller on raspberrypi⸮
type: 0010 rdlength: 29
16:62 61 73 65 6e 61 6d 65 3d 6c 61 70 69 71 75 65
basename=lapique
11:76 65 72 73 69 6f 6e 3d 31 2e 30
version=1.0
type: 0021 rdlength: 20
SRV 11 72 61 73 70 62 65 72 72 79 70 69
raspberrypi
type: 001c rdlength: 16
Ignoring unsupported type 8d
type: 0001 rdlength: 4
All answers parsed, adding to _answers list..
Chez ToiioT Controller: raspberrypi
192.168.1.4
1880
USING MBLYTHE86 'fork' of mDNS nTXT=2
by keyword works
lapique
1.0
by index doesn't

String ptrs are null
0: ?
1: ?
0
1
ENDTXT

@mblythe86
Copy link
Contributor Author

Oops! I forgot to "return" in the default case of one of my functions. I'll fix that and update the pull request soon-ish.

@codecov-io
Copy link

codecov-io commented Jun 14, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@40c159f). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #3107   +/-   ##
========================================
  Coverage          ?   27.6%           
========================================
  Files             ?      20           
  Lines             ?    3655           
  Branches          ?     678           
========================================
  Hits              ?    1009           
  Misses            ?    2468           
  Partials          ?     178

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40c159f...9c16683. Read the comment docs.

@mblythe86
Copy link
Contributor Author

I'm still having problems when I use this library with my changes...based on some debugging print statements I've added, I have a memory leak somewhere. I'll need to chase it down.

@mblythe86
Copy link
Contributor Author

ok, should be good now!

@beegee-tokyo
Copy link

Hope this gets merged soon. I need this functionality as well.

@horihiro
Copy link

When will be this feature released?

I hope to use this soon.

@horihiro
Copy link

I hope that this PR will be merged in 2.4.2 ...

@devyte
Copy link
Collaborator

devyte commented Jul 30, 2018

@mblythe86 could you please resolve the conflicts?

@devyte
Copy link
Collaborator

devyte commented Dec 5, 2018

Closing in favor of #5384 .

@devyte devyte closed this Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants