Bonjour a tous je suis desolé mais j’ai été absent quelques temps.
Voila mon probleme:
j’ai deux sonde sd 18b20 qui controle la temperature de congelateur.
Je precise que j’ai deja un dispositif qui fonctione mais je veux ammeliorer sur un banc d’essai.
Mon probleme :mes deux sondes indiquent la temperature zero. quand je vais dans ide je constate un device a 0.
A votre avis est-ce la carte ou bien la librairie qui ne fonctionne pas bien. J’ai testé 5 sondes avec le même resultat.
Si vous avez une piste je suis preneur merci
Voici le resultat obtenu :
onnecting to Wi-Fi
08:15:43.238 -> Connected with IP: 0.0.0.0
08:15:43.285 ->
08:15:54.674 -> Heure complete: 09:22:34
08:15:55.115 -> Heure complete: 09:22:35
08:15:55.972 -> 0 devices.
08:15:55.972 ->
08:15:55.972 -> controle temperature -10.00
08:15:55.972 -> temperature 1 :0.00
08:15:55.972 -> controle :-10.00
08:15:55.972 -> temperature 2 :
08:15:55.972 -> 0.00
08:15:55.972 -> c'est l'heure' 9
08:15:56.114 -> c'est la minute 22
08:15:56.114 -> test testheure
08:15:56.114 -> 9
/* le 20-08-2024 ici je modifie la facon d'envoie de mail . j'ai modifie le delay dans
loop a 1 minute et a 4 minutes dans testheure. Ce qui fait que tous le 5 minutes j'ai un
test.j'ai aussi ajouté un test if sur la comparaison de minute et currentMinute. normalement j'ai un test tous lers 4 minutes cee qui permet de decider si il y a mlail
donc a l'heure et la minute decidé*/
/**
* copier sur exemple
* Created by K. Suwatchai (Mobizt)
*
* Email: suwatchai@outlook.com
*
* Github: https://github.com/mobizt/ESP-Mail-Client
*
* Copyright (c) 2023 mobizt
*/
// This example shows how to send html message.
/** Note for library update from v2.x.x to v3.x.x.
*
* Struct data names changed
*
* "ESP_Mail_Session" changes to "Session_Config"
* "IMAP_Config" changes to "IMAP_Data"
*
* Changes in the examples
*
* ESP_Mail_Session session;
* to
* Session_Config config;
*
* IMAP_Config config;
* to
* IMAP_Data imap_data;
*/
#include <NTPClient.h>
#include "arduino_secrets.h"
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#include <WiFiUdp.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif __has_include(<WiFiNINA.h>)
//#include <WiFi101.h>
#elif __has_include(<WiFiS3.h>)
#include <WiFiS3.h>
#endif
#include <ESP_Mail_Client.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;
//-------------------------
float tempC; //sensor
float tempC1;//temperature du capteur 1
float tempC2;//temperature du capteur 2
float temperature1; //passage de temperature 1
float temperature2;//passage de temperature 2
char currentDate;// date du jour
//Concerne l'horloge
int monthDay;
int currentMonth;
int currentYear ;
int currentHour;
int currentMinute;
int numero;
int testurgence = 0;
//les controles
float controletemperature = -10; // temperature de controle d'alarme
//-------------------------------------------heure de declenchement---------------
int heure1 = 5;
int heure2 = 12;
int heure3 = 20;
// tous les tests boolean
bool demarre;
bool testSent = false;
bool timeUpdated = false;
bool sendMessage = true; // envoyer une notification à la mise sous tension.
bool contrheure;
bool testurgent;
bool controle1;
bool controle2;
bool temp1;
bool temp2;
//Nom des jours
String weekDays[7]={"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
//Noms des mois
String months[12]={"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre"};
// tous les string
String messagegeneral;
String formattedTime;
String tempe1 , tempe2;
String messagemail1a;
String messagemail2a;
String message1;
String color1;
String color2;
const unsigned long second = 1000;
const unsigned long minute = 60000;
const unsigned long heure =360000;
int deviceCount = 0; // pour la mesure de temperature
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
WiFiMulti multi;
#endif
void setup()
{
Serial.begin(38400);
sensors.begin(); // Mise en marche librairie
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
deviceCount = sensors.getDeviceCount();
#if defined(ARDUINO_ARCH_SAMD)
while (!Serial)
;
#endif
Serial.println();
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif
Serial.print("Connecting to Wi-Fi");
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* Set the network reconnection option */
MailClient.networkReconnect(true);
// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
MailClient.clearAP();
MailClient.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
}
void connectwifi(){
Serial.begin(9600);
#if defined(ARDUINO_ARCH_SAMD)
while (!Serial)
;
#endif
Serial.println();
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif
Serial.print("Connecting to Wi-Fi");
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* Set the network reconnection option */
MailClient.networkReconnect(true);
// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
MailClient.clearAP();
MailClient.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
setRTCtime();
}
void loop()
{
connectwifi();
delay(300);
setRTCtime();
getTempF();
testheure();
//urgence();
urgence1();
// mail1();
delay(minute);
}
//-----------horloge-------------
void setRTCtime(){
// Initialize a NTPClient to get time
timeClient.begin();
timeClient.setTimeOffset(7600);
timeClient.update();
time_t epochTime = timeClient.getEpochTime();
formattedTime = timeClient.getFormattedTime();
Serial.print("Heure complete: ");
Serial.println(formattedTime);
currentHour = timeClient.getHours();
String heurecourante = String(currentHour);
currentMinute = timeClient.getMinutes();
int currentSecond = timeClient.getSeconds();
String weekDay = weekDays[timeClient.getDay()];
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
monthDay = ptm->tm_mday;
currentMonth = ptm->tm_mon+1;
String currentMonthName = months[currentMonth-1];
currentYear = ptm->tm_year+1900;
}
//------------------test l'heure-----
void testheure() {
Serial.print(" c'est l'heure' ");
Serial.println(currentHour);
Serial.print(" c'est la minute ");
Serial.println(currentMinute);
if (currentHour == heure1 || currentHour == heure2 || currentHour == heure3) {
//nouveau
if (currentMinute >= 1 && currentMinute <= 5) {
Serial.print("minute ");
Serial.println(currentMinute);
testSent = false;
MessageMail();
mail1();
//EnvoiMail();
Serial.print("test reussi");
}
else Serial.print("pas bon");
}
Serial.println("test testheure");
// delay(minute * 4);//4 minutes
}
//---------------------------urgence------------
void urgence1(){
int heure1 = 5;
int heure2 = 9;
int heure3 = 17.50;
int heure4 = 19;
//Serial.println(heure1);
Serial.println(currentHour);
if (currentHour == heure1 || currentHour == heure2 || currentHour == heure3 || currentHour == heure4) {
if (currentMinute >= 1 && currentMinute <= 55) {
if (temp1 = true) {
//Serial.println("c'est une urgence dans urgence 1");
messagemail1a = (" Attention la temperature du congelateur 1 n'est pas bonne = " + String(temperature1, 1) + " Deg C");
color2 = "#FF0000";
//Serial.println(messagemail1a);
}
if (temp2 = true)
{
//Serial.println("c'esr une urgence dans urgence 2");
messagemail2a = (" Attention la temperature du congelateur 2 n'est pas bonne = " + String(temperature1, 1) + " Deg C");
color2 = "#FF0000";
//Serial.println(messagemail2a);
}
// Serial.println(testurgence);
mail1();
} else {
testurgence = 0;
}
}
delay(minute * 1);
}
//---------------------------temperature----------------
void getTempF() {
sensors.requestTemperatures();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
for (int i = 0; i < deviceCount; i++) {
numero = i + 1;
if (numero = 1) {
//Serial.println(tempC);
tempC1 = sensors.getTempCByIndex(i);
Serial.print("Temperature 1 :");
Serial.println(tempC1);
Serial.println("oui");
}
if (i = 1) {
tempC2 = sensors.getTempCByIndex(i);
Serial.print("Temperature 2 :");
Serial.println(tempC2);
}
}
temperature1 = tempC1;
temperature2 = tempC2;
//Serial.print("temperature 1 :");
//Serial.println(temperature1);
if (controletemperature <= temperature1) {
Serial.print("controle temperature ");
Serial.println(controletemperature);
Serial.print("temperature 1 :");
Serial.println(temperature1);
// si la temperature est inferieur
controle1 = true;
temp1 = true;
//message.subject = "ALARM";
//messagemail1a = ("la temperature du congelateur 1 n'est pas bonne = " + String(temperature1, 1) + " Deg C");
} else {
temp1 = false;
messagemail1a = ("la temperature du congelateur 1 est correct = " + String(temperature1, 1) + " Deg C");
//Serial.println(messagemail1a);
}
if (controletemperature <= temperature2) {
Serial.print("controle :");
Serial.println(controletemperature);
Serial.println("temperature 2 :");
Serial.println(temperature2);
temp2 = true;
//message.subject = "ALARM";
// messagemail2a = ("la temperature du congelateur 2 n'est pas bonne = " + String(temperature2, 1) + " Deg C");
//Serial.println(messagemail2a);
} else {
temp2 = false;
//message.subject = "Notification";
Serial.print("controle");
Serial.println(controletemperature);
Serial.print("temperature");
Serial.println(temperature2);
//message.subject = "Controle";
messagemail2a = ("la temperature du congelateur 2 est correct = " + String(temperature2, 1) + " Deg C");
//Serial.println(messagemail2a);
}
if (temp1 == true || temp2 == true) {
//message.subject = "Alarm";
// Serial.println("Alarm");
} else {
//message.subject = "Notification";
//Serial.println("Notification");
Serial.print(temp1);
Serial.print(temp2);
}
//Serial.println(messagemail1a);
//Serial.println(messagemail2a);
///--------------------------------
}
//------------------------Prepare le mail----------------
void MessageMail()
{
if (temp1 == false) {
messagemail1a = ("la temperature du congelateur 1 est correct = " + String(temperature1, 1) + " Deg C");
color1 = "#66CDAA";
} else
{
messagemail1a = ("la temperature du congelateur 1 n'est pas bonne = " + String(temperature1, 1) + " Deg C");
color1 = "#4682B4";
}
if (temp2 == false) {
messagemail2a = ("la temperature du congelateur 2 est correct = " + String(temperature2, 1) + " Deg C");
//Serial.println(messagemail1a);
color2 = "#66CDAA";
} else
{
messagemail2a = ("la temperature du congelateur 2 n'est pas bonne = " + String(temperature2, 1) + " Deg C");
//Serial.println(messagemail1a);
color2 = "#4682B4";
}
}
void EnvoiMail() {
/* Declare the Session_Config for user defined session credentials */
Session_Config config;
/* Set the session config */
config.server.host_name = SMTP_HOST;
config.server.port = SMTP_PORT;
config.login.email = AUTHOR_EMAIL;
config.login.password = AUTHOR_PASSWORD;
config.login.user_domain = F("127.0.0.1");
config.time.ntp_server = F("pool.ntp.org,time.nist.gov");
config.time.gmt_offset = 3;
config.time.day_light_offset = 0;
/* Declare the message class */
SMTP_Message message;
/* Set the message headers */
message.sender.name = F("message de arduino");
message.sender.email = AUTHOR_EMAIL;
message.subject = F("Etat des congelateurs");
message.addRecipient(F("Pour SERGE "), RECIPIENT_EMAIL);
message.html.charSet = F("us-ascii");
String message1 = messagemail1a;
String message2 = messagemail2a;
Serial.print("color1");
String htmlMsg;
htmlMsg.reserve(256);
htmlMsg = F("<div>");
htmlMsg += F("<h1 style=\"margin:0;color:");
htmlMsg += color1; htmlMsg += F(";\">");
htmlMsg += message1; htmlMsg += F("</h1>");
htmlMsg += F("<h1 style=\"margin:0;color:");
htmlMsg += color2; htmlMsg += F(";\">");
htmlMsg += message2; htmlMsg += F("</p></div>");
//---------------------------------------------
/*Send HTML message*/
message.html.content = htmlMsg.c_str();
//message.html.content = htmlMsg.c_str();
message.text.charSet = "us-ascii";
// message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;*/
/** The content transfer encoding e.g.
*/
message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
/** The message priority
* esp_mail_smtp_priority_high or 1
* esp_mail_smtp_priority_normal or 3
* esp_mail_smtp_priority_low or 5
* The default value is esp_mail_smtp_priority_low
*/
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
/** The Delivery Status Notifications e.g.
* esp_mail_smtp_notify_never
* esp_mail_smtp_notify_success
* esp_mail_smtp_notify_failure
* esp_mail_smtp_notify_delay
* The default value is esp_mail_smtp_notify_never
*/
// message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
/* Set the custom message header */
// message.addHeader(F("Message-ID: <abcde.fghij@gmail.com>"));
/* Set the TCP response read timeout in seconds */
// smtp.setTCPTimeout(10);
/* Connect to the server */
if (!smtp.connect(&config))
{
MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
return;
}
if (!smtp.isLoggedIn())
{
Serial.println("Error, Not yet logged in.");
}
else
{
if (smtp.isAuthenticated())
Serial.println("Successfully logged in.");
else
Serial.println("Connected with no Auth.");
}
/* Start sending Email and close the session */
if (!MailClient.sendMail(&smtp, &message))
MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
// to clear sending result log
// smtp.sendingResult.clear();
MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap());
}
void mail1(){
Serial.println("je passe a mail1");
//delay(5000);
//String htmlMsg = "<p>This is the <span style=\"color:#ff0000;\">message de serge pedussel</span> message.</p><p>SErge vous envoie un message .</p>";
// message.html.content = htmlMsg;
Serial.println(messagemail2a);
Serial.println(messagemail1a);
}
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status)
{
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success())
{
// MailClient.printf used in the examples is for format printing via debug Serial port
// that works for all supported Arduino platform SDKs e.g. SAMD, ESP32 and ESP8266.
// In ESP8266 and ESP32, you can use Serial.printf directly.
Serial.println("----------------");
MailClient.printf("Message sent success: %d\n", status.completedCount());
MailClient.printf("Message sent failed: %d\n", status.failedCount());
Serial.println("----------------\n");
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
// In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if
// your device time was synched with NTP server.
// Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970.
// You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970)
MailClient.printf("Message No: %d\n", i + 1);
MailClient.printf("Status: %s\n", result.completed ? "success" : "failed");
MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str());
MailClient.printf("Recipient: %s\n", result.recipients.c_str());
MailClient.printf("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");
Serial.print("c'est fait");
delay(5000);
// You need to clear sending result as the memory usage will grow up.
smtp.sendingResult.clear();
}
}