Troubleshooting Email from Core

Based on what I have from https://github.com/Clement87/PushingBox-for-Spark-Core

Try adding  
client.stop();
before client.connect.

I think that resets the connection prior to connect.

I tried this before and still not working. I also tried “google.com” example from Spark and result is same (not working). The same call client.connect was working before. But now, it is not.

Without seeing your code - the only thing else I can guess - did you include TCPClient client;

I just tested mine and it is working fine with PushingBox through to email, Newtifry and NotifyMyAndroid.

Finally discovered the problem. if I place the call client.connect before the Spark.publish in my code, then it works. Basically, send the email first, then trigger the event.
Now I got email from PushingBox which trigger by the core event.

Anyone has idea why ? I suppose there is conflict in resource usage inside the code ?

I had noticed one more issue, if I don’t perform client.stop, the system will reboot after a while.

I guess the issue is when your program loops, client.connect gets called over and over again with new sockets opened till it passes the limit and causing a fault. :slight_smile:

1 Like

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 ??