Programmation pour le Système de détection des fuites de gaz intelligent contrôlé par Arduino
Programmation pour le Système de détection des fuites de gaz intelligent contrôlé par Arduino
#include <Adafruit_ESP8266.h>
#include <SoftwareSerial.h>
#define ESP_RX 3
#define ESP_TX 4
#define ESP_RST 8
#define HOST “Nom du serveur SMTP” // Find/Google your email provider’s SMTP outgoing server
name for unencrypted email
#define PORT 587 // Find/Google your email provider’s SMTP outgoing port for unencrypted email
int count = 0; // we’ll use this int to keep track of which command we need to send next
bool send_flag = false; // we’ll use this flag to know when to send the email commands
void setup() {
pinMode(btnPin,INPUT_PULLUP);
char buffer[50];
wifi.setBootMarker(F(“Version:0.9.2.4]\r\n\r\nready”));
Serial.print(F(“Hard reset…”));
if(!wifi.hardReset()) {
for(;;);
Serial.println(F(“OK.”));
Serial.print(F(“Soft reset…”));
if(!wifi.softReset()) {
for(;;);
Serial.println(F(“OK.”));
wifi.println(F(“AT+GMR”));
if(wifi.readLine(buffer, sizeof(buffer))) {
Serial.println(buffer);
} else {
Serial.println(F(“error”));
Serial.print(F(“Connecting to WiFi…”));
if(wifi.connectToAP(F(ESP_SSID), F(ESP_PASS))) {
Serial.print(F(“OK\nChecking IP addr…”));
wifi.println(F(“AT+CIFSR”));
if(wifi.readLine(buffer, sizeof(buffer))) {
Serial.println(buffer);
wifi.find(); // Discard the ‘OK’ that follows
Serial.print(F(“Connecting to host…”));
Serial.print(“Connected..”);
wifi.find();
wifi.find();
Serial.println(F(“error”));
Serial.println(F(“FAIL”));
void loop() {
analogVal = analogRead(analogPin);
//Serial.println(btnVal);
delay(1000);
}
}
if(send_flag){ // the send_flat is set, this means we are or need to start sending SMTP commands
count++; // increment the count so that the next command will be executed next time.
boolean do_next()
switch(count){
case 0:
Serial.println(“Connecting…”);
break;
case 1:
// send “HELO ip_address” command. Server will reply with “250” and welcome message
break;
case 2:
// send “AUTH LOGIN” command to the server will reply with “334 username” base 64 encoded
break;
case 3:
// send username/email base 64 encoded, the server will reply with “334 password” base 64
encoded
return wifi.cipSend(EMAIL_FROM_BASE64,F(“334 UGFzc3dvcmQ6”));
break;
case 4:
// send password base 64 encoded, upon successful login the server will reply with 235.
return wifi.cipSend(EMAIL_PASSWORD_BASE64,F(“235”));
break;
case 5:{
char mailFrom[50] = “MAIL FROM:<“; // If 50 is not long enough change it, do the same for the array
in the other cases
strcat(mailFrom,EMAIL_FROM);
strcat(mailFrom,”>”);
return wifi.cipSend(mailFrom,F(“250”));
break;
case 6:{
strcat(rcptTo,EMAIL_TO);
strcat(rcptTo,”>”);
return wifi.cipSend(rcptTo,F(“250”));
break;
case 7:
// Send “DATA” command, the server will reply with something like “334 end message with \r\n.\r\
n.”
return wifi.cipSend(“DATA”,F(“354”));
break;
case 8:{
strcat(from,” “);
strcat(from,”<“);
strcat(from,EMAIL_FROM);
strcat(from,”>”);
return wifi.cipSend(from);
break;
case 9:{
// apply TO header
strcat(to,EMAIL_TO);
strcat(to,”<“);
strcat(to,EMAIL_TO);
strcat(to,”>”);
return wifi.cipSend(to);
break;
case 10:{
strcat(subject,SUBJECT);
return wifi.cipSend(subject);
break;
case 11:
break;
case 12:
return wifi.cipSend(EMAIL_CONTENT);
break;
case 13:
break;
case 14:
return wifi.cipSend(“QUIT”);
break;
case 15:
wifi.closeTCP();
return true;
break;
case 16:
Serial.println(“Done”);
send_flag = false;
count = 0;
break;
default:
break;