MRK1010 board
Trying to accomplish a task once a day, at a certain time. That task is send an email via Blynk with a daily max sensor value calculation (that code is omitted). Through my searching I have found an alarm function that seems to be the hot ticket, although, of course I can't get it to work. I think it doesn't work because it does not know the time? I am getting my current time from NTP server, but I think I need code that is something along of the lines of telling setTime, what time is coming in from server. Anybody mind telling me what I am doing wrong?
#include <Smoothed.h>
#include <Blynk.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <TimeAlarms.h>
char ssid[] = "-----";
char pass[] = "-----";
int status = WL_IDLE_STATUS;
const char auth[] = "dcy3wWSGO-ApB1uKvh9cUiEZ21HrPiab";
BlynkTimer timer;
WidgetLCD lcd(V1);
WidgetLED ledChange(V3);
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;
const byte wifiPin = 4;
const byte noWifiPin = 5;
void setup() {
Serial.begin(9600);
int attempts = 0;
while (status != WL_CONNECTED && attempts < 6) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.print(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
attempts++;
}
if (status != WL_CONNECTED) {
Serial.print("Failed to connect to Wifi!");
digitalWrite(noWifiPin, HIGH);
delay(1000);
digitalWrite(noWifiPin, LOW);
delay(1000);
while (true);
}
Serial.print("You're connected to the network");
digitalWrite(wifiPin, HIGH);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
pinMode(wifiPin, OUTPUT);
pinMode(noWifiPin, OUTPUT);
// Initialize a NTPClient to get time
timeClient.begin();
timeClient.setTimeOffset(-21600);
Alarm.alarmRepeat(21,32,0, EmailAlarm);
}
void loop() {
Blynk.run();
timer.run();
timeClient.update();
}
void myTimerEvent()
{
lcd.print(4, 0, "Current Time");
lcd.print(4, 1, timeClient.getFormattedTime());
}
void EmailAlarm(){
Blynk.email("-----", "FilterLynk Condition", "Test";
}