Resolving Host on mDNS

photon
Tags: #<Tag:0x00007fe21bfa6018>

#21

Hey, so I can see that the igmp library is included in the lwIP package under the third party folder. How can I access those library in functions? The ESP Resolver uses igmp for joining and maintaining the multicast group which I couldn’t find in the direct documentation anywhere. Any help on how to use them?


#22

This very simple sketch does subscribe to the mDNS multicast address and prints out what gets broadcasted.

UDP udp;

int remotePort = 5353;
IPAddress multicastAddress(224, 0, 0, 251);

void setup() {
  udp.begin(remotePort);
  udp.joinMulticast(multicastAddress);
}

void loop () {
  int     len;
  char    c;
  if (len = udp.parsePacket()) {
    for (int i=0; i < len; i++) {
      c = udp.read();
      Serial.printlnf("%3d %02x %c", c, c, c);
      //Serial.print(c);
    }
    Serial.println();
  }
}

When you send a DNS request with QTYPE A you should get a response from the respective device with the IP4 address being the last four bytes in the response.
However, the mDNS library for Particle does not respond to such requests.

This would be a function that emits a QTYPE A request

UDP udp;

void setup() {
  Particle.function("query", sendQuery);
  udp.begin(80);
}

uint8_t qHeader[]    = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t qTypeClass[] = { 0x00, 0x00, 0x01, 0x00, 0x01 };
int sendQuery(const char* arg) { // takes the name of the requested device
  uint8_t len = strlen(arg);

  udp.beginPacket(MDNS_ADDRESS, MDNS_PORT);
  udp.write(qHeader, sizeof(qHeader));
  udp.write(len);
  udp.print(arg);
  udp.write((uint8_t)0x05);
  udp.print("local");
  udp.write(qTypeClass, sizeof(qTypeClass));
  udp.endPacket();
    
  return len;    
}

#23

So, are you saying that this code for a QTYPE A cannot be used in the particle as of this moment because we don’t have the adequate response function? However, if we do make that function it should work.

  1. Why was it not made if all of this sounds so straightforward? There has to be something else that I am missing.
  2. How can I use the lwIP library/package in particle? I can see it under the third party folder but I couldn’t access it. There seems to be support for host resolving in it. I also noticed that the ESP library makes use of the IGMP but the MDNS for particle does not. Is it related to this lack of QTYPE A query and response?

#24

You’d have to ask this the contributor of the mDNS library as this is a community library and not provided by Particle.
I’d suspect it just wasn’t what the contributor needed for his-use case.
On the other hand, even if it’s straight forward, there are loads of QTYPEs and an evenly huge amount of possible QCLASSes that can be requested and even if each of them would be simple to implement the sheer number is enough to put someone off going down that rabbit hole.

For your other question you’d probably better ask Particle directly :wink:


#25

How much more direct does it have to be? Is there another community or you meant sarcastically referring to the particle board?


#26

A simple search will turn up support - try that route for direct contact.


#27

I am not a Particle employee. This community is mainly made up of private individuals who try to help to the best of their abilities.


#28

How do you check if it is working here? I tried printing the return value of joinMulticast() but it is giving 0.

I have also tried with Port as 5353 and multicast Address as 224.0.0.251 but got the same result.


#29

The LwIP code in the particle-iot Github is not intended for use by user firmware. It’s compiled directly into Device OS itself to implement IP functionality and is not a library, in the user firmware sense. You can’t directly access any of the functions from user firmware because they’re not exported. The Wiring interface for UDP should be sufficient to implement mDNS without using LwIP directly.


#30

Ok. Also, I am getting an error in using the joinMulticast() function saying it does not exist! I guess I will have to start there to join the group.


#31

Make sure you’ve correctly set the PLATFORM environment variable for your build. If you don’t set PLATFORM, the default is CORE and the Spark Core doesn’t support multicast UDP on any Device OS version.


#32

Yes. I have set it as photon only. I am currently changing the OS version and compile the same code to make sure it is not a version issue, which is very unlikely.
Another weird thing which is happening is the error is coming up only when I include the line in the main application. When inside a library file though, it is not throwing compilation error, however, it is not working. It is giving the return value -1


#33

My suggestion was entirely focused on your previous statement

To distiguish causes

  • when Web IDE builds with the code but your local toolchain doesn’t you’ll have an issue with the repo used for your local toolchain
  • when Web IDE doesn’t build you’d either have the wrong platform or device OS version targeted (as elboarted further up already)

Is your application file a .ino or a .cpp - if the latter you should add a #include <Particle.h> statement. Also try to not name your main file application.*


#34

Ok. Well I did try with v1.2.0 and it threw the same error. I am currently trying in v0.8.0 hoping for a different reply.

Why so? My main file is application.cpp
Also, I did find that while flashing using the Web IDE it did not throw an error. I guess there is some #define missing somewhere in the repo which I am using which is highly unlikely.


#35

Local or Web IDE?
If Web IDE, post a SHARE THIS REVISION link to let us see.
If local - my assessment from above still stands


#36

But I just cloned the latest repo and used the branch v1.2.0 which threw the same error


#37

It doesn’t for me from 0.4.5 onward - neither local (using Workbench) nor cloud.

Have you tried a make clean?


#38

Yes I have. And also all the other functions are working so it not likely the compiling pipe is broken.


#39

The udp.begin() function given in the spark_wiring_udp.cpp expects two parameters: port and the network interface but in usage we pass only the port number. Which udp library is the photon expected to call exactly because it doesn’t seems to b e this one under wiring/src/spark_wiring_udp.cpp


#40

If you look at spark_wiring_udp.h you’ll know why.