nRF5 IoT SDK  v0.9.0
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
DNS

The Domain Name System (DNS) is the protocol of the IP stack that enables translating the domain name, for example example.com, to a corresponding set of parameters, such as the IPv6 address.

To demonstrate DNS protocol support on nRF5x, Nordic's IPv6 stack is used. Currently lwIP does not support AAAA (IPv6) records in the DNS module.

This application implements a simple state machine which queries the DNS Server in order to retrieve the IPv6 address of the given hostname. Right after the response is received, the module starts to send ICMP Echo Requests periodically until the host is reachable. If the maximum retransmission number of ICMP Echo Requests without response is exceeded, the DNS Query is sent again.

Note
A demo requires IPv6 global connectivity in order to communicate with the DNS Server.

The demo setup and flow diagram are presented in Figure 1.


DNS_Client_Server.svg
Figure 1: Setup of the DNS application.


Overview

This example demonstrates how Nordic's IPv6 stack can be used for sending a DNS Query and receiving the response packets of the DNS Server.

The state machine of the application is triggered by the BUTTON_1 on the kit and can be stopped by pushing BUTTON_2. The LED configuration indicates the actual state of the process.

Data Exchange MSC

The MSC below provides an overview of the data exchange in the application between the node (nRF5x) and the router/cloud in two cases:

  • Correct behavior
  • the IPv6 address associated with the hostname suddenly becomes unreachable (DNS Query is sent again)

msc_nrf_dns
Figure 2: Data Exchange.

Common module dependency and usage

This section summarizes the usage of nRF5x resources and common modules in the examples apart from the IoT 6lowpan and IPv6 stack library.

Module Inclusion/Usage Description
Timer 3 Three timers - IoT timer, button module and for timing ICMP Ping requests.
Buttons 2 Buttons are used for switching application states.
LEDs 4 LEDs are used to indicate the application states. See LED assignments.
Adv Data Encoder Yes The device name used is 'IPv6DNS', IPSP Service UUID is included in the UUID list.
Scheduler No Scheduler is used for processing stack events.
UART Trace Included not enabledTracing is included but not enabled by default.

Setup

The source code and project file of the example can be found at: <InstallFolder>/examples/iot/dns

See the short state diagram below that describes the application states.

Nordic_DNS_Diagram.png
Figure 3: Application State Diagram.

LED assignments

Application State LED 1 State LED 2 State LED 3 State LED 4 State
Idle OFF OFF OFF OFF
Advertising BLINKING OFF OFF OFF
IPv6 Interface Up OFF ON OFF OFF
IPv6 Interface Down ON BLINKING OFF OFF
DNS response has been received OFF ON ON OFF
Echo Reply has been received OFF ON ON INVERT
ASSERT ON ON ON ON
Note
If commissioning is enabled, additional LED and Button assignments are made.
If the application asserts, it is halted.
This application is not power optimized!

Testing

See Connecting devices to the router for a list of relevant Linux commands.

  1. Compile and program the application. Observe that the device is advertising.
  2. Prepare the Linux router device by initializing the 6LoWPAN module.
  3. Discover the advertising device by using the hcitool lescan command.
  4. Connect to the discovered device from the Linux console using the Bluetooth 6LoWPAN connect command.
  5. Check if the connected state is reflected by the LEDs (LED2 is ON).
  6. Ensure that the kit has an IPv6 Internet connection.
  7. Push Button 1 on the kit.
  8. Observe if LED3 is lit (after several seconds) indicating that a DNS Reply was received.
  9. Observe if LED4 constantly changes its state (in 2 seconds interval) indicating that an Echo Response was received.
  10. Push Button 2 on the kit.
  11. Observe if the LED3 and the LED4 are off.
  12. Disconnect from the device by using the Bluetooth 6LoWPAN disconnect command.
  13. Observe that only the advertising LED1 is blinking.