bonjour
je butte sur un petit probleme
j’ai adapté un bout de soft qui me permet d’envoyer un mail si une porte est ouverte ou fermée
il fonctionne, mais 2 anomalies
1- a la reception du mail le champ expediteur "ex sur thunderbird " reste vierge
2- je souhaiterai faire apparaitre dans le champ du message l’heure de lenvoi
car le seul champ d’heure qui apparait est l’heure de l’ouverture de thunderbird
merci pour votre aide si vous pouvier me rajouter les lignes manquantes
cordialement a tous
je joint mon code
#include <SPI.h>
#include <Ethernet.h>
const int contactPorte =2;
boolean porteOuverte = 0;
boolean EtatPorte = 0;
/*** Configuration réseau ***/
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 100, 32);
IPAddress my_dns(212, 27, 40, 240);
IPAddress gateway(192, 168, 100, 254);
IPAddress subnet(255, 255, 255, 0);
/*** Configuration SMTP ***/
IPAddress smtpIp(212,27,48,4); // smtp.free.fr
int smtpPort = 25;
/*** Variables globales ***/
EthernetClient client;
/*** setup ***/
void setup() {
delay(5000);
// Lancement de la connexion ethernet
Ethernet.begin(mac, ip, my_dns, gateway, subnet);
// On attend une seconde que le réseau soit pret
delay(2000);
// Port série pour debug
Serial.begin(9600);
// Envoi d'un mail
pinMode(contactPorte, INPUT);
digitalWrite(contactPorte,HIGH);
}
void sendEmail(char* from, char* to, char* subject, char* body) {
char data[200];
Serial.println("Connexion...");
if (client.connect(smtpIp, smtpPort)) {
Serial.println("Connecté!");
telnetCmd("EHLO arduino\n");
sprintf(data, "MAIL From:<%s>\n", from);
telnetCmd(data);
sprintf(data, "RCPT To:<%s>\n", to);
telnetCmd(data);
sprintf(data, "DATA\nTo: %s\nSubject: %s\n%s\n.\n", to, subject, body);
telnetCmd(data);
}
else {
Serial.println("Connexion impossible");
}
client.stop();
}
// Envoi d'une commande telnet
// On n'analyse pas le retour, on suppose que la commande est bonne
void telnetCmd(char* command) {
if (client.connected()) {
Serial.print("> ");
Serial.println(command);
client.print(command);
}
// TODO : implémenter une vérification des codes retour ?
}
void loop() {
//-------------------------------------------
porteOuverte = digitalRead(contactPorte);
if ((porteOuverte==LOW) && (EtatPorte== LOW)) {
delay(20);
Serial.println("Fermeture ");//Serial.print(now.day(), DEC);Serial.print("-");Serial.print(now.month(), DEC);Serial.print("-");Serial.print(now.year(), DEC); Serial.print("/"); Serial.print(now.hour(), DEC);Serial.print("H");Serial.println(now.minute(), DEC);
sendEmail("xxxxxxxx@free.fr", "xxxxxxx@free.fr", "Acces haut Fermeture", "Fermeture");
EtatPorte= HIGH;
delay(200);
}
if ((porteOuverte==HIGH) && (EtatPorte== HIGH)) {
delay(20);
Serial.println("*Ouverture ");
sendEmail("xxxxxxx@free.fr", "xxxxxx@free.fr", "Acces haut Ouverture", "Ouverture");
EtatPorte= LOW;
delay(200);
}
}//fin loop