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

Multiple devices #22

Closed
bahlo opened this issue Jul 15, 2015 · 10 comments
Closed

Multiple devices #22

bahlo opened this issue Jul 15, 2015 · 10 comments

Comments

@bahlo
Copy link

bahlo commented Jul 15, 2015

How would one add multiple devices at once?

When I run hap.NewIPTransport("00102003", sw.Accessory) for every device, I get:

2015/07/15 21:49:18 [ERR] bonjour: Failed to bind to udp6 port: listen udp6 :5353: bind: address already in use
@brutella
Copy link
Owner

The second argument of NewIPTransport() is a variable length array of devices.

You can add multiple devices by calling hap.NewIPTransport("00102003", switch.Accessory, outlet.Accessory)

@bahlo
Copy link
Author

bahlo commented Jul 15, 2015

Okay, thank you very much!

@0x6368
Copy link

0x6368 commented Oct 4, 2015

I get the same error when I run _example/example.go even though no other process listens to port 5353. At least this is what the Terminal command lsof -i udp:5353 tells me. Any idea what the problem might be?

@brutella
Copy link
Owner

brutella commented Oct 5, 2015

The error output comes from here
mDNS uses the same port for IPv4 and IPv6

@0x6368
Copy link

0x6368 commented Oct 5, 2015

Does this mean I can just ignore it, because it already listens on the IPv4 address?

@brutella
Copy link
Owner

brutella commented Oct 5, 2015

Yes

@srizzling
Copy link

@brutella How would I go about adding multiple devices dynamically if I have a list of switches in a slice?

I'm new to Golang, and I'm not sure how I'll add a slice.

For example, here is my code:

for _, e := range *aliases {
		switchInfo := accessory.Info{
			Name: e,
		}

		acc := accessory.NewSwitch(switchInfo)
		accs = append(accs, acc.Accessory)

	}

	// TODO: figure out how to get generate this
	config := hc.Config{Pin: "12344321", Port: "12345", StoragePath: "./db"}
	t, err := hc.NewIPTransport(config, nil, accs)

I want to be able to dynamically add accessories

@bahlo
Copy link
Author

bahlo commented Feb 17, 2017

@srizzling You can just expand the slice with ... (more info):

t, err := hc.NewIPTransport(config, nil, accs...)

@brutella
Copy link
Owner

This should do the trick.

t, err := hc.NewIPTransport(config, accs...)

@srizzling
Copy link

Ah cheers.. I should have probably read the slices doc. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants