Skip to content

Commit

Permalink
Merge pull request #391 from OpenEVSE/jeremypoulter/issue350
Browse files Browse the repository at this point in the history
Apply a random start delay to the timer
  • Loading branch information
jeremypoulter authored Jul 20, 2022
2 parents d84c7d2 + 87a0ef9 commit 752553c
Show file tree
Hide file tree
Showing 18 changed files with 5,545 additions and 5,318 deletions.
44 changes: 32 additions & 12 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ paths:
description: |
The status endpoint can be called to get the status of the EVSE.
While it is posible to poll this endpoint, the recomendatoin is to retrieve the initial
state then use the [/ws](#statusUpdates)
While it is posible to poll this endpoint, the recomendatoin is to retrieve the initial
state then use the [/ws](#statusUpdates)
responses:
'200':
description: OK
Expand Down Expand Up @@ -78,7 +78,7 @@ paths:
operationId: statusUpdates
summary: EVSE status updates
description: |
As the state changes on the EVSE a websocket frame will be sent over the socket.
As the state changes on the EVSE a websocket frame will be sent over the socket.
The frame will contain a JSON document conntaining only the updated state.
responses:
'200':
Expand Down Expand Up @@ -404,6 +404,24 @@ paths:
tags:
- Schedule
summary: Remove event
/schedule/plan:
get:
summary: Get planned events and state
description: This will return the planned events by day and also the current state of the scheduler
responses:
'200':
description: List of planed events
content:
application/json:
schema:
type: object
properties:
current_day:
$ref: '#/components/schemas/Day'

operationId: getSchedulePlan
tags:
- Schedule
/logs:
get:
summary: Get event block information
Expand Down Expand Up @@ -512,6 +530,16 @@ components:
msg:
type: string
description: The message
Day:
type: string
enum:
- monday
- tuesday
- wednesday
- thursday
- friday
- saturday
- sunday
ScheduleEvent:
type: object
properties:
Expand All @@ -527,15 +555,7 @@ components:
type: array
uniqueItems: true
items:
type: string
enum:
- monday
- tuesday
- wednesday
- thursday
- friday
- saturday
- sunday
$ref: '#/components/schemas/Day'
required:
- state
- time
Expand Down
5 changes: 5 additions & 0 deletions min_spiffs_debug.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x3C0000,
spiffs, data, spiffs, 0x3D0000,0x30000,
7 changes: 7 additions & 0 deletions models/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,10 @@ properties:
charge_mode:
type: string
minLength: 1
scheduler_start_window:
type: number
default: 600
description: >
The maximum number of seconds to randomly add/subtract from the a scheduled charge start time,
eg a value of 600 will adjust the start time my +/- 10 minutes. This is to help prevent large
syncrinised loads when multiple verchiles start charging at the same time.
25 changes: 18 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ default_envs = openevse_wifi_v1

[common]
version = -D BUILD_TAG=4.1.3
monitor_speed = 115200
lib_deps =
bblanchon/ArduinoJson@6.19.1
jeremypoulter/ArduinoMongoose@0.0.18
Expand All @@ -50,9 +49,10 @@ debug_flags =
-D ENABLE_DEBUG
#-D ENABLE_DEBUG_WEB
#-D ENABLE_DEBUG_WEB_REQUEST
#-D ENABLE_DEBUG_SCHEDULER
-D ENABLE_DEBUG_SCHEDULER
# -D ENABLE_DEBUG_TIME
#-D ENABLE_DEBUG_EVSE_MAN
#-D ENABLE_DEBUG_EVSE_MONITOR
-D ENABLE_DEBUG_EVSE_MONITOR
#-D ENABLE_DEBUG_DIVERT
#-D ENABLE_DEBUG_LED
#-D ENABLE_DEBUG_LCD
Expand Down Expand Up @@ -91,6 +91,7 @@ build_flags =
-D USE_ESP32
-D USE_ESP32_FRAMEWORK_ARDUINO
build_partitions = min_spiffs.csv
build_partitions_debug = min_spiffs_debug.csv

neopixel_lib = adafruit/Adafruit NeoPixel@1.7.0

Expand All @@ -101,7 +102,7 @@ neopixel_lib = adafruit/Adafruit NeoPixel@1.7.0
#platform = https://github.com/platformio/platform-espressif32.git#feature/stage
#platform = https://github.com/platformio/platform-espressif32.git#develop
#platform = espressif32@1.11.1
platform = espressif32@4.4.0
platform = espressif32@5.0.0
#framework = arduino, espidf
framework = arduino
lib_deps = ${common.lib_deps}
Expand All @@ -117,7 +118,8 @@ board_build.partitions = ${common.build_partitions}
# ; use a special branch
# framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
# platformio/framework-arduinoespressif32 @ ~3.10006.0
monitor_filters = esp32_exception_decoder
monitor_filters =
esp32_exception_decoder

[env:openevse_nodemcu-32s]
board = nodemcu-32s
Expand Down Expand Up @@ -154,6 +156,8 @@ build_flags =
#upload_protocol = espota
upload_speed = 2000000
#upload_protocol = ftdi
#debug_tool = ftdi
#board_build.partitions = ${common.build_partitions_debug}

# export PLATFORMIO_UPLOAD_PORT=172.16.0.157
# export PLATFORMIO_UPLOAD_FLAGS="-p 3232"
Expand Down Expand Up @@ -262,10 +266,17 @@ build_flags =
-D RANDOM_SEED_CHANNEL=1
-D RX2=16
-D TX2=32
-D PHY_PWR=5
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"
upload_speed = 921600
monitor_flags =
--filter=esp32_exception_decoder

[env:openevse_esp32-gateway-e_dev]
extends = env:openevse_esp32-gateway-e
build_flags =
${env:openevse_esp32-gateway-e.build_flags}
${common.debug_flags}
build_type = debug
board_build.partitions = ${common.build_partitions_debug}

[env:openevse_esp32-heltec-wifi-lora-v2]
board = heltec_wifi_lora_32_V2
Expand Down
8 changes: 8 additions & 0 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ String rfid_storage;

long max_current_soft;

// Scheduler settings
uint32_t scheduler_start_window;

String esp_hostname_default = "openevse-"+ESPAL.getShortId();

void config_changed(String name);
Expand Down Expand Up @@ -162,6 +165,9 @@ ConfigOpt *opts[] =
new ConfigOptDefenition<uint8_t>(led_brightness, LED_DEFAULT_BRIGHTNESS, "led_brightness", "lb"),
#endif

// Scheduler options
new ConfigOptDefenition<uint32_t>(scheduler_start_window, SCHEDULER_DEFAULT_START_WINDOW, "scheduler_start_window", "ssw"),

// Flags
&flagsOpt,

Expand Down Expand Up @@ -236,6 +242,8 @@ void config_changed(String name)
ArduinoOcppTask::notifyConfigChanged();
} else if(name.startsWith("emoncms_")) {
emoncms_updated = true;
} else if(name.startsWith("scheduler_")) {
scheduler.notifyConfigChanged();
} else if(name == "divert_enabled" || name == "charge_mode") {
DBUGVAR(config_divert_enabled());
DBUGVAR(config_charge_mode());
Expand Down
5 changes: 4 additions & 1 deletion src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ extern double divert_attack_smoothing_factor;
extern double divert_decay_smoothing_factor;
extern uint32_t divert_min_charge_time;

// Scheduler settings
extern uint32_t scheduler_start_window;

// 24-bits of Flags
extern uint32_t flags;

Expand Down Expand Up @@ -137,7 +140,7 @@ inline bool config_pause_uses_disabled() {
inline bool config_vehicle_range_miles() {
return CONFIG_VEHICLE_RANGE_MILES == (flags & CONFIG_VEHICLE_RANGE_MILES);
}

inline bool config_rfid_enabled() {
return CONFIG_RFID == (flags & CONFIG_RFID);
}
Expand Down
3 changes: 3 additions & 0 deletions src/divert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ void divert_update_state()
event["available_current"] = available_current;
event["smoothed_available_current"] = smoothed_available_current;
event["pilot"] = evse.getChargeCurrent();
event["min_charge_end"] = (divert_active && divertmode_get_time() < min_charge_end) ?
min_charge_end - divertmode_get_time() :
0;
} // end ecomode

event_send(event);
Expand Down
4 changes: 4 additions & 0 deletions src/emonesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
#define LED_DEFAULT_BRIGHTNESS 128
#endif

#ifndef SCHEDULER_DEFAULT_START_WINDOW
#define SCHEDULER_DEFAULT_START_WINDOW 600
#endif

#ifndef FORMAT_LITTLEFS_IF_FAILED
#define FORMAT_LITTLEFS_IF_FAILED true
#endif // !FORMAT_LITTLEFS_IF_FAILED
Expand Down
8 changes: 8 additions & 0 deletions src/net_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ net_setup()

#ifdef ENABLE_WIRED_ETHERNET
//ETH.setHostname(esp_hostname.c_str());

#ifdef PHY_PWR
pinMode(PHY_PWR, OUTPUT);
digitalWrite(PHY_PWR, LOW);
delay(1000);
digitalWrite(PHY_PWR, HIGH);
#endif

ETH.begin();
#endif

Expand Down
Loading

0 comments on commit 752553c

Please sign in to comment.