mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Remove broken NTP BMS reset functionality
This commit is contained in:
parent
d38a8d6655
commit
dc4aa95109
7 changed files with 101 additions and 210 deletions
|
@ -35,11 +35,6 @@
|
|||
#error You must select a target hardware in the USER_SETTINGS.h file!
|
||||
#endif
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
#include "src/devboard/utils/ntp_time.h"
|
||||
#endif
|
||||
volatile unsigned long long bmsResetTimeOffset = 0;
|
||||
|
||||
// The current software version, shown on webserver
|
||||
const char* version_number = "9.0.RC5experimental";
|
||||
|
||||
|
@ -152,15 +147,6 @@ void setup() {
|
|||
xTaskCreatePinnedToCore((TaskFunction_t)&core_loop, "core_loop", 4096, NULL, TASK_CORE_PRIO, &main_loop_task,
|
||||
esp32hal->CORE_FUNCTION_CORE());
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
bmsResetTimeOffset = getTimeOffsetfromNowUntil(PERIODIC_BMS_RESET_AT);
|
||||
if (bmsResetTimeOffset == 0) {
|
||||
set_event(EVENT_PERIODIC_BMS_RESET_AT_INIT_FAILED, 0);
|
||||
} else {
|
||||
set_event(EVENT_PERIODIC_BMS_RESET_AT_INIT_SUCCESS, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTF("setup() complete\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -71,11 +71,3 @@ volatile float CHARGER_MIN_HV = 200; // Min permissible output (VDC) of cha
|
|||
volatile float CHARGER_MAX_POWER = 3300; // Max power capable of charger, as a ceiling for validating config
|
||||
volatile float CHARGER_MAX_A = 11.5; // Max current output (amps) of charger
|
||||
volatile float CHARGER_END_A = 1.0; // Current at which charging is considered complete
|
||||
|
||||
#ifdef PERIODIC_BMS_RESET_AT
|
||||
// A list of rules for your zone can be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
|
||||
const char* time_zone =
|
||||
"GMT0BST,M3.5.0/1,M10.5.0"; // TimeZone rule for Europe/London including daylight adjustment rules (optional)
|
||||
const char* ntpServer1 = "pool.ntp.org";
|
||||
const char* ntpServer2 = "time.nist.gov";
|
||||
#endif
|
||||
|
|
|
@ -90,8 +90,6 @@
|
|||
//#define NC_CONTACTORS //Enable this line to control normally closed contactors. CONTACTOR_CONTROL must be enabled for this option. Extremely rare setting!
|
||||
//#define PERIODIC_BMS_RESET //Enable to have the emulator powercycle the connected battery every 24hours via GPIO. Useful for some batteries like Nissan LEAF
|
||||
//#define REMOTE_BMS_RESET //Enable to allow the emulator to remotely trigger a powercycle of the battery via MQTT. Useful for some batteries like Nissan LEAF
|
||||
// PERIODIC_BMS_RESET_AT Uses NTP server, internet required. In 24 Hour format WITHOUT leading 0. e.g 0230 should be 230. Time Zone is set in USER_SETTINGS.cpp
|
||||
//#define PERIODIC_BMS_RESET_AT 525
|
||||
|
||||
/* Shunt/Contactor settings (Optional) */
|
||||
//#define BMW_SBOX // SBOX relay control & battery current/voltage measurement
|
||||
|
|
|
@ -125,8 +125,6 @@ void init_events(void) {
|
|||
events.entries[EVENT_EQUIPMENT_STOP].level = EVENT_LEVEL_ERROR;
|
||||
events.entries[EVENT_SD_INIT_FAILED].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_PERIODIC_BMS_RESET].level = EVENT_LEVEL_INFO;
|
||||
events.entries[EVENT_PERIODIC_BMS_RESET_AT_INIT_SUCCESS].level = EVENT_LEVEL_INFO;
|
||||
events.entries[EVENT_PERIODIC_BMS_RESET_AT_INIT_FAILED].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_BATTERY_TEMP_DEVIATION_HIGH].level = EVENT_LEVEL_WARNING;
|
||||
events.entries[EVENT_GPIO_CONFLICT].level = EVENT_LEVEL_ERROR;
|
||||
events.entries[EVENT_GPIO_NOT_DEFINED].level = EVENT_LEVEL_ERROR;
|
||||
|
@ -365,11 +363,6 @@ String get_event_message_string(EVENTS_ENUM_TYPE event) {
|
|||
return "SD card initialization failed, check hardware. Power must be removed to reset the SD card.";
|
||||
case EVENT_PERIODIC_BMS_RESET:
|
||||
return "BMS Reset Event Completed.";
|
||||
case EVENT_PERIODIC_BMS_RESET_AT_INIT_SUCCESS:
|
||||
return "Successfully syncronised with the NTP Server. BMS will reset every 24 hours at defined time";
|
||||
case EVENT_PERIODIC_BMS_RESET_AT_INIT_FAILED:
|
||||
return "Failed to syncronise with the NTP Server. BMS will reset every 24 hours from when the emulator was "
|
||||
"powered on";
|
||||
case EVENT_GPIO_CONFLICT:
|
||||
return "GPIO Pin Conflict: The pin used by '" + esp32hal->failed_allocator() + "' is already allocated by '" +
|
||||
esp32hal->conflicting_allocator() + "'. Please check your configuration and assign different pins.";
|
||||
|
|
|
@ -107,8 +107,6 @@
|
|||
XX(EVENT_AUTOMATIC_PRECHARGE_FAILURE) \
|
||||
XX(EVENT_SD_INIT_FAILED) \
|
||||
XX(EVENT_PERIODIC_BMS_RESET) \
|
||||
XX(EVENT_PERIODIC_BMS_RESET_AT_INIT_SUCCESS) \
|
||||
XX(EVENT_PERIODIC_BMS_RESET_AT_INIT_FAILED) \
|
||||
XX(EVENT_BATTERY_TEMP_DEVIATION_HIGH) \
|
||||
XX(EVENT_GPIO_NOT_DEFINED) \
|
||||
XX(EVENT_GPIO_CONFLICT) \
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
#include "ntp_time.h"
|
||||
#include <Arduino.h>
|
||||
#include "../../devboard/utils/logging.h"
|
||||
#include "time.h"
|
||||
|
||||
const unsigned long millisInADay = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
||||
|
||||
unsigned long long getNtpTimeInMillis() {
|
||||
configTzTime(time_zone, ntpServer1, ntpServer2);
|
||||
struct tm timeinfo;
|
||||
|
||||
// Wait for time to be set
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (getLocalTime(&timeinfo)) {
|
||||
logging.println("Time retrieved from NTP Server");
|
||||
break;
|
||||
}
|
||||
logging.println("Waiting for NTP time...");
|
||||
}
|
||||
|
||||
if (!getLocalTime(&timeinfo)) {
|
||||
logging.println("Failed to obtain time");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert to milliseconds
|
||||
time_t epochTime = mktime(&timeinfo);
|
||||
return static_cast<unsigned long long>(epochTime) * 1000;
|
||||
}
|
||||
|
||||
// Function to calculate the difference in milliseconds to the next target time
|
||||
unsigned long long millisToNextTargetTime(unsigned long long currentMillis, int targetTime) {
|
||||
int hour = targetTime / 100;
|
||||
int minute = targetTime % 100;
|
||||
|
||||
time_t currentTime = currentMillis / 1000; // Convert milliseconds to seconds
|
||||
struct tm* timeinfo = localtime(¤tTime);
|
||||
|
||||
// Set timeinfo to the target time on the next day
|
||||
timeinfo->tm_hour = hour;
|
||||
timeinfo->tm_min = minute;
|
||||
timeinfo->tm_sec = 0;
|
||||
|
||||
// Increment day if the current time is past the target time
|
||||
if (mktime(timeinfo) <= currentTime) {
|
||||
timeinfo->tm_mday += 1;
|
||||
}
|
||||
time_t nextTargetTime = mktime(timeinfo);
|
||||
unsigned long long nextTargetMillis = static_cast<unsigned long long>(nextTargetTime) * 1000;
|
||||
return nextTargetMillis - currentMillis;
|
||||
}
|
||||
|
||||
unsigned long long getTimeOffsetfromNowUntil(int targetTime) {
|
||||
logging.println("Getting time offset from now until " + String(targetTime));
|
||||
unsigned long long timeinMillis = getNtpTimeInMillis();
|
||||
if (timeinMillis != 0) {
|
||||
logging.println("Time in millis: " + String(timeinMillis));
|
||||
unsigned long long timeOffsetUntilTargetTime = millisInADay - (millisToNextTargetTime(timeinMillis, targetTime));
|
||||
logging.println("Time offset until target time: " + String(timeOffsetUntilTargetTime));
|
||||
return timeOffsetUntilTargetTime;
|
||||
} else
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef __NTPTIME_H__
|
||||
#define __NTPTIME_H__
|
||||
|
||||
extern const char* ntpServer1;
|
||||
extern const char* ntpServer2;
|
||||
extern const char* time_zone;
|
||||
|
||||
unsigned long long getNtpTimeInMillis();
|
||||
unsigned long long millisToNextTargetTime(unsigned long long currentMillis, int targetTime);
|
||||
unsigned long long getTimeOffsetfromNowUntil(int targetTime);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue