Troubleshooting Email from Core

Continuing the discussion from Email from the core:

Perhaps this will help...

"gmail requires an encrypted connection using TLS via the STARTTLS command. The Spark core cannot directly send email using gmail service since it cannot do TLS encryption right now. You must use
a service on the internet to act between the core and gmail. Pushingbox.com is one such service, but Spark will be introducing their own service that can do this in the future."

1 Like

Oh no, I just got the code and reach the same point with this error using gmail :frowning:
Any idea when Spark will support a method to send email ?

Thanks

ah ! …this may be exactly what i need - thanx @MisterNetwork :slight_smile:

BTW - I just started playing with Pushingbox as a solution to sending texts/emails, and it works great and integrates easily with the Spark.

@MisterNetwork - which code are you using? The Lib from github won’t compile… Am I missing something?

In file included from …/inc/spark_wiring.h:30:0,
from …/inc/application.h:29,
from pushingbox.cpp:2:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
#warning “Defaulting to Release Build”
^
pushingbox.cpp: In function ‘void setup()’:
pushingbox.cpp:36:37: warning: ‘char* NetworkClass::SSID()’ is deprecated (declared at …/inc/spark_wiring_network.h:39): Please use WiFi.SSID() instead [-Wdeprecated-declarations]
pinMode(LED, OUTPUT); // sets LED as output
^
pushingbox.cpp:38:40: warning: ‘IPAddress NetworkClass::localIP()’ is deprecated (declared at …/inc/spark_wiring_network.h:36): Please use WiFi.localIP() instead [-Wdeprecated-declarations]

^
pushingbox.cpp:40:42: warning: ‘IPAddress NetworkClass::gatewayIP()’ is deprecated (declared at …/inc/spark_wiring_network.h:38): Please use WiFi.gatewayIP() instead [-Wdeprecated-declarations]
if(DEBUG){
^
pushingbox.cpp:42:43: warning: ‘IPAddress NetworkClass::subnetMask()’ is deprecated (declared at …/inc/spark_wiring_network.h:37): Please use WiFi.subnetMask() instead [-Wdeprecated-declarations]
Serial.println(Network.SSID());
^
pushingbox.cpp:44:37: warning: ‘int8_t NetworkClass::RSSI()’ is deprecated (declared at …/inc/spark_wiring_network.h:40): Please use WiFi.RSSI() instead [-Wdeprecated-declarations]
Serial.println(Network.localIP());
^
pushingbox.cpp: In function ‘void sendToPushingBox(const char*)’:
pushingbox.cpp:89:41: warning: ‘int8_t NetworkClass::RSSI()’ is deprecated (declared at …/inc/spark_wiring_network.h:40): Please use WiFi.RSSI() instead [-Wdeprecated-declarations]
client.println(“User-Agent: Spark”);
^
pushingbox.o: In function setup': /spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:36: undefined reference toNetworkClass::SSID()’
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:38: undefined reference to NetworkClass::localIP()' /spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:40: undefined reference toNetworkClass::gatewayIP()’
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:42: undefined reference to NetworkClass::subnetMask()' /spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:44: undefined reference toNetworkClass::RSSI()’
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:46: undefined reference to Network' pushingbox.o: In functionsendToPushingBox(char const*)’:
/spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:89: undefined reference to NetworkClass::RSSI()' /spark/compile_server/shared/workspace/worker_1/core-firmware/build/pushingbox.cpp:96: undefined reference toNetwork’
collect2: error: ld returned 1 exit status
make: *** [c137152db14f5e6f59c9a1ab3d37e3672e7be9b6534ad6bf35bb295a611d.elf] Error 1

Ahh! I noticed some errors when I compiled, too. It doesn’t like "Network"class: rss: etc. Need to replace “Network” with “WiFi” …

if(DEBUG){
        Serial.print("SSID: ");
        Serial.println(WiFi.SSID());
        Serial.print("Core IP: ");
        Serial.println(WiFi.localIP());    
        Serial.print("Gateway: ");
        Serial.println(WiFi.gatewayIP());
        Serial.print("Mask: ");
        Serial.println(WiFi.subnetMask());
        Serial.print("WiFi RSSI: ");
        Serial.println(WiFi.RSSI());
    }

1 Like

thx @MisterNetwork - compiling :smile:

Cool!
After you get it working - perhaps you can help me.
I’m still battling with adding files to my firmware in Spark Build
Is there a rule of thumb when adding a file like PushingBox-for-Spark.ino to existing firmware? Does it matter if it is has a .h or .cpp extension? How should I handle duplicate void Setup() and void Loop() ? I have been cutting and pasting into my main .ino but wasn’t sure if it was correct, or if there was an easier way??

Tnx

well i’m probably not he most qualified person around - however the h. and .cpp are “real” libraries, which will the use a #include in your main file, this is more like a piece of example code really.
So yes cut and paste the parts from Setup() and Void() that you need and the put the rest at the bottom as far as I know there’s no better way to do it.

I tried to connect to server but failed in the client.connect
Did I miss anything important in setup ?

TCPClient client; // Client

void sendToPushingBox(const char * devid)
{

Serial.println("connecting... ");
if (client.connect("api.pushingbox.com", 80)) 

{
Serial.println("connected");
}
else
{
Serial.println("connection failed");
}
}

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.