Prvni ulozeni z chegewara githubu
This commit is contained in:
@ -0,0 +1,80 @@
|
||||
/*
|
||||
ESP8266 mDNS-SD responder and query sample
|
||||
|
||||
This is an example of announcing and finding services.
|
||||
|
||||
Instructions:
|
||||
- Update WiFi SSID and password as necessary.
|
||||
- Flash the sketch to two ESP8266 boards
|
||||
- The last one powered on should now find the other.
|
||||
*/
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
const char* ssid = "...";
|
||||
const char* password = "...";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(250);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(ssid);
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
if (!MDNS.begin("ESP32_Browser")) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
while(1){
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
browseService("http", "tcp");
|
||||
delay(1000);
|
||||
browseService("arduino", "tcp");
|
||||
delay(1000);
|
||||
browseService("workstation", "tcp");
|
||||
delay(1000);
|
||||
browseService("smb", "tcp");
|
||||
delay(1000);
|
||||
browseService("afpovertcp", "tcp");
|
||||
delay(1000);
|
||||
browseService("ftp", "tcp");
|
||||
delay(1000);
|
||||
browseService("ipp", "tcp");
|
||||
delay(1000);
|
||||
browseService("printer", "tcp");
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void browseService(const char * service, const char * proto){
|
||||
Serial.printf("Browsing for service _%s._%s.local. ... ", service, proto);
|
||||
int n = MDNS.queryService(service, proto);
|
||||
if (n == 0) {
|
||||
Serial.println("no services found");
|
||||
} else {
|
||||
Serial.print(n);
|
||||
Serial.println(" service(s) found");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print details for each service found
|
||||
Serial.print(" ");
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(MDNS.hostname(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(MDNS.IP(i));
|
||||
Serial.print(":");
|
||||
Serial.print(MDNS.port(i));
|
||||
Serial.println(")");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
120
libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino
Normal file
120
libraries/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
ESP32 mDNS responder sample
|
||||
|
||||
This is an example of an HTTP server that is accessible
|
||||
via http://esp32.local URL thanks to mDNS responder.
|
||||
|
||||
Instructions:
|
||||
- Update WiFi SSID and password as necessary.
|
||||
- Flash the sketch to the ESP32 board
|
||||
- Install host software:
|
||||
- For Linux, install Avahi (http://avahi.org/).
|
||||
- For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
|
||||
- For Mac OSX and iOS support is built in through Bonjour already.
|
||||
- Point your browser to http://esp32.local, you should see a response.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
const char* ssid = "............";
|
||||
const char* password = "..............";
|
||||
|
||||
// TCP server at port 80 will respond to HTTP requests
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// Connect to WiFi network
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.println("");
|
||||
|
||||
// Wait for connection
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(ssid);
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Set up mDNS responder:
|
||||
// - first argument is the domain name, in this example
|
||||
// the fully-qualified domain name is "esp32.local"
|
||||
// - second argument is the IP address to advertise
|
||||
// we send our IP address on the WiFi network
|
||||
if (!MDNS.begin("esp32")) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
while(1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
Serial.println("mDNS responder started");
|
||||
|
||||
// Start TCP (HTTP) server
|
||||
server.begin();
|
||||
Serial.println("TCP server started");
|
||||
|
||||
// Add service to MDNS-SD
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Check if a client has connected
|
||||
WiFiClient client = server.available();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("New client");
|
||||
|
||||
// Wait for data from client to become available
|
||||
while(client.connected() && !client.available()){
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Read the first line of HTTP request
|
||||
String req = client.readStringUntil('\r');
|
||||
|
||||
// First line of HTTP request looks like "GET /path HTTP/1.1"
|
||||
// Retrieve the "/path" part by finding the spaces
|
||||
int addr_start = req.indexOf(' ');
|
||||
int addr_end = req.indexOf(' ', addr_start + 1);
|
||||
if (addr_start == -1 || addr_end == -1) {
|
||||
Serial.print("Invalid request: ");
|
||||
Serial.println(req);
|
||||
return;
|
||||
}
|
||||
req = req.substring(addr_start + 1, addr_end);
|
||||
Serial.print("Request: ");
|
||||
Serial.println(req);
|
||||
|
||||
String s;
|
||||
if (req == "/")
|
||||
{
|
||||
IPAddress ip = WiFi.localIP();
|
||||
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
|
||||
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at ";
|
||||
s += ipStr;
|
||||
s += "</html>\r\n\r\n";
|
||||
Serial.println("Sending 200");
|
||||
}
|
||||
else
|
||||
{
|
||||
s = "HTTP/1.1 404 Not Found\r\n\r\n";
|
||||
Serial.println("Sending 404");
|
||||
}
|
||||
client.print(s);
|
||||
|
||||
client.stop();
|
||||
Serial.println("Done with client");
|
||||
}
|
||||
|
25
libraries/ESPmDNS/keywords.txt
Normal file
25
libraries/ESPmDNS/keywords.txt
Normal file
@ -0,0 +1,25 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Ultrasound
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
ESPmDNS KEYWORD1
|
||||
MDNS KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
end KEYWORD2
|
||||
addService KEYWORD2
|
||||
enableArduino KEYWORD2
|
||||
disableArduino KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
9
libraries/ESPmDNS/library.properties
Normal file
9
libraries/ESPmDNS/library.properties
Normal file
@ -0,0 +1,9 @@
|
||||
name=ESPmDNS
|
||||
version=2.0.0
|
||||
author=Hristo Gochkov, Ivan Grokhtkov
|
||||
maintainer=Hristo Gochkov <hristo@espressif.com>
|
||||
sentence=ESP32 mDNS Library
|
||||
paragraph=
|
||||
category=Communication
|
||||
url=
|
||||
architectures=esp32
|
359
libraries/ESPmDNS/src/ESPmDNS.cpp
Normal file
359
libraries/ESPmDNS/src/ESPmDNS.cpp
Normal file
@ -0,0 +1,359 @@
|
||||
/*
|
||||
|
||||
ESP8266 Multicast DNS (port of CC3000 Multicast DNS library)
|
||||
Version 1.1
|
||||
Copyright (c) 2013 Tony DiCola (tony@tonydicola.com)
|
||||
ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com)
|
||||
MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com)
|
||||
Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com)
|
||||
|
||||
|
||||
License (MIT license):
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
// Important RFC's for reference:
|
||||
// - DNS request and response: http://www.ietf.org/rfc/rfc1035.txt
|
||||
// - Multicast DNS: http://www.ietf.org/rfc/rfc6762.txt
|
||||
// - MDNS-SD: https://tools.ietf.org/html/rfc6763
|
||||
|
||||
#ifndef LWIP_OPEN_SRC
|
||||
#define LWIP_OPEN_SRC
|
||||
#endif
|
||||
|
||||
#include "ESPmDNS.h"
|
||||
#include "WiFi.h"
|
||||
#include <functional>
|
||||
#include "esp_wifi.h"
|
||||
|
||||
// Add quotes around defined value
|
||||
#ifdef __IN_ECLIPSE__
|
||||
#define STR_EXPAND(tok) #tok
|
||||
#define STR(tok) STR_EXPAND(tok)
|
||||
#else
|
||||
#define STR(tok) tok
|
||||
#endif
|
||||
|
||||
// static void _on_sys_event(arduino_event_t *event){
|
||||
// mdns_handle_system_event(NULL, event);
|
||||
// }
|
||||
|
||||
MDNSResponder::MDNSResponder() :results(NULL) {}
|
||||
MDNSResponder::~MDNSResponder() {
|
||||
end();
|
||||
}
|
||||
|
||||
bool MDNSResponder::begin(const char* hostName){
|
||||
if(mdns_init()){
|
||||
log_e("Failed starting MDNS");
|
||||
return false;
|
||||
}
|
||||
//WiFi.onEvent(_on_sys_event);
|
||||
_hostname = hostName;
|
||||
_hostname.toLowerCase();
|
||||
if(mdns_hostname_set(hostName)) {
|
||||
log_e("Failed setting MDNS hostname");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MDNSResponder::end() {
|
||||
mdns_free();
|
||||
}
|
||||
|
||||
void MDNSResponder::setInstanceName(String name) {
|
||||
if (name.length() > 63) return;
|
||||
if(mdns_instance_name_set(name.c_str())){
|
||||
log_e("Failed setting MDNS instance");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MDNSResponder::enableArduino(uint16_t port, bool auth){
|
||||
mdns_txt_item_t arduTxtData[4] = {
|
||||
{(char*)"board" ,(char*)STR(ARDUINO_VARIANT)},
|
||||
{(char*)"tcp_check" ,(char*)"no"},
|
||||
{(char*)"ssh_upload" ,(char*)"no"},
|
||||
{(char*)"auth_upload" ,(char*)"no"}
|
||||
};
|
||||
|
||||
if(mdns_service_add(NULL, "_arduino", "_tcp", port, arduTxtData, 4)) {
|
||||
log_e("Failed adding Arduino service");
|
||||
}
|
||||
|
||||
if(auth && mdns_service_txt_item_set("_arduino", "_tcp", "auth_upload", "yes")){
|
||||
log_e("Failed setting Arduino txt item");
|
||||
}
|
||||
}
|
||||
|
||||
void MDNSResponder::disableArduino(){
|
||||
if(mdns_service_remove("_arduino", "_tcp")) {
|
||||
log_w("Failed removing Arduino service");
|
||||
}
|
||||
}
|
||||
|
||||
void MDNSResponder::enableWorkstation(esp_interface_t interface){
|
||||
char winstance[21+_hostname.length()];
|
||||
uint8_t mac[6];
|
||||
esp_wifi_get_mac((wifi_interface_t)interface, mac);
|
||||
sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
if(mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) {
|
||||
log_e("Failed adding Workstation service");
|
||||
} else if(mdns_service_instance_name_set("_workstation", "_tcp", winstance)) {
|
||||
log_e("Failed setting Workstation service instance name");
|
||||
}
|
||||
}
|
||||
|
||||
void MDNSResponder::disableWorkstation(){
|
||||
if(mdns_service_remove("_workstation", "_tcp")) {
|
||||
log_w("Failed removing Workstation service");
|
||||
}
|
||||
}
|
||||
|
||||
bool MDNSResponder::addService(char *name, char *proto, uint16_t port){
|
||||
char _name[strlen(name)+2];
|
||||
char _proto[strlen(proto)+2];
|
||||
if (name[0] == '_') {
|
||||
sprintf(_name, "%s", name);
|
||||
} else {
|
||||
sprintf(_name, "_%s", name);
|
||||
}
|
||||
if (proto[0] == '_') {
|
||||
sprintf(_proto, "%s", proto);
|
||||
} else {
|
||||
sprintf(_proto, "_%s", proto);
|
||||
}
|
||||
|
||||
if(mdns_service_add(NULL, _name, _proto, port, NULL, 0)) {
|
||||
log_e("Failed adding service %s.%s.\n", name, proto);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){
|
||||
char _name[strlen(name)+2];
|
||||
char _proto[strlen(proto)+2];
|
||||
if (name[0] == '_') {
|
||||
sprintf(_name, "%s", name);
|
||||
} else {
|
||||
sprintf(_name, "_%s", name);
|
||||
}
|
||||
if (proto[0] == '_') {
|
||||
sprintf(_proto, "%s", proto);
|
||||
} else {
|
||||
sprintf(_proto, "_%s", proto);
|
||||
}
|
||||
|
||||
if(mdns_service_txt_item_set(_name, _proto, key, value)) {
|
||||
log_e("Failed setting service TXT");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
IPAddress MDNSResponder::queryHost(char *host, uint32_t timeout){
|
||||
esp_ip4_addr_t addr;
|
||||
addr.addr = 0;
|
||||
|
||||
esp_err_t err = mdns_query_a(host, timeout, &addr);
|
||||
if(err){
|
||||
if(err == ESP_ERR_NOT_FOUND){
|
||||
log_w("Host was not found!");
|
||||
return IPAddress();
|
||||
}
|
||||
log_e("Query Failed");
|
||||
return IPAddress();
|
||||
}
|
||||
return IPAddress(addr.addr);
|
||||
}
|
||||
|
||||
|
||||
int MDNSResponder::queryService(char *service, char *proto) {
|
||||
if(!service || !service[0] || !proto || !proto[0]){
|
||||
log_e("Bad Parameters");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(results){
|
||||
mdns_query_results_free(results);
|
||||
results = NULL;
|
||||
}
|
||||
|
||||
char srv[strlen(service)+2];
|
||||
char prt[strlen(proto)+2];
|
||||
if (service[0] == '_') {
|
||||
sprintf(srv, "%s", service);
|
||||
} else {
|
||||
sprintf(srv, "_%s", service);
|
||||
}
|
||||
if (proto[0] == '_') {
|
||||
sprintf(prt, "%s", proto);
|
||||
} else {
|
||||
sprintf(prt, "_%s", proto);
|
||||
}
|
||||
|
||||
esp_err_t err = mdns_query_ptr(srv, prt, 3000, 20, &results);
|
||||
if(err){
|
||||
log_e("Query Failed");
|
||||
return 0;
|
||||
}
|
||||
if(!results){
|
||||
log_w("No results found!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mdns_result_t * r = results;
|
||||
int i = 0;
|
||||
while(r){
|
||||
i++;
|
||||
r = r->next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
mdns_result_t * MDNSResponder::_getResult(int idx){
|
||||
mdns_result_t * result = results;
|
||||
int i = 0;
|
||||
while(result){
|
||||
if(i == idx){
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
result = result->next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mdns_txt_item_t * MDNSResponder::_getResultTxt(int idx, int txtIdx){
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return NULL;
|
||||
}
|
||||
if (txtIdx >= result->txt_count) return NULL;
|
||||
return &result->txt[txtIdx];
|
||||
}
|
||||
|
||||
String MDNSResponder::hostname(int idx) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return String();
|
||||
}
|
||||
return String(result->hostname);
|
||||
}
|
||||
|
||||
IPAddress MDNSResponder::IP(int idx) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return IPAddress();
|
||||
}
|
||||
mdns_ip_addr_t * addr = result->addr;
|
||||
while(addr){
|
||||
if(addr->addr.type == MDNS_IP_PROTOCOL_V4){
|
||||
return IPAddress(addr->addr.u_addr.ip4.addr);
|
||||
}
|
||||
addr = addr->next;
|
||||
}
|
||||
return IPAddress();
|
||||
}
|
||||
|
||||
IPv6Address MDNSResponder::IPv6(int idx) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return IPv6Address();
|
||||
}
|
||||
mdns_ip_addr_t * addr = result->addr;
|
||||
while(addr){
|
||||
if(addr->addr.type == MDNS_IP_PROTOCOL_V6){
|
||||
return IPv6Address(addr->addr.u_addr.ip6.addr);
|
||||
}
|
||||
addr = addr->next;
|
||||
}
|
||||
return IPv6Address();
|
||||
}
|
||||
|
||||
uint16_t MDNSResponder::port(int idx) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return 0;
|
||||
}
|
||||
return result->port;
|
||||
}
|
||||
|
||||
int MDNSResponder::numTxt(int idx) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return 0;
|
||||
}
|
||||
return result->txt_count;
|
||||
}
|
||||
|
||||
bool MDNSResponder::hasTxt(int idx, const char * key) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
while(i < result->txt_count) {
|
||||
if (strcmp(result->txt[i].key, key) == 0) return true;
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String MDNSResponder::txt(int idx, const char * key) {
|
||||
mdns_result_t * result = _getResult(idx);
|
||||
if(!result){
|
||||
log_e("Result %d not found", idx);
|
||||
return "";
|
||||
}
|
||||
int i = 0;
|
||||
while(i < result->txt_count) {
|
||||
if (strcmp(result->txt[i].key, key) == 0) return result->txt[i].value;
|
||||
i++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String MDNSResponder::txt(int idx, int txtIdx) {
|
||||
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
|
||||
return !resultTxt
|
||||
? ""
|
||||
: resultTxt->value;
|
||||
}
|
||||
|
||||
String MDNSResponder::txtKey(int idx, int txtIdx) {
|
||||
mdns_txt_item_t * resultTxt = _getResultTxt(idx, txtIdx);
|
||||
return !resultTxt
|
||||
? ""
|
||||
: resultTxt->key;
|
||||
}
|
||||
|
||||
MDNSResponder MDNS;
|
125
libraries/ESPmDNS/src/ESPmDNS.h
Normal file
125
libraries/ESPmDNS/src/ESPmDNS.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
ESP8266 Multicast DNS (port of CC3000 Multicast DNS library)
|
||||
Version 1.1
|
||||
Copyright (c) 2013 Tony DiCola (tony@tonydicola.com)
|
||||
ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com)
|
||||
MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com)
|
||||
Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com)
|
||||
Rewritten for ESP32 by Hristo Gochkov (hristo@espressif.com)
|
||||
|
||||
This is a simple implementation of multicast DNS query support for an Arduino
|
||||
running on ESP32 chip.
|
||||
|
||||
Usage:
|
||||
- Include the ESP32 Multicast DNS library in the sketch.
|
||||
- Call the begin method in the sketch's setup and provide a domain name (without
|
||||
the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'), and the
|
||||
Adafruit CC3000 class instance. Optionally provide a time to live (in seconds)
|
||||
for the DNS record--the default is 1 hour.
|
||||
- Call the update method in each iteration of the sketch's loop function.
|
||||
|
||||
License (MIT license):
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
#ifndef ESP32MDNS_H
|
||||
#define ESP32MDNS_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "IPv6Address.h"
|
||||
#include "mdns.h"
|
||||
|
||||
//this should be defined at build time
|
||||
#ifndef ARDUINO_VARIANT
|
||||
#define ARDUINO_VARIANT "esp32"
|
||||
#endif
|
||||
|
||||
class MDNSResponder {
|
||||
public:
|
||||
MDNSResponder();
|
||||
~MDNSResponder();
|
||||
bool begin(const char* hostName);
|
||||
void end();
|
||||
|
||||
void setInstanceName(String name);
|
||||
void setInstanceName(const char * name){
|
||||
setInstanceName(String(name));
|
||||
}
|
||||
void setInstanceName(char * name){
|
||||
setInstanceName(String(name));
|
||||
}
|
||||
|
||||
bool addService(char *service, char *proto, uint16_t port);
|
||||
bool addService(const char *service, const char *proto, uint16_t port){
|
||||
return addService((char *)service, (char *)proto, port);
|
||||
}
|
||||
bool addService(String service, String proto, uint16_t port){
|
||||
return addService(service.c_str(), proto.c_str(), port);
|
||||
}
|
||||
|
||||
bool addServiceTxt(char *name, char *proto, char * key, char * value);
|
||||
void addServiceTxt(const char *name, const char *proto, const char *key,const char * value){
|
||||
addServiceTxt((char *)name, (char *)proto, (char *)key, (char *)value);
|
||||
}
|
||||
void addServiceTxt(String name, String proto, String key, String value){
|
||||
addServiceTxt(name.c_str(), proto.c_str(), key.c_str(), value.c_str());
|
||||
}
|
||||
|
||||
void enableArduino(uint16_t port=3232, bool auth=false);
|
||||
void disableArduino();
|
||||
|
||||
void enableWorkstation(esp_interface_t interface=ESP_IF_WIFI_STA);
|
||||
void disableWorkstation();
|
||||
|
||||
IPAddress queryHost(char *host, uint32_t timeout=2000);
|
||||
IPAddress queryHost(const char *host, uint32_t timeout=2000){
|
||||
return queryHost((char *)host, timeout);
|
||||
}
|
||||
IPAddress queryHost(String host, uint32_t timeout=2000){
|
||||
return queryHost(host.c_str(), timeout);
|
||||
}
|
||||
|
||||
int queryService(char *service, char *proto);
|
||||
int queryService(const char *service, const char *proto){
|
||||
return queryService((char *)service, (char *)proto);
|
||||
}
|
||||
int queryService(String service, String proto){
|
||||
return queryService(service.c_str(), proto.c_str());
|
||||
}
|
||||
|
||||
String hostname(int idx);
|
||||
IPAddress IP(int idx);
|
||||
IPv6Address IPv6(int idx);
|
||||
uint16_t port(int idx);
|
||||
int numTxt(int idx);
|
||||
bool hasTxt(int idx, const char * key);
|
||||
String txt(int idx, const char * key);
|
||||
String txt(int idx, int txtIdx);
|
||||
String txtKey(int idx, int txtIdx);
|
||||
|
||||
private:
|
||||
String _hostname;
|
||||
mdns_result_t * results;
|
||||
mdns_result_t * _getResult(int idx);
|
||||
mdns_txt_item_t * _getResultTxt(int idx, int txtIdx);
|
||||
};
|
||||
|
||||
extern MDNSResponder MDNS;
|
||||
|
||||
#endif //ESP32MDNS_H
|
Reference in New Issue
Block a user