Hello, for my project I am making a School bell. I am attempting to make it ring according to the school period schedule which changes depending on the day.
The general idea is
if (day == 1 ||2||3||5) && (hour == 12) && (minutes == 30) && (0<seconds < 10) {
ringbell
}
and then ill copy this format for each time I need the bell to ring. Currently I have my arduino connected to wifi, connected to the NTP server, but now I am struggling on what the "day" "hour" "minutes" or "seconds" variable is. Please help me. This is the current code.
#include <Arduino.h>
#include <WiFi.h> //includes the libraries for wifi capability
#include <time.h> // includes the libraries for NTP Time
#include <sntp.h>
#define WIFI_NETWORK "Wifi" // these lines of code allow the arduino to connect to the wifi network
#define WIFI_PASSWORD "Wifipassword"
#define WIFI_TIMEOUT_MICROS 2000 // times out connection after 20 secs if not connected
const char* NTP_SERVER = "us.pool.ntp.org"; // server for NTP time
const char* TZ_INFO = "EST5EDT,M3.2.0/2:00:00,M11.1.0/2:00:00"; //time zone
void connectToWifi(){ //this entire void allows the arduino to print if it is connected
Serial.print("Connecting to WiFi");
WiFi.mode(WIFI_STA); //sets the mode as a standalone wifi user as opposed to a node
WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD) ; // my password and network name
unsigned long startAttemptTime = micros(); //defining variable for network connect timeout
while(WiFi.status() !=WL_CONNECTED && micros() - startAttemptTime < WIFI_TIMEOUT_MICROS){ //
Serial.print(".");
delay(100);
}
if(WiFi.status() != WL_CONNECTED){
Serial.println("Failed");
}else{
Serial.print("Connected"); // I could include here code to make the arduino sleep and stop attempting to connect, but I did not, I want it to conintously attempt
}
}
void printLocalTime() //code for NTP Time
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("No time available (yet)");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}
void timeavailable(struct timeval *t) // Callback function (get's called when time adjusts via NTP)
{
Serial.println("Got time adjustment from NTP!");
printLocalTime();
}
void bellringing() {
struct tm; {
if (int8_t tm::tm_wday == 1||2||3||5) {
if (tm_hour == 8 && tm_) {
digitalWrite(14, HIGH);
}
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // sets baud rate
sntp_set_time_sync_notification_cb( timeavailable );
configTzTime(TZ_INFO, NTP_SERVER); // Tells what the TZ and NTP server are
connectToWifi(); // runs wifi void
pinMode(14, OUTPUT);
}
void loop() {
if(WiFi.status() !=WL_CONNECTED) {
connectToWifi();
}
delay(5000); //prints time every 5 secounds
printLocalTime();
}