WebThingsIO / webthing-rust

Rust implementation of a Web Thing server
Mozilla Public License 2.0
211 stars 25 forks source link

mDNS-SD publishes correctly #54

Closed DazWilkin closed 3 years ago

DazWilkin commented 3 years ago

mDNS Service Discovery (mDNS-SD) now works correctly.

Fixed: #52

It's not easy to provide Rust-based unit test for this (see #53).

However, the service publication can be shown to work using the gateway:

docker run \
--name webthings-gateway \
--rm --interactive --tty \
--env=TZ=America/Los_Angeles \
--volume=${PWD}/webthings:/home/node/.webthings \
--network=host \
--log-opt max-size=1m \
--log-opt max-file=10 \
webthingsio/gateway:latest

Then browsing the Gateway's UI:

image

Ensure the "Web Thing: Native web thing support" addon is enabled:

image

Then, run the Rust example:

cargo run
[main] Starting server
setting new humidity level: 0.12784115970134735
setting new humidity level: 22.60777473449707
setting new humidity level: 30.48933982849121
setting new humidity level: 16.809547424316406
setting new humidity level: 14.687156677246094

Then, scan for devices:

image

NOTE I renamed the devices to be prefixed Rusty to confirm this was working.

Alternatively:

avahi-browse --all | grep _webthing._tcp
+ wlp6s0 IPv6 RustyDevice                                   _webthing._tcp       local
+ enp5s0 IPv6 RustyDevice                                   _webthing._tcp       local
+ enp5s0 IPv4 RustyDevice                                   _webthing._tcp       local

NOTE avahi-browse finds ThingsType::Multiple by the multiple's name. But (see below), will find ThingsType::Single by the device name, e.g.:

- wlp6s0 IPv6 RustyDevice                                   _webthing._tcp       local
- enp5s0 IPv4 RustyDevice                                   _webthing._tcp       local
- enp5s0 IPv6 RustyDevice                                   _webthing._tcp       local