{"id":37,"date":"2021-01-01T14:06:53","date_gmt":"2021-01-01T14:06:53","guid":{"rendered":"http:\/\/www.vanmeel.at\/?p=37"},"modified":"2021-01-02T16:34:24","modified_gmt":"2021-01-02T16:34:24","slug":"esp8266-webserver-mit-mdns","status":"publish","type":"post","link":"https:\/\/www.vanmeel.at\/?p=37","title":{"rendered":"ESP8266 WebServer mit mDNS"},"content":{"rendered":"\n<p>F\u00fcr mein Olero Projekt brauche ich einen WebServer auf dem ESP8266, der sich selbst ins WLAN einh\u00e4ngt und innerhalb des LAN \u00fcber eine lokale Domain (mDNS) erreichbar ist.<\/p>\n\n\n\n<p>Sollte doch eigentlich nicht so schwer sein. Es gibt haufenweise Tutorials dazu im Internet. Aber egal welches Tutorial ich befolgte: mein ESP war nie \u00fcber mDNS erreichbar &#8211; immer nur \u00fcber seine IP.<\/p>\n\n\n\n<p>Nach ewig langem Suchen bin ich dann \u00fcber eine Diskussion gestolpert, die mir den notwendigen Hinweis gezeigt hat: bei allen Tutorials fehlten zwei mDNS Aufrufe! Kaum habe ich sie hinzugef\u00fcgt, klappt alles wie am Schn\u00fcrchen.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/\/ ---------------------------------------------------------\n#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESP8266mDNS.h&gt;\n#include &lt;WiFiClient.h&gt;\n\n#include &lt;ESPAsyncTCP.h&gt;\n#include &lt;ESPAsyncWebServer.h&gt;\n\n\/\/ WLAN settings it should try to connect to\nconst char *ssid = &quot;MyNetworkSSID&quot;;\nconst char *password = &quot;myNetworkPassword&quot;;\n\n\/\/ Hostname for mDNS - note that .local will be added automatically\nconst char *hostname = &quot;myeps&quot;;\n\n\/\/ web server port - 80 is http\nconst int port = 80;\n\n\/\/ Create a async http server\nAsyncWebServer server(port);\n\n\/\/ ---------------------------------------------------------\n\/\/ Arduino setup function\n\/\/ ---------------------------------------------------------\nvoid setup(void) {\n  \/\/ connect to existing WLAN\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n\n  \/\/ wait for connection to be stablished - note: you should do some error handling here\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n  }\n\n  \/\/ start HTTP server - note: might need some other setup beforehand\n  server.begin();\n\n  \/\/ setup mDNS - note: you should do error handling here\n  MDNS.begin(hostname);\n\n  \/\/ IMPORTANT: add http service to MDNS - this step was always missing\n  MDNS.addService(&quot;http&quot;, &quot;tcp&quot;, 80);\n}\n\n\/\/ ---------------------------------------------------------\n\/\/ Arduino main loop function\n\/\/ ---------------------------------------------------------\nvoid loop(void)\n{\n  \/\/ IMPORTANT: this step was always missing, too\n  MDNS.update();\n}\n\n\/\/ end-of-file\n\/\/ ---------------------------------------------------------\n\n<\/pre><\/div>\n\n\n<p>Und damit ist der ESP unter folgenden URLs zu finden:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Windows 10: http:\/\/myesp.local<\/li><li>Android: http:\/\/myesp.<\/li><\/ul>\n\n\n\n<p>Auf den Android Trick bin ich zuf\u00e4llig gesto\u00dfen. Einfach statt &#8222;.local&#8220; nur den Punkt &#8222;.&#8220; an die mDNS Domain anh\u00e4ngen und dann wird der ESP gefunden.<\/p>\n\n\n\n<p>Der gesamte Source Code f\u00fcr einen ESP8266 Web Server ist auf Github unter <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/emavok\/esp8266-webserver\" target=\"_blank\">https:\/\/github.com\/emavok\/esp8266-webserver<\/a> zu finden.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>F\u00fcr mein Olero Projekt brauche ich einen WebServer auf dem ESP8266, der sich selbst ins WLAN einh\u00e4ngt und innerhalb des LAN \u00fcber eine lokale Domain (mDNS) erreichbar ist. Sollte doch eigentlich nicht so schwer sein. Es gibt haufenweise Tutorials dazu im Internet. Aber egal welches Tutorial ich befolgte: mein ESP war nie \u00fcber mDNS erreichbar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3,5],"tags":[6],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-elektronik","category-esp8266","category-programmierung","tag-esp8266"],"_links":{"self":[{"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":29,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vanmeel.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}