Class MDNS

Description

A class used for registering and removing MDNS service records.

Syntax

class MDNSClass

Members

Public Constructors

The public constructor should not be used as this class is intended to be a singleton class. Access member functions using the object instance named MDNS.

Public Methods

MDNSClass::begin

Start MDNS operations

MDNSClass::end

Stop MDNS operations

MDNSClass::registerService

Add a service record

MDNSClass::deregisterService

Remove service record

MDNSClass::updateService

Update service record


MDNSClass::begin

Description

Start MDNS operations to begin responding to MDNS queries.

Syntax

void begin(void);

Parameters

The function requires no input parameter.

Returns

The function returns nothing.

Example Code

Example: mDNS_On_Arduino_IDE

This example shows how to register Ameba as a service that can be

recognized by Arduino IDE. If both of the PC runs Arduino IDE and the Ameba board are connecting to the same local network. Then you can find Ameba in “Tools” -> “Port” -> “Arduino at 192.168.1.238 (Ameba RTL8195A), which means the Arduino IDE find Ameba via mDNS.

mDNS_On_Arduino_IDE
 1#include "WiFi.h"
 2#include "AmebaMDNS.h"
 3
 4char ssid[] = "yourNetwork";     //  your network SSID (name)
 5char pass[] = "secretPassword";  // your network password
 6
 7MDNSService service("MyAmeba", "_arduino._tcp", "local", 5000);
 8
 9void setup() {
10  printf("Try to connect to %s\r\n", ssid);
11  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
12    printf("Failed. Wait 1s and retry...\r\n");
13    delay(1000);
14  }
15  printf("Connected to %s\r\n", ssid);
16
17  service.addTxtRecord("board", strlen("ameba_rtl8195a"), "ameba_rtl8195a");
18  service.addTxtRecord("auth_upload", strlen("no"), "no");
19  service.addTxtRecord("tcp_check", strlen("no"), "no");
20  service.addTxtRecord("ssh_upload", strlen("no"), "no");
21
22  printf("Start mDNS service\r\n");
23  MDNS.begin();
24
25  printf("register mDNS service\r\n");
26  MDNS.registerService(service);
27}
28
29void loop() {
30  // put your main code here, to run repeatedly:
31  delay(1000);
32}

MDNSClass::end

Description

Stop MDNS operations and stop responding to MDNS queries.

Syntax

void end(void);

Parameters

The function requires no input parameter.

Returns

The function returns nothing.

Example Code

NA

Notes and Warnings

Include “AmebaMDNS.h” to use the class function.


MDNSClass::registerService

Description

Add a service record to be included in MDNS responses.

Syntax

void register service(MDNSService service);

Parameters

service : MDNSService class object with required MDNS service data

Returns

The function returns nothing.

Example Code

Example: mDNS_On_Arduino_IDE

Details of the code can be found in the previous section of MDNSClass:: begin.

Notes and Warnings

Include “AmebaMDNS.h” to use the class function.


MDNSClass::deregisterService

Description

Remove a service record from MDNS responses.

Syntax

void deregisterService(MDNSService service);

Parameters

service : MDNSService class object to be removed

Returns

The function returns nothing.

Example Code

Example: mDNS_On_Arduino_IDE

Details of the code can be found in the previous section of MDNSClass:: begin.

Notes and Warnings

Include “AmebaMDNS.h” to use the class function.


MDNSClass::updateService

Description

Update a service record.

Syntax

void updateService(MDNSService service, unsigned int ttl);

Parameters

service: MDNSService class object to be updated

ttl : time-to-live(TTL) for service

Returns

The function returns nothing.

Example Code

NA

Notes and Warnings

Include “AmebaMDNS.h” to use the class function.