Dear Arduino friends,
I have bought an ESP12E Board by NodeMCU to realise my favorite project: I want to recieve an Email, when my mailbox is opened, so I don't need to check it every day.
I am able to send a simple Email with SMTP2Go to my mail account. Now I want to initialize this process, when the Board recieves an interrupt on pin 4. I checked and it seems that this is the correct pin.
I attached my attempt to integrate the sending-process as an Interrupt-Service-Routine. But it seems that the "attachtInterrupt" function doesn't accept byte-functions. In line 17 i get the error:
"invalid conversion from 'byte ()() {aka unsigned char ()()}' to 'void (*)()' [-fpermissive]".
I tried to convert the byte functions into void, but it just got worse. Since i'm not a programming expert I hope that someone has an idea, how to integrate the whole process into an ISR, in order to set the board to a low-power mode in the next step.
Thank's for your help!
#include <ESP8266WiFi.h> // the ESP8266WiFi.h lib
const char* SSID = "*******";
const char* PASS = "*********";
char server[] = "mail.smtpcorp.com";
ADC_MODE(ADC_VCC);
WiFiClient client;
void setup()
{
pinMode(4, INPUT);
}
void loop()
{
attachInterrupt(digitalPinToInterrupt(4), sendEmail, HIGH);
}
byte sendEmail(){
Serial.begin(115200);
delay(10);
Serial.println("");
Serial.println("");
Serial.print("Connecting To ");
Serial.println(SSID);
WiFi.begin(SSID, PASS);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
byte ret = sendEmail();
byte thisByte = 0;
byte respCode;
if (client.connect(server, 2525) == 1) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if (!eRcv()) return 0;
Serial.println(F("Sending EHLO"));
client.println("EHLO www.example.com");
if (!eRcv()) return 0;
Serial.println(F("Sending auth login"));
client.println("auth login");
if (!eRcv()) return 0;
Serial.println(F("Sending User"));
// Change to your base64, ASCII encoded user
client.println("*************"); // SMTP UserID
if (!eRcv()) return 0;
Serial.println(F("Sending Password"));
// change to your base64, ASCII encoded password
client.println("***********");// SMTP Passw
if (!eRcv()) return 0;
Serial.println(F("Sending From")); // change to your email address (sender)
client.println(F("MAIL From: esp@gmail.com"));// not important
if (!eRcv()) return 0; // change to recipient address
Serial.println(F("Sending To"));
client.println(F("RCPT To: **********"));
if (!eRcv()) return 0;
Serial.println(F("Sending DATA"));
client.println(F("DATA"));
if (!eRcv()) return 0;
Serial.println(F("Sending email")); // change to recipient address
client.println(F("To: *************")); // change to your address
client.println(F("From: ***********"));
client.println(F("Subject: Emails from ESp8266\r\n"));
client.print(F("Power is: "));
client.print(ESP.getVcc());
client.println(F("mV"));
client.print(F("Device Chip ID: "));
client.println(ESP.getChipId());
Serial.print(F("Voltage is: "));
Serial.print(ESP.getVcc());
client.println(F("."));
if (!eRcv()) return 0;
Serial.println(F("Sending QUIT"));
client.println(F("QUIT"));
if (!eRcv()) return 0;
client.stop();
Serial.println(F("disconnected"));
return 1;
}
byte eRcv()
{
byte respCode;
byte thisByte;
int loopCount = 0;
while (!client.available())
{
delay(1);
loopCount++; // if nothing received for 10 seconds, timeout
if (loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return 0;
}
}
respCode = client.peek();
while (client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
if (respCode >= '4')
{
// efail();
return 0;
}
return 1;
while(1){
}
}