MAJOR update. More like a Backup before things get Crazy

Added Websocket Support
Added Universal Message Handling for both MQTT and WS
Added Timekeeper Class, that handles Physical Clock and Scheduling
Added Bell Assignment Settings, Note to Bell mapping
This commit is contained in:
2025-09-05 19:27:13 +03:00
parent c1fa1d5e57
commit 101f9e7135
20 changed files with 10746 additions and 9766 deletions

View File

@@ -1,43 +1,4 @@
/*
Done Features:
- Initiate General Structure
- Add WiFi Support
- Add MQTT Support both for Subscribing and Publishing
- Add JSON support to handle MQTT messaging
- Add File Handling
- Add Melody Class with functions to Play/Pause/Stop etc.
- Add Main BellEngine
- Add custom Relay Timings (saved on-board)
- Add RTC support
- Add Timekeeper class, with functions to track time and call schedules
- Add OTA Update Functionality
- Add global logger with Mode Selection (None, Error, Warning, Info, Debug)
- Add Captive Portal / WiFi HotSpot
- Add NTP Time Sync
ToDo Features:
- Add reset to Factory Defaults button
- Add manual Sync-Time (for No-Connectivity Setups)
- Add the ability to report the list of melodies
- Add the ability to report a month's ScheduleEntry
- Add the ability to report the free space in SPIFFS.
- Add Bluetooth support
- Add WiFi Direct AP Support
- Add PCB Temperature Sensor
- Counters and Statistics:
- Counter for each bell (counts total times the bell ringed)
- Counter per bell, beats/minute for reliability and thermal protection. Warranty Void scenario.
- Counter per playback, to figure out which melody is the most played.
- Counter of items per Scheduler
*/
#include "logging.hpp"
#include <SD.h>
#include <FS.h>
#include <ETH.h>
@@ -51,37 +12,54 @@ ToDo Features:
#include <string>
#include <Wire.h>
#include <Adafruit_PCF8574.h>
#include "RTClib.h"
#include <WebServer.h>
#include <ESPAsyncWebServer.h>
#include <WiFiManager.h>
#include <AsyncUDP.h>
#include <RTClib.h>
// Custom Classes
#include "timekeeper.hpp"
// Hardware Constructors:
Adafruit_PCF8574 relays;
RTC_DS1307 rtc;
// Wrapper function to connect timekeeper to your relays
void relayWrite(int relayIndex, int state) {
relays.digitalWrite(relayIndex, state);
}
// SD Card Chip Select:
#define SD_CS 5
// Include Classes
#include "classes.hpp"
#include "class_player.hpp"
// Class Constructors
Timekeeper timekeeper;
AsyncMqttClient mqttClient;
Player player;
std::vector<uint16_t> melody_steps; // holds the steps of the melody. Should move into bell Engine.
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
AsyncWebSocketClient* activeClient = nullptr;
AsyncUDP udp;
constexpr uint16_t DISCOVERY_PORT = 32101;
uint32_t strikeCounters[16] = {0};
uint16_t bellLoad[16] = {0};
bool coolingActive = false;
#include "config.h"
#include "ota.hpp"
#include "functions.hpp"
#include "MQTT_Message_Handling.hpp"
#include "MQTT_WiFi_Utilities.hpp"
#include "commands_handling.hpp"
#include "MQTT_Functions.hpp"
#include "MQTT_Connection_Handling.hpp"
#include "WebSocket_Functions.hpp"
#include "PlaybackControls.hpp"
#include "bellEngine.hpp"
#include "dataLogging.hpp"
TaskHandle_t bellEngineHandle = NULL;
TimerHandle_t schedulerTimer;
@@ -111,11 +89,12 @@ void setup()
// do nothing
}
// Initialize RTC
if (!rtc.begin()) {
LOG_ERROR("Couldn't find RTC");
while(true) delay(10);
}
// Initialize timekeeper with NO clock outputs
timekeeper.begin(); // No parameters needed
// Connect the timekeeper to your relay controller
timekeeper.setRelayWriteFunction(relayWrite);
timekeeper.setClockOutputs(5, 4);
// Initialize Networking and MQTT
Network.onEvent(NetworkEvent);
@@ -135,7 +114,7 @@ void setup()
delay(100);
checkForUpdates(); // checks for updates online
syncTimeWithNTP(); // syncs time from NTP Server
setupUdpDiscovery();
delay(100);
@@ -149,6 +128,7 @@ void setup()
xTaskCreatePinnedToCore(bellEngine,"bellEngine", 8192, NULL, 1, &bellEngineHandle, 1);
xTaskCreatePinnedToCore(durationTimer, "durationTimer", 8192, NULL, 2, NULL, 1);
xTaskCreatePinnedToCore(relayControlTask, "Relay Control", 2048, NULL, 2, NULL, 1);
//xTaskCreatePinnedToCore(dataLogging, "dataLogging", 2048, NULL, 2, NULL, 1);
loadRelayTimings();
}
@@ -156,5 +136,5 @@ void setup()
void loop()
{
//Serial.printf("b1:%d - b2:%d - Bell 1 Load: %d \n",strikeCounters[0], strikeCounters[1], bellLoad[0]);
}