Troubleshooting Email from Core

This is not case, I have a flag to perform only once per event. Also, I have enabled the serial print to monitor the activities. I got it all working now but requires to have specific calling sequence of client.connect and Spark.publish. and must perform client.stop before the server disconnect.

I double check the timing using the terminal commands to PushingBox. It will disconnect right after it receive all the commands. And that the time, SparkCore will reboot if connection is not already stopped.

HELP again. This was working last week and I changed other part of the code, then the client is not working again. It seems to missing something and sensitive to certain order of the code. In order to use TCPClient, do I need to include any .h file ?

Here is the order of the code. I tried this in setup() and loop() and both come back failed.

TCPClient client;

void SendEmail(void)
{
if (client.connect(“api.pushingbox.com”, 80)==true)
Serial.println("-- connected --");
else
Serial.println(“failed”);

    client.flush();
    client.stop();

}

Hi @Dilbert

Have you changed from a sketch (.ino file) to a library (.cpp/.h file)? Only sketches have the Arduino preprocessor run on them, so for a library you have to follow the real C/C++ rule with function prototypes and #include "application.h" to get access to the Spark includes.

Had done this already. The code is located in a .cpp file and #include “application.h” as indicated.
Strange is : this code was working and stop working after I changed code in other files. So, nothing had changed in the “SendEmail” function which will communicate to the URL.

Additional test being done on a Test Apps which only has the ino file and no other library attached. Make the TCPClient connect call in the “Setup()” and also failed :frowning:

OK, found a workaround. If I use the IP address directly, then it OK.

byte serverIP[] = { 213, 186, 33, 19 }; // pushing box

client.connect(serverIP, 80) --> OK
client.connect(“api.pushingbox.com”, 80) --> NO GOOD

Anyone has idea ?

It sounds like DNS service from your router is not working. Are other hosts on your network having any trouble with domain names?

I have the same issue frequently… thats the exact reason why i ported this

but it will give you an error now, it needs updating… ill fix it tomorrow… but the fix is here if you need it sooner!

That is really cool and great for your satellite (I think) Internet link, but shouldn’t be needed by everyone. If you have a regular broadband connection, you should be able to use the built-in DNS client.

1 Like

i have some days on the home internet where it cant look-up, and that’s on 100mbit cable… not all the time and if you wait 5 mins it will work again. but yep your right on the slow satellite it never works

The strange thing is : the same address was working before. So, the router DNS lookup should be OK, I think. I did not experience other device having any problem. I am using my PC to lookup the IP address for the site.

One more strange error I am having is :frowning: I am trying to access the weather site

api.wunderground.com
serverIP[] = { 23, 195, 210, 80 };

I had validated this with the PuTTY and response is OK

GET /api/my ID/conditions/q/autoip.json HTTP/1.1
Host: api.wunderground.com

HTTP/1.1 200 OK
Server: Apache/1.3.42 (Unix) PHP/5.3.2

But when I use the SpareCore to communicate, it did not work…

HTTP/1.1 400 Bad Request
Server: AkamaiGHost
Mime-Version: 1.0

Hi @Dilbert

The response from AkamaiGHost indicates that this in an edge router, that is, Akamai is providing a sort of caching service for the host api.wunderground.com. You really, really need the Host: line in your HTTP request since that is the only way the edge router knows what host you actually wanted to talk to.

So I would check that your HTTP request has a valid Host: line.

Hi Brian,
Thanks for direction :slight_smile: Once again it is the line format issue.

  1. “\n\r” --> not working
  2. “\r\n” --> OK

I used the 1st format in the PushingBox.com is fine. But this one is not. I am a newbie to all the TCP IP stuff. How would I know which format each server will support ? Or the standard is using the 2nd one ??

remaining issue to solve is why DNS lookup not working…

Since I am using the online build option, how could I update your change in DNSClient.cpp ??

@Dilbert I have updated the files on Git today, they can be manually added as a library

To give you an idea of what its doing, it takes the serverName, connects to Google’s DNS, resolves the IP, and returns the IP into remote_addr. your function then uses remote_addr to pass to the TCPclient. because its already an IP address it doesn’t need to look it up.

in the online build page you can add tabs, there is a little plus up the top right. you will need to create a set of tabs (it adds *.cpp and *.h) name them “DNSclient” then add another set of tabs and call them “myUDP” once thats done you can delete just the “myUDP.cpp” as you don’t need it.

in the Git page linked to above there are 3 folders… example, inc and src. Copy and paste the text from DNSclient.cpp in the src folder into your new tab with the same name. then do the same for “DNSclient.h” and “myUDP.h” in the inc folder

When you add the tabs it will automatically add two lines -> “#include DNSclient.h” and “#include myUDP.h” you need to delete just the “#include myUDP.h” the other one is needed

Before the setup function you need to add:

IPAddress dnsServerIP(8,8,8,8);
IPAddress remote_addr;
DNSClient dns; 

At the top of your SendEmail function add this:

dns.begin(dnsServerIP);
dns.getHostByName(serverName, remote_addr);

and change this

if (client.connect("api.pushingbox.com", 80)==true) 

to this:

if (client.connect(remote_addr, 80)==true) 

The DNSclient will try 3 times if it cant connect the first time, the number can be changed on line 160 of DNSclient.cpp

Also each loop has a 5sec timeout… the time out can be changed on line 276 of DNSclient.cpp

Hi Chris,
So your solution is not using the SparkCore internal DNS service and lookup IP with this code, correct ? Do you believe this is a problem with original release FW ?
I am using Cable for ISP and speed is 15Mbps which should not be slow problem.
I also tried with both PuTTY and CURL today again, both working just fine. So I doubt this is my Router DNS issue (I hope not).

It was just a fix for the issue i had on really slow internet offshore, but then I had a few times at home where i didn’t get emails, so i added it to that core and i haven’t missed an email that i know of yet.

and yep I’m bypassing the built in one in favor of the one i ported from arduino

I should have done a bit more work testing where the core firmware failed and error numbers and see what we could do to change it, but its all well over my head and it was in c not cpp and i got so lost…

I dig through the previous discussion below and I got the same result by calling gethostbyname(); Is “-85” return status meant timeout or something else ?


0.0.0.0
-85
901

This make me wonder that I am having a different problem that u originally trying to resolve.

http://community.spark.io/t/connecting-with-tcpclient-code-and-ping-issues/5174

So the WifI class brings out a bunch of useful information from the TI CC3000 configuration, but that does not include the DNS server by default. But you can access it yourself and check that it makes sense for your router–normally the DNS host is the same as the gateway host and is your router.

Here’s how:

   IPAddress dnshost(ip_config.aucDNSServer[3], ip_config.aucDNSServer[2], ip_config.aucDNSServer[1], ip_config.aucDNSServer[0]);
    Serial.print(dnshost);

I sent some time on the TI side to try to find out what error the -85 return code means but I didn’t find it. These come from inside the TI CC3000 and not from core firmware (except for -1 when the host name is too long).

-85 is indeed a strange one… maybe we are stuffing something maybe a int32_t into the int16_t that we set for the return value

901 is the same timeout i got… that seems to be the built in timeout