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

The esp_local_ctrl example doesn't work (IDFGH-13814) #14666

Open
3 tasks done
pavel808 opened this issue Oct 4, 2024 · 7 comments
Open
3 tasks done

The esp_local_ctrl example doesn't work (IDFGH-13814) #14666

pavel808 opened this issue Oct 4, 2024 · 7 comments
Assignees
Labels
Status: Opened Issue is new

Comments

@pavel808
Copy link

pavel808 commented Oct 4, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

I have build the esp_local_ctrl example and flashed it to an ESP32-C3 device (on an ESP Thread Border Router). It connects to my local Wi-Fi. The HTTP server starts to listen on port 443.

Now this is where the problem is. The instructions provided in the esp_local_ctrl/README.md.

It states to first ping my_esp_ctrl_device.local.
The DNS cannot be resolved.

But if I do ping my_esp_ctrl_device, this pings ok. It makes sense from looking at the service name in the app_main.cpp it is just my_esp_ctrl_device

Connection fails on trying to run the following command :

python scripts/esp_local_ctrl.py --sec_ver 2 --sec2_username localctrl --sec2_pwd abcd1234

However, if I remove the .local extension from line 38 of the esp_local_ctrl.py, so that the service name is just my_esp_ctrl_device, on connecting, I then get the following errors from the script :

++++ Connecting to my_esp_ctrl_device++++
Connection Failure : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'my_esp_ctrl_device'. (_ssl.c:1007)
Traceback (most recent call last):
  File "/home/user/esp-idf-new/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py", line 437, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/user/esp-idf-new/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py", line 342, in main
    raise RuntimeError('Failed to establish connection')
RuntimeError: Failed to establish connection

And from the device :

(9453) control: Development mode: using hard coded salt
I (9463) wifi:<ba-add>idx:1 (ifx:0, 2c:3a:fd:af:ca:0e), tid:0, ssn:0, winSize:64
I (9473) control: Development mode: using hard coded verifier
I (9483) esp_https_server: Starting server
I (9483) esp_https_server: Server listening on port 443
I (9483) control: esp_local_ctrl service started with name : my_esp_ctrl_device
I (156043) esp_https_server: performing session handshake
E (156713) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x7780
E (156713) esp_https_server: esp_tls_create_server_session failed
E (156723) httpd: httpd_accept_conn: session creation failed
W (156723) httpd: httpd_server: error accepting new connection

Please help:)

@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 4, 2024
@github-actions github-actions bot changed the title The esp_local_ctrl example doesn't work The esp_local_ctrl example doesn't work (IDFGH-13814) Oct 4, 2024
@chegewara
Copy link
Contributor

Did you try to change esp32 example to match certificate name '.local'?

@pavel808
Copy link
Author

pavel808 commented Oct 4, 2024

Did you try to change esp32 example to match certificate name '.local'?

@chegewara I did also that. It still can't resolve the DNS for some reason.

Unable to resolve hostname: my_esp_ctrl_device.local

@chegewara
Copy link
Contributor

I think it's probably not the issue with example, thus using ".local" domain is not best choice.
It's most likely this problem

https://askubuntu.com/questions/1068131/ubuntu-18-04-local-domain-dns-lookup-not-working

Please try this solution

Essentially put two lines in /etc/mdns.allow:

.local. 
.local

@pavel808
Copy link
Author

pavel808 commented Oct 4, 2024

I think it's probably not the issue with example, thus using ".local" domain is not best choice. It's most likely this problem

https://askubuntu.com/questions/1068131/ubuntu-18-04-local-domain-dns-lookup-not-working

Please try this solution

Essentially put two lines in /etc/mdns.allow:

.local. 
.local

That doesn't work for me unfortunately.

@pavel808
Copy link
Author

pavel808 commented Oct 4, 2024

@chegewara I will try various changes in Ubuntu.

For a start, should this line be changed in the application ?:

#define SERVICE_NAME "my_esp_ctrl_device"

to

#define SERVICE_NAME "my_esp_ctrl_device.local"

@chegewara
Copy link
Contributor

In theory yes.
I have no time right now, but I will try to test it too.
Maybe tomorrow.

@espressif-bot espressif-bot assigned mahavirj and Harshal5 and unassigned mahavirj Oct 7, 2024
@Harshal5
Copy link
Collaborator

Harshal5 commented Oct 7, 2024

Hello, @pavel808, thanks for the report!

I tested the example on a MacOS device and it seems to resolve the my_esp_ctrl_device.local service name and the example works as expected. Whereas, when I tried running the ping command on a Linux device, it failed to connect.
The fix that helped me to resolve the service name: https://askubuntu.com/a/1114887.

In order to make the system use your preferred DNS resolver instead of localhost, you change the symlink to point to /run/systemd/resolve/resolv.conf instead of /run/systemd/resolve/stub-resolv.conf.
Immediately after this, resolution of .local started working. No need to reboot or restart any service.

sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

Please help try out the fix discussed here and let me know if this addresses the issue on your side.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

5 participants