lure23 / ESP32-WSL

Instructions for setting up ESP32 development, within virtual Linux environments
8 stars 2 forks source link

Material: Service discovery with WSL2 doesnt work #1

Closed oidebrett closed 10 months ago

oidebrett commented 10 months ago

Hi, Thanks for this guide. I want to develop matter applications. For matter commissioning / discovery, the commissioner needs to do service discovery using mDNS. When I have an external matter device (e.g. running on a ESP32 SOC) then service discovery to WSL2 doesnt work. I also posted over on the esp32 forum but this repo seems to be more regularly updated.

To reproduce this you will need 2 machines - a windows machine running wsl2 and a linux machine running Ubuntu such as Ubuntu22.04

Steps to reproduce:

On Ubuntu based machine

1) Simulate a Matter Application in commissioning pairing mode on a machine running Ubuntu (i.e. non wsl2) As per Matter Core Specification 1.2 Section 4.3.1, this can be simulated using Avahi command

In a separate terminal on the Ubuntu machine run this command

avahi-publish-service --subtype=_S3._sub._matterc._udp \
--subtype=_L840._sub._matterc._udp --subtype=_V123._sub._matterc._udp \
--subtype=_CM._sub._matterc._udp --subtype=_T81._sub._matterc._udp DD200C20D25AE5F7 \
_matterc._udp 11111 D=840 VP=123+456 CM=2 DT=81 DN="Kitchen Plug" PH=256 PI=5

2) Confirm that the mDNS service discovery is working

In a separate terminal on the Ubuntu machine run this command

 avahi-browse _matterc._udp -rt

You should see an output such as this

=   eth0 IPv4 DD200C20D25AE5F7                              _matterc._udp        local
   hostname = [DESKTOP-J0S44C6-2.local]
   address = [1XX.XX.XXX.XXX]
   port = [11111]
   txt = ["PI=5" "PH=256" "DN=Kitchen Plug" "DT=81" "CM=2" "VP=123+456" "D=840"]

Note: this is a quick method to test the mDNS service discovery aspects of the Matter protocol. If you want to fully build a matter example application such as the lighting-app for an ESP32 you should follow this link: https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/esp32/build_app_and_commission.md . This may proof to be a complicated task if someone has not done it before therefore I have included the simulated approach above as a quicker way to test.

On WSL2 machine

1) Ensured that dbus and avahi-daemon has started

sudo service dbus start
sudo service avahi-daemon start

2) check that the services are running

/etc/init.d/dbus status
/etc/init.d/avahi-daemon status

3) check that we can discover both commissioned and commissioning devices

avahi-browse -rt _matterc._udp

You should see the same output as above.

!!! This doesnt work - no devices are found even though I have a simulated matter device on the network and advertising mDNS waiting for commissioning.

Note: people have reported issues with mDNS from WSL2 and have suggested some routing at the windows firewall level but this did not work for me. See link. mDNS service discover use port 5353.

Has anyone found a solution for mDNS service discovery so that matter development for esp32 can be done on WSL2?

Many thanks!

lure23 commented 10 months ago

Hi,

thanks for popping by in the repo!

this repo seems to be more regularly updated.

I don't know about that... Just happened to get my ESP32 device a week back. :)

Let's keep this issue here, in case someone finds it and helps do a cure.

Here are some ideas, how you can edit the Issue to be better - this will help people find it in the first place.

More specific title

It's currently "ESP32 - developing matter applications using WSL2" - but this is a wholesale title. Specific ones are usually better, and you do describe the problem in the text as "service discovery to WSL2 doesnt work". I'd use that as a title.

Note that "ESP32" isn't likely needed to be stated (you may, of course). It's already in the name of the repo.

code syntax

Your [code] blocks are not valid Markdown syntax, so they don't render correctly. I imagine you wish them to be monospaced. Use triple back-ticks instead?

This makes the entry easier for others to read.

Then about your actual issue. I'm not a Matter expert - haven't touched it, yet. But if something works in Linux but not WSL2, my first hunch would be it's a firewall issue.


Edit:

people have reported issues with mDNS from WSL2 and have suggested some routing

It would be great if you can share some links, where such things have been reported. This helps others help you.

[...] at the hyper-v level but this is unclear to me.

Hyper-V is the Windows hypervisor, available on Pro licenses. There are some settings in there for the virtualization - perhaps ways to mount folders or allow port pass-throughs, that could indeed help. Please mention whether you have a Pro license.

oidebrett commented 10 months ago

Updated the original issue as suggested

lure23 commented 10 months ago

@oidebrett One more thing:

so that matter development for esp32 can be done on WSL2?

Is there something ESP32 specific in what you are asking? Couldn't the ESP32 just "join" Matter / use it, over its own wireless connection? Does the development account (WSL in this case) need to also be "on" Matter?

Sorry if my terms are completely wrong.

oidebrett commented 10 months ago

When you do matter development for esp32 you generally test from your development machine. Testing an esp32 based matter device normally involves using the chip-tool

The chip-tool is used to pair the matter device to the matter network (fabric) and also issue test commands.

So yes, you could just develop for the esp32 on wsl and use esp-idf to build, flash and monitor but you would not be able to test your development easily without WSL handling mDNS service discovery.

lure23 commented 10 months ago

When you are testing this, is your ESP32 in the same wireless network as your development computer?

oidebrett commented 10 months ago

Yes. It's on the same network.

oidebrett commented 10 months ago

Solution to this problem is outlined here