Comments on: How To Do Daily Tasks with Arduino https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Mon, 26 Jun 2023 18:52:56 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Dave K. https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-842980 Mon, 26 Jun 2023 18:52:56 +0000 http://randomnerdtutorials.com/?p=44001#comment-842980 In reply to 3doorsDown.

“onceOnly Alarms and Timers are freed when they are triggered so another onceOnly alarm can be set to trigger again.
There is no limit to the number of times a onceOnly alarm can be reset.

The following fragment gives one example of how a timerOnce task can be rescheduled:
Alarm.timerOnce(random(10), randomTimer); // trigger after random number of seconds

void randomTimer(){
int period = random(2,10); // get a new random period
Alarm.timerOnce(period, randomTimer); // trigger for another random period”
…From the docs.

He is using a random variable, but you could also use one you have chosen in place of “period”. I didn’t try it, but I suspect this would need to reside in loop() or a function run from loop(), otherwise the alarm would not see the variable change.

Late, but maybe it will help?
Dave

]]>
By: Michael Brinster https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-828630 Thu, 06 Apr 2023 06:07:36 +0000 http://randomnerdtutorials.com/?p=44001#comment-828630 Hi, I would love to get this sketch working to open and close my shades every morning. This would be perfect….I included the libraries below… (Wire) because I read there is some dependency with one of the other libraries??
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
– I tried installing TimeLib, but Arduino installs TIme.
I’m using a DS3231, but still trying to use DS1307RTC library. When I changed it to DS3231RTC library I had errors. But now I am getting an error on the following line in the sketch– ‘tmElements_t’
the error is—“does not name a type; did you mean ‘timelib_month_t’?”
What do I do?

tmElements_t tm;

]]>
By: Michael Brinster https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-827981 Sun, 02 Apr 2023 17:24:09 +0000 http://randomnerdtutorials.com/?p=44001#comment-827981 I tried running the code, but I get an error -“tm eLements_t-tm does not name a type. Did you mean TimeLib_month_t?

What should I do?

]]>
By: Vespucci https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-815338 Sat, 04 Feb 2023 19:50:25 +0000 http://randomnerdtutorials.com/?p=44001#comment-815338 Is there a possibility to have an “on-auto-off” switch which has priority over the timer?
Say I want to turn the lights “on” manually already one hour earlier. Before I leave, I turn to “auto” that in the next morning they turn on again.
Or I come earlier in the morning and switch manually “off”. When I leave I switch to “auto” to get back to the original rhythm.

]]>
By: 3doorsDown https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-802858 Tue, 13 Dec 2022 13:21:27 +0000 http://randomnerdtutorials.com/?p=44001#comment-802858 Hello to everyone, I would like to resettable time schedule via Nextion HMI screen.

I am using Arduino mega and would like to make a kind of greenhouse. That’s why I need the resettable time scheduled watering system. When I put Alarm.alarmRepeat into void setup() function it works but I can not set it again without rebooting.

When I put Alarm.alarmRepeat into void loop() function only the first alarm is triggered. The second alarm doesn’t trigger.

Are there any suggestions for me?

]]>
By: 鍾佳哲 https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-788739 Wed, 05 Oct 2022 09:18:25 +0000 http://randomnerdtutorials.com/?p=44001#comment-788739 Alarm.alarmRepeat(HH,MM,SS,MyFunction);
Is there a set cap, I need 20 to run my function

]]>
By: Hassan,Nikkhoo https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-770275 Thu, 21 Jul 2022 12:38:24 +0000 http://randomnerdtutorials.com/?p=44001#comment-770275 Hello
I have obtained the date and time by connecting to Wi-Fi and I want to write one or more alarms in the program, can anyone help me?
my Program:
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-date-time-ntp-client-server-arduino/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

#include <WiFi.h>
#include “time.h”

const char* ssid = “1234”;
const char* password = “1234”;

const char* ntpServer = “pool.ntp.org”;
const long gmtOffset_sec = 12600;
const int daylightOffset_sec = 3600;

void setup(){
Serial.begin(115200);
// Connect to Wi-Fi
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected.”);

// Init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();

//disconnect WiFi as it’s no longer needed
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
}

void loop(){

printLocalTime();

delay(1000);

}

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”);

}

]]>
By: Marc https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-588309 Sun, 11 Apr 2021 17:57:08 +0000 http://randomnerdtutorials.com/?p=44001#comment-588309 Hi
I´m a beginner and trying to figure it out. It took me weeks before i discovered that my DS3231 device was damaged which was very frustrating because i thought i was doing something wrong.
Now i have it finally running and i´m using your sketch to switch a LEd on and off just like it´s explained here.
But what happens is that when i upload the sketch the LED goes on…when it reaches the Time for “MorningAlarm it goes off…when it reaches the time for the “EveningAlarm” it goes on again !!!!
What am i doing wrong !!! Can somebody help me please…this is so frustrating.

]]>
By: john https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-531401 Sun, 20 Dec 2020 15:02:12 +0000 http://randomnerdtutorials.com/?p=44001#comment-531401 can you look at this code. i took your temperature alarm code and applied it with this code so i can have it send a email at 7:00am every day but it gives me a error of ‘alarm’ does not name a type. thank you for your help.
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include “ESP32_MailClient.h”
#include <TimeLib.h>
#include <TimeAlarms.h>

const char* ssid = “123456”;
const char* password = “123456”;

#define emailSenderAccount “1234567@gmail.com”
#define emailSenderPassword “1234”
#define smtpServer “smtp.gmail.com”
#define smtpServerPort 465
#define emailSubject “[ALERT] CES Building Loop Temperature”

String inputMessage = “1234567@gmail.com”;
String enableEmailChecked = “checked”;
String inputMessage2 = “true”;
// Default Temperature Thresholds
String inputMessage3 = “95”;
String inputMessage4 = “65”;
String lastTemperature;

const char index_html[] PROGMEM = R”rawliteral(

Email Notification with Temperature

DS18B20 Temperature

%TEMPERATURE% °F

ESP Email Notification

Email Address
Enable Email Notification
Upper Temperature Threshold
Lower Temperature Threshold

)rawliteral”;

void notFound(AsyncWebServerRequest *request) {
request->send(404, “text/plain”, “Not found”);
}

AsyncWebServer server(80);

String processor(const String& var){
//Serial.println(var);
if(var == “TEMPERATURE”){
return lastTemperature;
}
else if(var == “EMAIL_INPUT”){
return inputMessage;
}
else if(var == “ENABLE_EMAIL”){
return enableEmailChecked;
}
else if(var == “UPPER_THRESHOLD”){
return inputMessage3;
}
else if(var == “LOWER_THRESHOLD”){
return inputMessage4;
}
return String();
}

bool emailSent = false;

const char* PARAM_INPUT_1 = “email_input”;
const char* PARAM_INPUT_2 = “enable_email_input”;
const char* PARAM_INPUT_3 = “upper_threshold_input”;
const char* PARAM_INPUT_4 = “lower_threshold_input”;

unsigned long previousMillis = 0;
const long interval = 5000;

const int oneWireBus = 4;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

SMTPData smtpData;

void setup() {

Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println(“WiFi Failed!”);
return;
}
Serial.println();
Serial.print(“ESP IP Address: http://“);
Serial.println(WiFi.localIP());

sensors.begin();

server.on(“/”, HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, “text/html”, index_html, processor);
});

server.on(“/get”, HTTP_GET, [] (AsyncWebServerRequest *request) {

if (request->hasParam(PARAM_INPUT_1)) {
inputMessage = request->getParam(PARAM_INPUT_1)->value();

if (request->hasParam(PARAM_INPUT_2)) {
inputMessage2 = request->getParam(PARAM_INPUT_2)->value();
enableEmailChecked = "checked";
}
else {
inputMessage2 = "false";
enableEmailChecked = "";
}

if (request->hasParam(PARAM_INPUT_3)) {
inputMessage3 = request->getParam(PARAM_INPUT_3)->value();
}
if (request->hasParam(PARAM_INPUT_4)) {
inputMessage4 = request->getParam(PARAM_INPUT_4)->value();
}
}
else {
inputMessage = "No message sent";
}
Serial.println(inputMessage);
Serial.println(inputMessage2);
Serial.println(inputMessage3);
Serial.println(inputMessage4);
request->send(200, "text/html", "HTTP GET request sent to your ESP.<br><a href=\"/\">Return to Home Page</a>");

});
server.onNotFound(notFound);
server.begin();
}
Alarm.alarmRepeat(7,0,0, MorningAlarm); // 7:00am every day
void loop() {

unsigned long currentMillis = millis();
if (currentMillis – previousMillis >= interval) {
previousMillis = currentMillis;
sensors.requestTemperatures();
// Temperature in Fahrenheit degrees
float temperature = sensors.getTempFByIndex(0);
Serial.print(temperature);
Serial.println(” *F”);

// Temperature in Fahrenheit degrees
/*float temperature = sensors.getTempFByIndex(0);
SerialMon.print(temperature);
SerialMon.println(" *F");*/

lastTemperature = String(temperature);

// Check if temperature is above threshold and if it needs to send the Email alert
if(temperature > inputMessage3.toFloat() && inputMessage2 == "true" && !emailSent){
String emailMessage = String("Temperature above threshold. Current temperature: ") +
String(temperature) + String("F");
if(sendEmailNotification(emailMessage)) {
Serial.println(emailMessage);
emailSent = true;
}

void MorningAlarm () {
Serial.println(temerature);
}
else {
Serial.println(“Email failed to send”);
}
}
// Check if temperature is below threshold and if it needs to send the Email alert
if(temperature < inputMessage4.toFloat() && inputMessage2 == “true” && !emailSent){
String emailMessage = String(“Temperature below threshold. Current temperature: “) +
String(temperature) + String(“F”);
if(sendEmailNotification(emailMessage)) {
Serial.println(emailMessage);
emailSent = true;
}
else {
Serial.println(“Email failed to send”);
}
}
}
}

bool sendEmailNotification(String emailMessage){
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);

// For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be
// enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
//smtpData.setSTARTTLS(true);

// Set the sender name and Email
smtpData.setSender(“CES Loop Sensor”, emailSenderAccount);

// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority(“High”);

// Set the subject
smtpData.setSubject(emailSubject);

// Set the message with HTML format
smtpData.setMessage(emailMessage, true);

// Add recipients
smtpData.addRecipient(inputMessage);

smtpData.setSendCallback(sendCallback);

// Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData)) {
Serial.println(“Error sending Email, ” + MailClient.smtpErrorReason());
return false;
}
// Clear all data from Email object to free memory
smtpData.empty();
return true;
}

// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
// Print the current status
Serial.println(msg.info());

// Do something when complete
if (msg.success()) {
Serial.println(“—————-“);
}
}

]]>
By: Sara Santos https://randomnerdtutorials.com/how-to-do-daily-tasks-with-arduino/#comment-511379 Wed, 28 Oct 2020 12:12:56 +0000 http://randomnerdtutorials.com/?p=44001#comment-511379 In reply to Georg Berthelsen.

Hi.
That error means that the code is crashing the ESP32 board.
We built this example for the Arduino. So, it’s probably not compatible with the ESP32.
Regards,
Sara

]]>