Bonjour resin.io


#1

I’m using resin.io/bonjour node module to advertise a service but it comes back with no addresses when using bonjour browser on mac, if I discover locally on the box it returns the information correctly.

Any recommendations?


#4

Hi Brice,

That module is mainly used in Resin within the CLI to search for local devices using Bonjour/mDNS, rather than to advertise them. The device itself already has Avahi configured in the OS, so you’ll find this works much more reliably if you configure the OS’s Avahi instance using D-Bus, rather than starting your own competing mDNS service on the same device.

There’s a Python example of a full project doing exactly that here: https://github.com/resin-io-playground/resin-avahi-dbus.

It looks like you’re using JS though, is that right? https://github.com/resin-io-modules/resin-discoverable-services/blob/master/lib/backends/avahi.coffee may be of interest. That’s JS (well, coffeescript) code to query Avahi over D-Bus when searching for devices, but you should be able to get some working logic to publish devices too from there.


#6

Awesome, thanks @pimterry will give this a try, I’m trying to have a consistent build that works on mac and in my resin.io container, hence why I was keen to use the bonjour module. I’ve tested https://github.com/ardean/spread-the-word today and it’s working ok even if the package is fairly recent.


#8

@pimterry is there a way to disable avahi on the host container via dBus or other method? Would this cause issues? Would rather use my own broadcasting service.


#11

@pimterry I’m using dbus-native to talk to Avahi via dbus but can’t get the interface, any idea what’s going on please?

const dbus = require('dbus-native');
const bus = dbus.systemBus();
const service = bus.getService('org.freedesktop.Avahi').getInterface('/', 'org.freedesktop.Avahi.Server', (err, interface) => {
        console.log(err);
        console.log(interface);
}); 

I get a No such interface found error.


#12

@brice Have you set the DBUS address to use the host DBUS? That would cause this. You need to run something like export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket beforehand.

The example python project for this has some details at https://github.com/resin-io-playground/resin-avahi-dbus, and there’s docs on this specifically here: https://docs.resin.io/runtime/runtime/#dbus-communication-with-hostos


#13

To answer your previous question as well:

is there a way to disable avahi on the host container via dBus or other method? Would this cause issues? Would rather use my own broadcasting service.

I’ve been talking to some of the team to see if we have any solutions here, but right now I’m not aware of any way to do that.


#15

I’ve setup the env, but still getting the same error. Tried with dbus and dbus-native.

If I use dbus-send I can talk to avahi but dbus-send doesn’t support array of array of bytes which is required when broadcasting a new service on Avahi.


#21

@pimterry I’m still stuck on this one, that’s the code I’m using:

const dbus = require('dbus-native')

const bus = dbus.systemBus();
bus.getService('org.freedesktop.Avahi').getInterface('/', 'org.freedesktop.Avahi.Server', (err, interface) => {
  console.error(err);
  console.info(interface);
});

process.stdin.resume();

DBUS_SYSTEM_BUS_ADDRESS is correctly set, and I keep getting a No such interface found error from dbus-native. I must be missing something obvious, any idea please?

PS: happy birthday :sweat_smile:


#22

For some reasons the list of methods is empty, even when using dbus-send:

dbus-send --system --print-reply --dest=org.freedesktop.Avahi / org.freedesktop.DBus.Introspectable.Introspect
method return sender=:1.4 -> dest=:1.93 reply_serial=2
   string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
</node>
"

#25

Any progress on this issue? I am running into it as well.

It looks like the Avahi interface description document is not present under /usr/share/dbus-1/interfaces/. The dbus-native library relies on DBus’ introspection description documents to allow access to the interfaces. I’m not sure if there is a way to add it since the location is in the read-only image.


#26

@samjrdn my work around was to install avahi-utils on the box and use that to broadcast using avahi-publish


#30

Hi @brice,

What is the device type that you noticed this issue at?


#35

Using the IntelNUC image on a Zotac computer.