Ok, well, got a few things working and a little bit closer to the source of the problem, I think. Thank you guys for all your help and input, definitely wouldn’t have gotten anywhere even close to where I am without it!
So, here’s where I am at… I got the core hooked up via USB and I can putty in and see all the serial print stuff (yaaaay), then I compared some code to the arduino playground email code and grabbed a little function that reads the output and prints it back to the serial monitor. Finally I also added in the timer above to measure the length of time I am sitting in the SendMail function (whew). Now I am seeing a “Timeout” in the middle of that routine - it gets as far as this line:
client.println("DATA");
It starts timing out there fairly consistently, the problem is that it times out WELL before 10 seconds, so I am guessing this isn’t a hard and fast rule. I guess my next step would be to pull down the code and modify the timeout values?
Anyway, here is the current code:
uint32_t counter = 0;
long lastUp = 0;
int SenseDelay = 10000;
byte smtp[] = { 46, 105, 158, 236 }; //mailjet SMTP server
//int SensorValue = A0;
int SensorValue = 200;
TCPClient client;
void setup() {
pinMode(D7, OUTPUT); // Turn on the D7 led so we know it's time
digitalWrite(D7, HIGH); // to open the Serial Terminal.
Serial.begin(9600); // Open serial over USB.
while(!Serial.available()); // Wait here until the user presses ENTER in the Serial Terminal
digitalWrite(D7, LOW); // Turn off the D7 led ... your serial is serializing!
pinMode(SensorValue,INPUT);
}
void loop() {
if (millis() - lastUp > SenseDelay) {
if (analogRead(SensorValue) > 300) {
char SubjectString[] = "Sensor Check";
char Body1String[] = "Values in range!";
SendMail(SubjectString, Body1String, analogRead(SensorValue));
lastUp = millis();
} else if (analogRead(SensorValue) < 300) {
char SubjectString[] = "Sensor Check";
char Body1String[] = "Values out of range!";
SendMail(SubjectString, Body1String, analogRead(SensorValue));
lastUp = millis();
} else {
Serial.println("Some weird failure.");
lastUp = millis();
}
}
}
void SendMail(char *Subject, char *Body, int Sensor) {
if (client.connect(smtp,587)) { //Successful connection to SMTP Server
uint32_t start = millis();
Serial.print("1st operation done at: "); Serial.print.ln(millis() - start / 1000);
client.println("EHLO kltan");
if(!eRcv());
Serial.println();
client.println("AUTH LOGIN");
if(!eRcv());
Serial.println();
client.println("username=");
if(!eRcv());
Serial.println();
client.println("password=");
if(!eRcv());
Serial.println();
client.println("MAIL FROM:<blah@gmail.com>");
if(!eRcv());
Serial.println();
client.println("RCPT TO:<blah@gmail.com>");
if(!eRcv());
Serial.println();
client.println("DATA");
if(!eRcv());
Serial.println();
Serial.print("Last operation done at: "); Serial.print.ln(millis() - start / 1000);
Serial.println();
client.println("from:blah@gmail.com");
if(!eRcv());
Serial.println();
/*client.println("to:blah@gmail.com");
if(!eRcv());
Serial.println();
client.print("SUBJECT: ");
if(!eRcv());
Serial.println();
client.println(Subject);
if(!eRcv());
Serial.println();
client.print(Body);
if(!eRcv());
Serial.println();
client.println(Sensor);
if(!eRcv());
Serial.println();
client.println(".");
if(!eRcv());
Serial.println();
client.println(".");
if(!eRcv());
Serial.println();
client.println("QUIT");
if(!eRcv());
Serial.println();
*/
client.flush();
} else {} //SMTP Server Connection failed
/*int bytecount = client.available();
while (bytecount>0) {
char c = client.read();
bytecount--;
}*/
//Disconnecting from the SMTP server.
client.stop();
}
byte eRcv() {
byte respCode;
byte thisByte;
char c;
int loopCount = 0;
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 500ms, timeout
if(loopCount > 2000) {
client.stop();
Serial.println("\r\nTimeout");
return 0;
}
}
respCode = client.peek();
while(client.available()) {
c = client.read();
Serial.print(c);
}
if(respCode >= '4') {
return 0;
}
return 1;
}
I have unfortunately run out of time right now and the web gui is acting funky now for some reason when I factory reset the core now - won’t let me select my core in the gui for some weird reason. Good time to hit the hay, will hopefully be able to make further progress tomorrow.