# Resolving Host on mDNS

**URL:** <https://community.particle.io/t/resolving-host-on-mdns/51577>\
**Category:** Libraries\
**Tags:** photon\
**Created:** [August 8, 2019, 4:03pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577 "2019-08-08T16:03:36Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 10, 2019, 4:22pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/21 "2019-08-10T16:22:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 11, 2019, 12:28am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/22 "2019-08-11T00:28:19Z")

</div>

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

```cpp
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

```cpp
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;    
}

```

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 11, 2019, 10:10am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/23 "2019-08-11T10:10:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 11, 2019, 10:45am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/24 "2019-08-11T10:45:04Z")

</div>

> [@moz](#):
>
> Why was it not made if all of this sounds so straightforward?

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 😉

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 8:28am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/25 "2019-08-12T08:28:46Z")

</div>

> [@ScruffR](#):
>
> For your other question you’d probably better ask Particle directly

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

---

<div class="post-metadata">

**Author:** ![shanevanj](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/shanevanj/32/21186_2.png) [@shanevanj](https://community.particle.io/u/shanevanj)\
**Post date:** [August 12, 2019, 8:58am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/26 "2019-08-12T08:58:15Z")

</div>

A simple search will turn up [support](https://docs.particle.io/support/menu-base/) - try that route for direct contact.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 12, 2019, 10:55am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/27 "2019-08-12T10:55:02Z")

</div>

> [@moz](#):
>
> How much more direct does it have to be?

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.

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 12:46pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/28 "2019-08-12T12:46:15Z")

</div>

> [@ScruffR](#):
>
> If Web IDE works (as it does for me) but not your local build, I’d suspect there might be something wrong with your local toolchain.

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.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [August 12, 2019, 12:54pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/29 "2019-08-12T12:54:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 12:58pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/30 "2019-08-12T12:58:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [August 12, 2019, 1:02pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/31 "2019-08-12T13:02:59Z")

</div>

> [@moz](#):
>
> I am getting an error in using the joinMulticast() function saying it does not exist!

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.

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 1:08pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/32 "2019-08-12T13:08:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 12, 2019, 1:56pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/33 "2019-08-12T13:56:00Z")

</div>

> [@moz](#):
>
> How do you check if it is working here?

My suggestion was entirely focused on your previous statement

> [@moz](#):
>
> src/application.cpp:237:6: error: ‘class UDP’ has no member named ‘joinMuticast’  
> udp.joinMuticast(multicastAddress);
> 
> This is the error message I am getting. I have referred the library on github for the correct parameters. The OS I am working with is 1.1.0-rc.2

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)

> [@moz](#):
>
> Another weird thing which is happening is the error is coming up only when I include the line in the main application.

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.*`

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 2:14pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/34 "2019-08-12T14:14:52Z")

</div>

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.

> [@ScruffR](#):
>
> Also try to _not_ name your main file `application.*`

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.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 12, 2019, 2:16pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/35 "2019-08-12T14:16:56Z")

</div>

> [@moz](#):
>
> Well I did try with v1.2.0 and it threw the same error.

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

> [@ScruffR](#):
>
> you’ll have an issue with the repo used for your local toolchain

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 2:18pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/36 "2019-08-12T14:18:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 12, 2019, 2:20pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/37 "2019-08-12T14:20:12Z")

</div>

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

Have you tried a `make clean`?

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 12, 2019, 2:28pm UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/38 "2019-08-12T14:28:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moz](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moz/32/20176_2.png) [@moz](https://community.particle.io/u/moz)\
**Post date:** [August 13, 2019, 8:01am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/39 "2019-08-13T08:01:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [August 13, 2019, 8:09am UTC](https://community.particle.io/t/resolving-host-on-mdns/51577/40 "2019-08-13T08:09:51Z")

</div>

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

> <https://github.com/particle-iot/device-os/blob/develop/wiring/inc/spark_wiring_udp.h#L121>

[Previous page](https://community.particle.io/t/resolving-host-on-mdns/51577.md?page=1)

[Next page](https://community.particle.io/t/resolving-host-on-mdns/51577.md?page=3)
