TCPClient connect Issues

@bko. The joy was short lived. Now I'm getting nearly consistent DNS fails.
Code:

  IPAddress serverIP;
  for (int i = 0; i < 10; i++)
  {
      serverIP = WiFi.resolve(cmStr);
      if (serverIP) break;
      delay(250);        // allow time for the DNS server to maybe think about giving us an IP address?
  }
  Serial.print("Server IP: "); Serial.println(serverIP);

It works the first time:

--textbelt.com--
IP: 104.28.21.107
--smtp.gmx.com--
IP: 212.227.17.184

All subsequent times?

--textbelt.com--
IP: 0.0.0.0
--smtp.gmx.com--
IP: 0.0.0.0

Which build do you recommend that I use for this patch? At the moment, I'm using the RELEASE 0.4.3 branch.

See this github issue for the details:

I would check those DNS logs on your router or DNS host to see what it thinks it happening.

If this is a core, you should check if you DNS host is 76.83.0.0. If so you should reapply TI CC3000 patch since the TI part seems to lose itā€™s mind sometimes wrt DNS. In the CLI do, particle flash --usb cc3000 to reflash the TI part with the core in DFU mode over USB.

1 Like

I'm not getting an SOS...just an outright TCPClient.connect() fail: it returns 0.

Dug through the firmware to get the DNS server. My code looks like this:

  #include "system_network.h"

  ...

  //Code based on http://community.particle.io/t/tcpclient-problem-dhcp-dns-problems/7858/2
  const WLanConfig *ip_config = network_config(NULL, 0, NULL);
  IPAddress dnshost = ip_config->nw.aucDNSServer;
  Serial.print("DNS host: "); Serial.println(dnshost);

The response:

DNS host: 10.0.0.254

One successful DNS resolve made; the one immediately following failed. FWIW, I don't have control of the WiFi router, but that could be part of the problem. Yes, I'm using a Core, and the router gives it a fixed IP address of 10.0.0.43.

I tried it again, and got the same DNS IP address. Following that, it successfully resolved textbelt.com...but the TCPClient failed to connect to the resolved IP address!
I'll try connecting the Core to my phone's WiFi hotspot. If everything's hunky dory after that, I know what to blame.

Connected my Core to my phoneā€™s unsecured WiFi hotspot. The response?

DNS host: 192.168.43.1

Result? Same. It was able to resolve the first hostname (textbelt.com), but not the second (smtp.gmx.com). Actually, there was no response back from textbelt.com and no message sent. Obviously, I didnā€™t get an e-mail from GMX, either.

@bko: Quick question, as this could possibly be the issue: Is it good practice to define my TCPClient in the declarations at the head of the source code? I do understand that there are no destructors specified for the TCPClient/TCPServer, but am running out of things to try to resolve this issue.
As in:

#define RS_DEBUG      // for RS-232 printout.

TCPClient cClient;    // our own TCPClient
char cmStr[80];
int mBase, mWork;

//-----------------------------------------------------------------------------
// Glue-wrapper routine 
//-----------------------------------------------------------------------------
void SendNotify(char *Message)
{
   ...

Basically, Iā€™m getting random DNS fails on every single build Iā€™ve tried, (now) from Particle Dev IDE, to RELEASE 0.4.3, LATEST and DEVELOP.

FWIW: My WiFi router is using OpenDNS.

EDIT: some more thoughts. The TCPServer/TCPClient server is working very nicely, and reliably. BUTā€¦that code also creates a new TCPClient structure for each connection. Could it be that in my notification code, thereā€™s some ā€œstrayā€ values not getting reset in the structure that are causing these connection issues with my publicly-defined TCPClient instance?

:cloud: connection seems to be what breaks it. Disable the cloud (Iā€™m in manual modeā€¦itā€™s easy to do), and bingo: 100% transmission success rate, and 100% DNS resolveā€¦
ā€¦the only problem? My local Sprint tower just died again, so I havenā€™t received a single message. Cheers!

Iā€™m experimenting with adding Spark.process() to strategic locations around the loop.