Azure IoT Hub Library with OpenThread

Hello Everyone,

We are working on a new product using the nrf52840 and OpenThread.Our current product uses the Azure IoT Hub and we were wondering if we could use the library used by the nrf91.

According to Didrik in a post on Devzone It should be possible to use this library to connect to the Azure IoT Hub.

I have set up a Thread network and added a route for the NAT64 interface. I am able to use the NAT64 interface as a DNS server to get a IPv6 address synthesized from the well-known-prefix and the IPv4 address.

I've done this using the OpenThread CLI example from the nRF Connect SDK.

I've created a project and I've included the Azure IoT Hub library. It runs but is unable to get a ip address for the provided domain.

I've looked at the Azure IoT Hub code and it uses getaddrinfo to get a ip address from a hostname.

What would be the best way to proceed? I can see the OpenThread CLI example uses a different method to retrieve the ip address from the DNS. Is there a way to configure a DNS server used by getaddrinfo?

Parents
  • Hi,

    It looks like getaddrinfo() internally calls dns_get_addr_info(), so you may be able to call dns_resolve_init() or dns_resolve_reconfigure() to set the DNS server address.

    You may also use the Kconfigs DNS_SERVER_IP_ADDRESSES and CONFIG_DNS_SERVERx to specify the DNS servers used by the DNS resolve library.

    Best regards,
    Jørgen

  • Hi,

    Looks like error code -101 means that the request was cancelled (DNS_EAI_CANCELED). Have you checked with a sniffer trace if the request is actually sent over the air, and if it is sent to the correct address and port (compared to the OT CLI command)?

    From an earlier test case, it looks like the request will be cancelled if a local DNS server is not present.

    Best regards,
    Jørgen

  • Hi,

    I've checked by running tcpdump on the RPi OTBR device.

    With OT-CLI I see the DNS requests coming through in the tcpdump:

    pi@raspberrypi:~ $ sudo tcpdump -vnni wpan0

    tcpdump: listening on wpan0, link-type LINUX_SLL (Linux cooked v1), snapshot length 262144 bytes

    14:04:33.770137 IP6 (hlim 64, next-header UDP (17) payload length: 36) fd35:ad25:a99f:8c75:a301:6d0:492:8a96.49153 > fdaa:bb:1::2.53: [udp sum ok] 54430+ AAAA? reddit.com. (28)

    14:04:33.831836 IP6 (flowlabel 0x67ac1, hlim 64, next-header UDP (17) payload length: 148) fdaa:bb:1::2.53 > fd35:ad25:a99f:8c75:a301:6d0:492:8a96.49153: [udp sum ok] 54430 4/0/0 reddit.com. AAAA 64:ff9b::9765:818c, reddit.com. AAAA 64:ff9b::9765:c18c, reddit.com. AAAA 64:ff9b::9765:18c, reddit.com. AAAA 64:ff9b::9765:418c (140)

    I do not see any activity with my resolve_dns() function

  • Can you use the OpenThread specific DNS API used by the ot-cli in the Azure IoT Hub case as well?

    If not, you need to debug the application to see where it fails (increase log levels would be a good start), and/or do a on-air sniffer trace of the Thread traffic, to see if the DNS is sent to any destination.

  • Debugging shows the DNS_EAI_CANCELED is the result of a timeout.

    I'm also getting a timeout using the OpenThread specific DNS API's

    
    #include <openthread/dns_client.h>
    
    void ot_dns_response(otError aError, const otDnsAddressResponse *aResponse, void *aContext)
    {
    
    	char address_string[OT_IP6_ADDRESS_STRING_SIZE];
    	otIp6Address address;
    	uint32_t ttl;
    
    	// Fails with error 28
    	// [00:00:19.219,787] <inf> net_l2_openthread: State changed! Flags: 0x00000200 Current role: 3
    	// [00:00:21.184,112] <err> coap_server: ot_dns_response failed 28
    
    	if (aError == OT_ERROR_NONE)
    	{
    		uint16_t index = 0;
    
    		LOG_INF("ot_dns_response Success");
    
    		while (otDnsAddressResponseGetAddress(aResponse, index, &address, &ttl) == OT_ERROR_NONE)
    		{
    			otIp6AddressToString(&address, address_string, sizeof(address_string));
    			LOG_INF("ip: %s, TTL:%u ", address_string, ttl);
    			index++;
    		}
    	}
    	else
    	{
    		LOG_ERR("ot_dns_response failed %d", aError);
    	}
    }
    
    otDnsQueryConfig config;
    const otDnsQueryConfig *current_config;
    void set_ot_dns_config(void)
    {
    	otError error;
    	current_config = otDnsClientGetDefaultConfig(ot_context->instance);
    
    	memcpy(&config, current_config, sizeof(otDnsQueryConfig));
    
    	config.mNat64Mode = OT_DNS_NAT64_ALLOW;
    	config.mRecursionFlag = OT_DNS_FLAG_RECURSION_DESIRED;
    	config.mMaxTxAttempts = 2;
    	config.mResponseTimeout = 1000;
    	config.mServerSockAddr.mPort = 53;
    
    	error = otIp6AddressFromString("FDAA:BB:1::2", &config.mServerSockAddr.mAddress);
    	if (error != OT_ERROR_NONE)
    		LOG_ERR("otIp6AddressFromString failed %d", error);
    
    	otDnsClientSetDefaultConfig(ot_context->instance, &config);
    
    	current_config = otDnsClientGetDefaultConfig(ot_context->instance);
    }
    
    void resolve_ot_dns(void)
    {
    	otError error;
    	error = otDnsClientResolveAddress(ot_context->instance, "ing.nl", &ot_dns_response, ot_context->instance, &config);
    	if (error != OT_ERROR_NONE)
    	{
    		LOG_ERR("ot_dns_response resolve_dns %d", error);
    	}
    }

    Thanks for your suggestions. I'm going to try and increase logging and let you know. Any suggestion to which NET component I should set to debug logging?

Reply
  • Debugging shows the DNS_EAI_CANCELED is the result of a timeout.

    I'm also getting a timeout using the OpenThread specific DNS API's

    
    #include <openthread/dns_client.h>
    
    void ot_dns_response(otError aError, const otDnsAddressResponse *aResponse, void *aContext)
    {
    
    	char address_string[OT_IP6_ADDRESS_STRING_SIZE];
    	otIp6Address address;
    	uint32_t ttl;
    
    	// Fails with error 28
    	// [00:00:19.219,787] <inf> net_l2_openthread: State changed! Flags: 0x00000200 Current role: 3
    	// [00:00:21.184,112] <err> coap_server: ot_dns_response failed 28
    
    	if (aError == OT_ERROR_NONE)
    	{
    		uint16_t index = 0;
    
    		LOG_INF("ot_dns_response Success");
    
    		while (otDnsAddressResponseGetAddress(aResponse, index, &address, &ttl) == OT_ERROR_NONE)
    		{
    			otIp6AddressToString(&address, address_string, sizeof(address_string));
    			LOG_INF("ip: %s, TTL:%u ", address_string, ttl);
    			index++;
    		}
    	}
    	else
    	{
    		LOG_ERR("ot_dns_response failed %d", aError);
    	}
    }
    
    otDnsQueryConfig config;
    const otDnsQueryConfig *current_config;
    void set_ot_dns_config(void)
    {
    	otError error;
    	current_config = otDnsClientGetDefaultConfig(ot_context->instance);
    
    	memcpy(&config, current_config, sizeof(otDnsQueryConfig));
    
    	config.mNat64Mode = OT_DNS_NAT64_ALLOW;
    	config.mRecursionFlag = OT_DNS_FLAG_RECURSION_DESIRED;
    	config.mMaxTxAttempts = 2;
    	config.mResponseTimeout = 1000;
    	config.mServerSockAddr.mPort = 53;
    
    	error = otIp6AddressFromString("FDAA:BB:1::2", &config.mServerSockAddr.mAddress);
    	if (error != OT_ERROR_NONE)
    		LOG_ERR("otIp6AddressFromString failed %d", error);
    
    	otDnsClientSetDefaultConfig(ot_context->instance, &config);
    
    	current_config = otDnsClientGetDefaultConfig(ot_context->instance);
    }
    
    void resolve_ot_dns(void)
    {
    	otError error;
    	error = otDnsClientResolveAddress(ot_context->instance, "ing.nl", &ot_dns_response, ot_context->instance, &config);
    	if (error != OT_ERROR_NONE)
    	{
    		LOG_ERR("ot_dns_response resolve_dns %d", error);
    	}
    }

    Thanks for your suggestions. I'm going to try and increase logging and let you know. Any suggestion to which NET component I should set to debug logging?

Children
No Data
Related