# How to perform mDNS discovery

**URL:** <https://community.homey.app/t/how-to-perform-mdns-discovery/72784>\
**Category:** Developers\
**Tags:** homey-pro\
**Created:** [November 28, 2022, 12:27pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784 "2022-11-28T12:27:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [November 28, 2022, 12:27pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/1 "2022-11-28T12:27:14Z")

</div>

I’ve been reading through the documentation [Discovery - Homey Apps SDK](https://apps.developer.homey.app/wireless/wi-fi/discovery/) to set up discovery of devices, I can see the device advertise itself with avahi-browse:

```auto
oh2th@pi ~: avahi-browse -r _go-e_go-eCharger_V4._tcp
   hostname = [go-echarger_123456.local]
   address = [192.168.4.16]
   port = [80]
   txt = ["serial=123456" "friendly_name=123456" "manufacturer=go-e" "devicetype=go-eCharger_V4" "version=054.7" "protocol=2"]

```

However Homey does not discover it no matter what I do. What am a missing? The sample plugwise reference is a bit too complex to figure this out.

And yes, I know there is an app for go-e Chargers, however that one doesn’t use the new go-e api.

.homeycompose/discovery/go-eCharger\_V4.json:

```auto
{
  "type": "mdns-sd",
  "mdns-sd": {
    "name": "go-e_go-eCharger_V4",
    "protocol": "tcp"
  },
  "id": "{{txt.serial}}"
}

```

drivers/go-e-charger-gemini/driver.compose.json:

```auto
{
  "name": {
    "en": "go-e Charger Gemini"
  },
  "class": "other",
  "capabilities": [
    "measure_current",
    "meter_power",
    "alarm_generic",
    "measure_power",
    "measure_temperature",
    "onoff",
    "measure_voltage"
  ],
  "platforms": [
    "local"
  ],
  "connectivity": [
    "lan"
  ],
  "images": {
    "small": "{{driverAssetsPath}}/images/small.png",
    "large": "{{driverAssetsPath}}/images/large.png",
    "xlarge": "{{driverAssetsPath}}/images/xlarge.png"
  },
  "discovery": "go-e_go-eCharger_V4",
  "pair": [
    {
      "id": "list_devices",
      "template": "list_devices",
      "navigation": {
        "next": "add_devices"
      }
    },
    {
      "id": "add_devices",
      "template": "add_devices"
    }
  ]
}

```

drivers/go-e-charger-gemini/driver.js:

```auto
'use strict';

const { Driver } = require('homey');

class MyDriver extends Driver {

  /**
   * onInit is called when the driver is initialized.
   */
  async onInit() {
    this.log('MyDriver has been initialized');
  }

  /**
   * onPairListDevices is called when a user is adding a device
   * and the 'list_devices' view is called.
   * This should return an array with the data of devices that are available for pairing.
   */
  async onPairListDevices() {
    this.log('MyDriver searching mDNS');

    const discoveryStrategy = this.getDiscoveryStrategy();
    const discoveryResults = discoveryStrategy.getDiscoveryResults();
    const devices = Object.values(discoveryResults).map(discoveryResult => {
      return {
        name: discoveryResult.txt.friendly_name,
        data: {
          id: discoveryResult.id,
          hostname: discoveryResult.hostname,
          address: discoveryResult.address,
          port: discoveryResult.port,
          devicetype: discoveryResult.txt.devicetype,
        },
      };
    });

    return devices;
  }

}

module.exports = MyDriver;

```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 28, 2022, 12:49pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/2 "2022-11-28T12:49:29Z")

</div>

Try:

```auto
"mdns-sd": {
 "name": "go-e_go-eCharger_V4",
 "protocol": "tcp"
},

```

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [November 28, 2022, 1:08pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/3 "2022-11-28T13:08:25Z")

</div>

Thanks for the hint, but no help with that either. I’m still getting “No new devices have been found.”

Updated the original post to reflect the suggested change for the mdns-sd name to ‘go-e\_go-eCharger\_V4’

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 28, 2022, 1:29pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/4 "2022-11-28T13:29:26Z")

</div>

Are your Homey and the charger on the same network?

Also, even though the `conditions` field is as documented, it seems strange that it’s a nested array. Try this:

```auto
 "conditions": [
      {
        "field": "txt.manufacturer",
        "match": {
          "type": "string",
          "value": "go-e"
        }
      }
  ]

```

Or just try leaving out the conditions part entirely to see if that at least provides discovery results.

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [November 28, 2022, 1:47pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/5 "2022-11-28T13:47:39Z")

</div>

Yes, both are in the same network and my avahi-browse linux and my mac with Discovery-tool.

I thru away to condition now, since it in away is extra, as the query already is unique for go-e.  
Still without a result.

As a comparison, Shelly devices are nicely found by Shelly Homey app from the network with mDNS.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 28, 2022, 2:10pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/6 "2022-11-28T14:10:07Z")

</div>

Try running a tcpdump for mDNS packets:

```auto
sudo tcpdump -n host 224.0.0.251 and port 5353 | grep e_go

```

Also, try restarting your app a few times. I was helping out with the Plugwise app over the weekend and we found that the mDNS discovery has some issues that could cause it to not discover any devices (specifically after an mDNS cache flush from the device). After a restart the app would start finding the devices again.

And you can also try using standalone discovery: [Discovery - Homey Apps SDK](https://apps.developer.homey.app/wireless/wi-fi/discovery#using-discovery-standalone)

I don’t know how long the SDK will wait for results to be discovered before it returns from `getDiscoveryResults()`, but it may not be long enough. The example code for the standalone discovery is useful for debugging to see if any results come in at all (even after `getDiscoveryResults()` has already returned).

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [November 28, 2022, 5:56pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/7 "2022-11-28T17:56:14Z")

</div>

Are you missing an \_ of the beginning of the name?

The excerpt `oh2th@pi ~: avahi-browse -r _go-e_go-eCharger_V4._tcp` has an \_ at the beginning but I’m not sure if that is part of the problem

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 28, 2022, 6:00pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/8 "2022-11-28T18:00:22Z")

</div>

AFAIK the SDK adds that underscore.

For instance, this is the mDNS discovery setup for the Plugwise app:

```auto
"mdns-sd": {
  "name": "plugwise",
  "protocol": "tcp"
}

```

And this is the `avahi-browse` command:

```auto
$ avahi-browse -r _plugwise._tcp
+ br0 IPv4 Plugwise on smile0109a7 _plugwise._tcp local
= br0 IPv4 Plugwise on smile0109a7 _plugwise._tcp local
   hostname = [smile0109a7.local]
   address = [192.168.23.68]
   port = [80]
   txt = ["status=/system" "path=/" "version=4.3.12" "product=smile_thermo"]

```

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [November 29, 2022, 5:01am UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/9 "2022-11-29T05:01:04Z")

</div>

Thank you @robertklep, for your kind help. Got me to a better path over night.

go-eCharger advertise its’ service also with \_http.\_tcp and switching to that brought a result for all http capable devices, including the go-e device.

Now with

```auto
{
  "type": "mdns-sd",
  "mdns-sd": {
    "name": "http",
    "protocol": "tcp"
  },
  "id": "{{txt.serial}}",
  "conditions": [
    [
      {
        "field": "txt.manufacturer",
        "match": {
          "type": "string",
          "value": "go-e"
        }
      }
    ]
  ]
}

```

I finally get a result with standalone discovery:

```auto
[log] 2022-11-29 04:47:01 [MyApp] Got result: DiscoveryResultMDNSSD {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: '123456',
  lastSeen: '2022-11-29T04:47:01.300Z',
  address: '192.168.4.16',
  host: 'go-echarger_123456',
  port: 80,
  name: '123456',
  fullname: '123456._http._tcp.local.',
  txt: {
    serial: '123456',
    friendly_name: '123456',
    manufacturer: 'go-e',
    devicetype: 'go-eCharger_V4',
    version: '054.7',
    protocol: '2'
  },
  [Symbol(kCapture)]: false
}

```

So there is progress, for some reason nothing is discovered the the go-e manufacturer specific service. But now I can continue and add the condition to filter only go-e results and even that looks like working now. Oh, and the condition indeed is an array of arrays. Homey complains, if it isn’t.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 16, 2023, 6:35pm UTC](https://community.homey.app/t/how-to-perform-mdns-discovery/72784/10 "2023-01-16T18:35:02Z")

</div>

FWIW, it looks like you’re right, someone else also ran into a very similar issue where discovery is likely to be failing because the service name contains a digit. I’ve created an issue for it on Github: [mDNS discovery seems to fail for services that contain a digit in their name · Issue #284 · athombv/homey-apps-sdk-issues · GitHub](https://github.com/athombv/homey-apps-sdk-issues/issues/284)
