From 035e2d43a589162d7c931d74fe6f0f586474295d Mon Sep 17 00:00:00 2001 From: witnessmenow Date: Mon, 19 Jun 2023 18:00:44 +0100 Subject: [PATCH 1/3] Making Telegram support optional --- F1-Notifications/F1-Notifications.ino | 24 +++++++++++++++++------- F1-Notifications/config.h | 4 ++++ F1-Notifications/raceLogic.h | 6 ++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/F1-Notifications/F1-Notifications.ino b/F1-Notifications/F1-Notifications.ino index 28acd09..bd7ec89 100644 --- a/F1-Notifications/F1-Notifications.ino +++ b/F1-Notifications/F1-Notifications.ino @@ -215,17 +215,27 @@ bool notificaitonEventRaised = false; void sendNotification() { // Cause it could be set to the image one - secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); - Serial.println("Sending notifcation"); - f1Config.currentRaceNotification = sendNotificationOfNextRace(&bot); - if (!f1Config.currentRaceNotification) { - //Notificaiton failed, raise event again - Serial.println("Notfication failed"); - setEvent( sendNotification, getNotifyTime() ); + if (f1Config.isTelegramConfigured()) { + secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); + Serial.println("Sending notifcation"); + f1Config.currentRaceNotification = sendNotificationOfNextRace(&bot); + if (!f1Config.currentRaceNotification) { + //Notificaiton failed, raise event again + Serial.println("Notfication failed"); + setEvent( sendNotification, getNotifyTime() ); + } else { + notificaitonEventRaised = false; + f1Config.saveConfigFile(); + } } else { + + Serial.println("Would have sent Notification now, but telegram is not configured"); + notificaitonEventRaised = false; + f1Config.currentRaceNotification = true; f1Config.saveConfigFile(); } + } bool first = true; diff --git a/F1-Notifications/config.h b/F1-Notifications/config.h index 2fbb29c..c6a9ca3 100644 --- a/F1-Notifications/config.h +++ b/F1-Notifications/config.h @@ -25,6 +25,10 @@ class F1Config { bool currentRaceNotification = false; + bool isTelegramConfigured(){ + return (botToken != "") && (chatId != "") + } + bool fetchConfigFile() { if (SPIFFS.exists(F1_CONFIG_JSON)) { //file exists, reading and loading diff --git a/F1-Notifications/raceLogic.h b/F1-Notifications/raceLogic.h index 7aae0f6..1643557 100644 --- a/F1-Notifications/raceLogic.h +++ b/F1-Notifications/raceLogic.h @@ -166,6 +166,12 @@ int fetchRaceJson(FileFetcher fileFetcher) { } bool saveCurrentRaceToFile(const JsonObject& raceJson) { + + if(raceJson.isNull()){ + Serial.println("Race data is null, nothing to save"); + return false; + } + File currentRaceFile = SPIFFS.open(CURRENT_RACE_FILE_NAME, "w"); if (!currentRaceFile) { Serial.println("failed to open config file for writing"); From 08c3879c0f5d274b018c232918b18cd6901a0ffe Mon Sep 17 00:00:00 2001 From: witnessmenow Date: Mon, 19 Jun 2023 20:02:45 +0100 Subject: [PATCH 2/3] fixed typo --- F1-Notifications/F1-Notifications.ino | 2 +- F1-Notifications/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/F1-Notifications/F1-Notifications.ino b/F1-Notifications/F1-Notifications.ino index bd7ec89..f09241c 100644 --- a/F1-Notifications/F1-Notifications.ino +++ b/F1-Notifications/F1-Notifications.ino @@ -23,7 +23,7 @@ //#define YELLOW_DISPLAY // 2. Matrix Displays (Like the ESP32 Trinity) -//#define MATRIX_DISPLAY +#define MATRIX_DISPLAY // If no defines are set, it will default to CYD #if !defined(YELLOW_DISPLAY) && !defined(MATRIX_DISPLAY) diff --git a/F1-Notifications/config.h b/F1-Notifications/config.h index c6a9ca3..cbb2a9a 100644 --- a/F1-Notifications/config.h +++ b/F1-Notifications/config.h @@ -26,7 +26,7 @@ class F1Config { bool currentRaceNotification = false; bool isTelegramConfigured(){ - return (botToken != "") && (chatId != "") + return (botToken != "") && (chatId != ""); } bool fetchConfigFile() { From 250206ba66397d33ba964d8c0d6b2768e5e286d1 Mon Sep 17 00:00:00 2001 From: witnessmenow Date: Tue, 27 Jun 2023 05:54:16 +0100 Subject: [PATCH 3/3] This doesn't seem to be needed, not sure if it caused the blank notification though --- F1-Notifications/raceLogic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/F1-Notifications/raceLogic.h b/F1-Notifications/raceLogic.h index 1643557..158128f 100644 --- a/F1-Notifications/raceLogic.h +++ b/F1-Notifications/raceLogic.h @@ -235,7 +235,7 @@ bool getNextRace(int &offset, bool ¬ificationSent, F1Display* f1Display, bool bool newRace = false; int roundNumber = races[i]["round"]; if (roundNumber != offset) { - if (saveCurrentRaceToFile(races[i].to())) { + if (saveCurrentRaceToFile(races[i])) { offset = roundNumber; notificationSent = false; Serial.println("New Race");