Buen Dia
he intentado varias opciones de agregarle a este codigo el envio de un correo electronico pero no logro realizarlo alguien me podria ayudar con la programación, no soy muy buena con esto y lo necesito para mi proyecto de grado
#include <SoftwareSerial.h>
SoftwareSerial espSerial = SoftwareSerial(2, 3);
// arduino RX pin=2 arduino TX pin=3 Conecte el arduino RX pin al modulo esp8266 TX pin-conecte el arduino TX pin al modulo esp8266 RX pin
#include “DHT.h”
//Nota: Para la nueva libreria del sensor DHT11 necesitara la libreria Adafruit_Sensor library
//Descarguela en el siguiente link: GitHub - adafruit/Adafruit_Sensor: Common sensor library
//Instalar el Software Arduino
#define DHTPIN 5 // Conecte el pin de señal del sensor DHT11 al pin digital 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
String apiKey = “XYKPF05PEFTNN0TL”; // Reemplazar con la clave WRITE API key de su canal de thingspeak
String ssid = “YIMADISATEO”; // SSID Red Wifi
String password = “sayimateo1”; // Contraseña Red Wifi
boolean DEBUG = true;
//============================================================ Mostar Respuesta
void showResponse(int waitTime) {
long t = millis();
char c;
while (t + waitTime > millis()) {
if (espSerial.available()) {
c = espSerial.read();
if (DEBUG) Serial.print(c);
}
}
}
//========================================================================
boolean thingSpeakWrite(float value1, float value2) {
String cmd = “AT+CIPSTART=“TCP”,”"; // TCP conexion
cmd += “184.106.153.149”; // api.thingspeak.com
cmd += “”,80";
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
if (espSerial.find(“Error”)) {
if (DEBUG) Serial.println(“AT+CIPSTART error”);
return false;
}
String getStr = “GET /update?api_key=”; // preparacion cadena GET
getStr += apiKey;
getStr += “&field1=”;
getStr += String(value1);
getStr += “&field2=”;
getStr += String(value2);
// getStr +="&field3=";
// getStr += String(value3);
// …
getStr += “\r\n\r\n”;
// Enviar longitud de datos
cmd = “AT+CIPSEND=”;
cmd += String(getStr.length());
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
delay(100);
if (espSerial.find(">")) {
espSerial.print(getStr);
if (DEBUG) Serial.print(getStr);
}
else {
espSerial.println(“AT+CIPCLOSE”);
// alert user
if (DEBUG) Serial.println(“AT+CIPCLOSE”);
return false;
}
return true;
}
//===================================================== Preparar
void setup() {
DEBUG = true; // Habilitar debug serie
Serial.begin(9600);
dht.begin(); // Iniciar sensor DHT
espSerial.begin(9600); // Habilitar software de serie
// La velocidad del modulo ESP8266 es probablemente de 115200
// Por esta razon se le configura al modulo ESP8266 la velocidad de 9600
//espSerial.println(“AT+RST”); // Esta linea realiza un reset del modulo ESP8266;
//showResponse(1000);
//espSerial.println(“AT+UART_CUR=9600,8,1,0,0”); // En esta linea se configura la velocidad de 9600 bps en el modulo ESP8266
//showResponse(1000);
espSerial.println(“AT+CWMODE=1”); // En esta linea se configura el modo de uso del ESP8266
showResponse(1000);
espSerial.println(“AT+CWJAP=”" + ssid + “”,"" + password + “”"); // Configuracion del SSID y Contraseña de la RED WiFi
showResponse(5000);
if (DEBUG) Serial.println(“Setup completed”);
}
// ====================================================================== loop
void loop() {
// Read sensor values
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(t) || isnan(h)) {
if (DEBUG) Serial.println(“Failed to read from DHT”);
}
else {
if (DEBUG) Serial.println(“Temp=” + String(t) + " *C");
if (DEBUG) Serial.println(“Humidity=” + String(h) + " %");
thingSpeakWrite(t, h); // Escribe los valores a thingspeak
}
// thingspeak necesita 5 Seg de retraso entre actualizaciones,
delay(5000);
}
thingspeak_esp8266.ino (4.56 KB)