Hello
How can you make an action between 10 p.m. and 7 a.m. with the code ESP32 Time and Date?
during the compilation, I have the default: ISO C ++ forbids comparison between pointer and integer [-fpermissive]
thanks in advance
Hello
thanks for you reaction
here is the code
the if with the hour is found on line 444
/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com
liste des signaux entrants
1: cave
– température chaudière (entre 20 et 100)
– Kg pellets (entre 10000 et 99000)
– porte cave ( entre 120 et 121)
– niveau silo pellet ( entre 200 et 400 )
– niveau du puits (entre 1000 et 1500 )ajout de 1000 à la mesure
2: garage
porte vitrée garage (entre 2010 et 2011) (ajout de 2010 au signal)
porte garage entre 2020 et 2021 (ajout de 2020 au signal)
porte atelier entre 2030 et 2031 (ajout de 2030 au signal)
détection incendie (entre 2040 et 2041 (ajout de 2040 au signal)
serre
température serre entre 3000 et 3100 )ajout de +/- 3000 à la mesure pour 3050 =0°
humidité serre entre 3200 et 3300 ajout de +/- 3200 à la mesure
*********/
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
#include <WebServer.h>
#include “time.h”
const char* ntpServer = “pool.ntp.org”;
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 3600;
#include <ESP_Mail_Client.h>
// Import required libraries
#ifdef ESP32
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#else
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>S
#endif
// Variables to store temperature values
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 2000;
// Replace with your network credentials
const char* ssid = “xxxxx”;
const char* password = “xxxxxxx”;
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
#define BAND 866E6
String LoRaData;
int count;
int LoRaDataInt;
int compteur;
int impulsion;
int KgPellets;
int KgPelletsLoRa;
int NiveauPuits;
int PorteCave;
int countmailChaudiere=0;
int countmailPuits=0;
int countmailPorteCave=0;
float temperature_C;
float temperatureChaudiere;
char timeHour[3];
//tempSensor2, tempSensor3;
////////////////////
#define SMTP_HOST “smtp.gmail.com”
#define SMTP_PORT 465
/* The sign in credentials */
#define AUTHOR_EMAIL “xxxxxxx@gmail.com”
#define AUTHOR_PASSWORD “xxxxxxxxx”
/* Recipient’s email*/
#define RECIPIENT_EMAIL “xxxxxxxx@gmail.com”
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
//////////////////
// Create AsyncWebServer object on port 80
//AsyncWebServer server(80);
WebServer server(80);
void handle_OnConnect()
{
server.send(200, “text/html”, SendHTML(temperatureChaudiere,compteur,NiveauPuits));
}
void handle_NotFound()
{
server.send(404, “text/plain”, “Not found”);
}
String SendHTML(float temperatureChaudiere,int compteur,int NiveauPuits)
{
String ptr = “<!DOCTYPE html> <html>\n”;
ptr +=”<head><meta name=\”viewport\” content=\”width=device-width, initial-scale=1.0, user-scalable=no\”>\n”;
ptr +=”<title>ESP32 Temperature Monitor</title>\n”;
ptr +=”<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n”;
ptr +=”body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n”;
ptr +=”p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n”;
ptr +=”</style>\n”;
ptr +=”</head>\n”;
ptr +=”<body>\n”;
ptr +=”<div id=\”webpage\”>\n”;
ptr +=”<h1>ESP32 Monitoring </h1>\n”;
ptr +=”<p>Temperature chaudiere: “;
ptr +=temperatureChaudiere;
ptr +=”°C</p>”;
ptr +=”<p>vis pellets: “;
ptr +=KgPellets;
ptr +=”Kg;</p>”;
ptr +=”<p>niveau Puits: “;
ptr +=NiveauPuits;
ptr +=”CM;</p>”;
ptr +=”<p>Porte Cave: “;
ptr +=PorteCave;
ptr +=”</div>\n”;
ptr +=”</body>\n”;
ptr +=”</html>\n”;
return ptr;
}
///////////////////////
//////////////////////
/* 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())
{
Serial.println(“—————-“);
ESP_MAIL_PRINTF(“Message sent success: %d\n”, status.completedCount());
ESP_MAIL_PRINTF(“Message sent failled: %d\n”, status.failedCount());
Serial.println(“—————-\n”);
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
localtime_r(&ts, &dt);
ESP_MAIL_PRINTF(“Message No: %d\n”, i + 1);
ESP_MAIL_PRINTF(“Status: %s\n”, result.completed ? “success” : “failed”);
ESP_MAIL_PRINTF(“Date/Time: %d/%d/%d %d:%d:%d\n”, dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
ESP_MAIL_PRINTF(“Recipient: %s\n”, result.recipients);
ESP_MAIL_PRINTF(“Subject: %s\n”, result.subject);
}
Serial.println(“—————-\n”);
}
}
void EnvoiMailTempChaudiere()
{
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Set the message headers */
message.sender.name = “ESP chemin de huy 34 “;
message.sender.email = AUTHOR_EMAIL;
message.subject = “Alarme”;
message.addRecipient(“”, RECIPIENT_EMAIL);
/*Send HTML message*/
String htmlMsg = “<div style=\”color:#2f4468;\”><h1>Alarme Chaudiére</h1><p>- Sent from ESP board</p></div>”;
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;
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending Email and close the session */
{
if (!MailClient.sendMail(&smtp, &message))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
countmailChaudiere++;
}
///////////////////////
void EnvoiMailPorteCave()
{
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Set the message headers */
message.sender.name = “ESP chemin de huy 34 “;
message.sender.email = AUTHOR_EMAIL;
message.subject = “Alarme Porte Cave”;
message.addRecipient(“”, RECIPIENT_EMAIL);
/*Send HTML message*/
String htmlMsg = “<div style=\”color:#2f4468;\”><h3>Alarme Porte Cave</h1><p>- Sent from ESP board</p></div>”;
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;
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending Email and close the session */
{
if (!MailClient.sendMail(&smtp, &message))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
countmailPorteCave++;
}
///////////////////////
void EnvoiMailPuits()
{
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = “”;
/* Declare the message class */
SMTP_Message message;
/* Set the message headers */
message.sender.name = “ESP chemin de huy 34 “;
message.sender.email = AUTHOR_EMAIL;
message.subject = “Alarme”;
message.addRecipient(“”, RECIPIENT_EMAIL);
/*Send HTML message*/
String htmlMsg = “<div style=\”color:#2f4468;\”><h1>Puit niveau bas</h1><p>- Sent from ESP board</p></div>”;
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;
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending Email and close the session */
{
if (!MailClient.sendMail(&smtp, &message))
Serial.println(“Error sending Email, ” + smtp.errorReason());
}
countmailPuits++;
}
///////////////////////
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo))
{
Serial.println(“Failed to obtain time”);
return;
}
Serial.println(&timeinfo, “%A, %B %d %Y %H:%M:%S”);
//Serial.print(“Hour: “);
//Serial.println(&timeinfo, “%H”);
// Serial.println(“Time variables”);
strftime(timeHour,3, “%H”, &timeinfo);
//Serial.println(timeHour);
//Serial.println(timeHourInt);
char timeWeekDay[10];
strftime(timeWeekDay,10, “%A”, &timeinfo);
//Serial.println(timeWeekDay);
//Serial.println();
}
//////////////////////////////////////////////////////////////////////////////////////
void setup()
{
// Serial port for debugging purposes
Serial.begin(115200);
Serial.println();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.println(“Connecting to WiFi”);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println();
// Print ESP Local IP Address
Serial.println(WiFi.localIP());
// Start server
server.begin();
server.on(“/”, handle_OnConnect);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println(“LoRa Receiver Test”);
//SPI LoRa pins
SPI.begin(SCK, MISO, MOSI, SS);
//setup LoRa transceiver module
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(BAND))
{
Serial.println(“Starting LoRa failed!”);
while (1);
}
Serial.println(“LoRa Initializing OK!”);
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
}
void loop()
{
printLocalTime();
server.handleClient();
if ((millis() – lastTime) > timerDelay)
{
lastTime = millis();
}
//try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize)
{
//received a packet
//Serial.print(“Received packet “);
//read packet
while (LoRa.available())
{
LoRaData = LoRa.readString();
Serial.print(“LoRaData = “);
Serial.println(LoRaData);
}
LoRaDataInt = LoRaData.toInt();
Serial.print(“LoRaDataInt = “);
Serial.println(LoRaDataInt);
///////////
// température chaudiére
//////////
if ((LoRaDataInt > 1)&&(LoRaDataInt < 100))
{
temperatureChaudiere = LoRaDataInt;
}
///////////
// Kilos pellets
//////////
if (LoRaDataInt > 10000)
{
KgPelletsLoRa = LoRaDataInt;
KgPellets = KgPelletsLoRa-10000;
}
///////////
// niveau puits
//////////
if ((LoRaDataInt > 1000)&&(LoRaDataInt < 1500))
{
NiveauPuits = LoRaDataInt;
}
///////////
// porte cave
//////////
if (timeHour >= 22)
if (timeHour < 7)
if((LoRaDataInt == 121)&&(countmailPorteCave < 2))
{
EnvoiMailPorteCave();
}
if (NiveauPuits == 120)
{
countmailPorteCave = 0;
}
///////////
// niveau puits
//////////
if ((LoRaDataInt > 1000)&&(LoRaDataInt < 1500))
{
NiveauPuits = LoRaDataInt;
}
}
if((NiveauPuits == 1010)&&(countmailPuits < 2))
{
EnvoiMailPuits();
}
if (NiveauPuits > 150)
{
countmailPuits=0;
}
////////////
//temp chaudiere
////////////
if((temperatureChaudiere > 28)&&(countmailChaudiere < 2))
{
EnvoiMailTempChaudiere();
}
if (temperatureChaudiere < 28)
{
countmailChaudiere=0;
}
//Serial.print(“temperatureChaudiere = “);
//Serial.println(temperatureChaudiere);
//Serial.print(“countmailChaudiere = “);
//Serial.println(countmailChaudiere);
//Serial.print(“Kg Pellet = “);
//Serial.println(KgPellets);
//Serial.print(“Porte Cave = “);
//Serial.println(PorteCave);
//printLocalTime();
delay(1000);
}
///////////////////////
//fin loop
/////////////////
Hi.
It seems that line 444 is commented, so that can’t be the source of the error.
It is very difficult to read code like this.
Please post your code using a link to Github, pastebin, google drive, etc…
For the error, you’re getting, this discussion might help:
Regards,
Sara
Hello
I found the solution
https://forum.arduino.cc/t/time-library-functions-with-esp32-core/515397/5
Thank you for your help