DNS lookup

N5NHJ

Member
I need to reach out to a server over a DNS lookup.
I'm using NativeEthernet for my T4.1
Should I include a DNS library (specific for the Teensy), and if yes, which one?
I've been looking for example but found none.
Thank you
Max
 
The QNEthernet library includes a DNSClient class, but the Arduino Ethernet API’s UDP and TCP functions also include versions with a “host” string (in addition to the functions that take an IP address), so you don’t need to use a specialized DNS client. That is, unless you just want an IP address from a host.

I’m not super familiar with its API, but this also means you should probably be able to use just the included NativeEthernet functions.
 
Last edited:
Thanks Shawn and Defragster.
I'll look at the calls in the NativeEthernet library.
In the meantime, are NativeEthernet and QNEthernet code compatible? I have a number of systems in production, and I would like to avoid changing the code as much as possible.
 
The QNEthernet library supports the Arduino Ethernet API plus some useful additions. The only difference is that I’ve put all the classes in a namespace. After including <QNEthernet.h>, simply add
using namespace qindesign::network;
just after. Most things should be the same, otherwise.
 
Just included the library and the namespace definition.
I'm getting errors about "socketStatus" (I can survive without it..)

EthernetRoutines.ino:32:69: error: 'class qindesign::network::EthernetClass' has no member named 'socketStatus'
32 | Serial.print("socket Status: "); Serial.println(String(Ethernet.socketStatus(St)));

I'll test in production later today.

Can you point me to any documentations about the original DNS requests?
Much appreciated.
Max
 
Ethernet.socketStatus() isn’t part of the Arduino API. Can you link me to some documentation for it?
 
I need(ed) it for debugging the Ethernet status while I was suffering some disconnections.

Code:
/* ETHERNET CHANNELS AND BUFFERS */
uint8_t                 St                    = 0;

 while (Ethernet.begin(MyMAC) == 0) {
      if (millis() - TimeIt > 10000)  { // Ten seconds to get a DHCP served address
        if (TeensyDebug) {
          Serial.println("Failed to configure Ethernet using DHCP");
          Serial.print("link Status: "); Serial.println(Ethernet.linkStatus());
          Serial.print("hardware Status: "); Serial.println(Ethernet.hardwareStatus());
          Serial.print("socket Status: "); Serial.println(String(Ethernet.socketStatus(St)));
       }
      getFixedIpAddress();
      break;
      }
    }

But it is really not needed or useful anymore. I can remove it.
 
Oh, that is one of the many holdovers from a API design based on the W5100/5500 chips and how they work, and isn’t really relevant to a “generic” API. Also, it doesn’t look, from what you posted, like it’s being used correctly. (Just a guess.)
 
Last edited:
I agree, I'm removing it.
I see you have other status indicators in your library, so I can use some of them if needed.
Reading the documentation about the DNS, should I explicitly use Ethernet.setDNSServerIP(ip) or the Ethernet.begin() overload with the DNS ip declaration is ok if I just have one DNS?
 
Yep! One DNS is fine. (Note that I deprecated the Ethernet begin() functions that aren’t defined well by the old Arduino API.)

Try the Ethernet.begin(ip, netmask, gateway, dns) version.
 
Last edited:
Back to the DNS question.
I'm assuming I should declare the DNSClient and call the method:

Code:
DNSClient RadioDNS;
IPAddress RadioIP;

RadioDNS.getHostByName ("hello.wrl", RadioIP, 0);

but I get
error: 'DNSClient' does not name a type; did you mean 'Client'?
60 | DNSClient RadioDNS;
| ^~~~~~~~~
| Client
EthernetRoutines.ino: In function 'void FlexURL()':
error: 'class qindesign::network::EthernetClass' has no member named 'getHostByName'; did you mean 'setHostname'?
65 | Ethernet.getHostByName("hello.wrl", FlexIP, 0);
| ^~~~~~~~~~~~~
| setHostname
 
I'm currently using this.
Code:
Ethernet.begin(MyMAC, MyIP, MyDNS, MyGateway, MyMask);
Is it fine?
Use Ethernet.begin(MyIP, MyMask, MyGateway, MyDNS). No need to set your own MAC. The QNEthernet library uses the Teensy’s built-in one.
 
Back to the DNS question.
I'm assuming I should declare the DNSClient and call the method:

Code:
DNSClient RadioDNS;
IPAddress RadioIP;

RadioDNS.getHostByName ("hello.wrl", RadioIP, 0);

but I get
error: 'DNSClient' does not name a type; did you mean 'Client'?
60 | DNSClient RadioDNS;
| ^~~~~~~~~
| Client
EthernetRoutines.ino: In function 'void FlexURL()':
error: 'class qindesign::network::EthernetClass' has no member named 'getHostByName'; did you mean 'setHostname'?
65 | Ethernet.getHostByName("hello.wrl", FlexIP, 0);
| ^~~~~~~~~~~~~
| setHostname

You also need to include "DNSClient.h" (soon to be "qnethernet/DNSClient.h"). That’s one of the very few extras you need to include beyond "QNEthernet.h".
 
Noticeable Delay with QNEthernet Library

Hi Shawn,

I’ve come across something concerning and potentially critical for my application, and I wanted to give you a heads-up. We can dive deeper into this if needed, though I understand it’s not a straightforward topic.

In short, my app connects via TCP to a server and sends a message, like "on" when a button is pressed or "off" when the button is released.

After compiling with the QNEthernet library, I noticed a delay between pressing the button and the server’s reaction. Initially, I thought it might be due to other factors, but today, I had the chance to investigate further.

For context, the network configuration remains unchanged—both the server and the Teensy are local.

Here’s what I observed:

  • Using NativeEthernet: The server responds immediately. There’s no delay in sending the TCP message from the Teensy.
  • Using QNEthernet: There’s a noticeable delay in sending the message. I estimate the delay to be no less than 200ms.
I performed A/B testing multiple times, switching between the two libraries, and the results consistently confirmed this behavior.

Do you have any thoughts or insights on this?

Thanks.
Max
 
Call flush() when you want data to be sent immediately, otherwise it buffers a little bit.

Some related info:
* Post in thread 'QNEthernet and SimpleFTPServer modification'
https://forum.pjrc.com/index.php?th...impleftpserver-modification.76108/post-351998
* Post in thread 'TEENSY 4.1 REDUCED ENCODER PERFORMANCE WITH NATIVE ETHERNET'
https://forum.pjrc.com/index.php?th...rmance-with-native-ethernet.75183/post-344444

The second link has a link into my Readme.
https://github.com/ssilverman/QNEthernet#write-immediacy
 
Last edited:
Hi Shawn.
Unfortunately, I had to rollback to NativeEthernet. I'm getting reports of timing issues with sending/receiving the TCP packets which make the application un-usable. I will investigate more, and I'll report my findings.
Thanks, Max
 
I’d be interested in attempting to help solve this if you’re willing. What are the symptoms? Are you calling flush() when you need to send data right away? Are you sure you’re not including both libraries? (I’ve seen this last one cause issues.)
 
Last edited:
Back
Top