Skip to content

Commit 752553c

Browse files
Merge pull request #391 from OpenEVSE/jeremypoulter/issue350
Apply a random start delay to the timer
2 parents d84c7d2 + 87a0ef9 commit 752553c

18 files changed

+5545
-5318
lines changed

api.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ paths:
2424
description: |
2525
The status endpoint can be called to get the status of the EVSE.
2626
27-
While it is posible to poll this endpoint, the recomendatoin is to retrieve the initial
28-
state then use the [/ws](#statusUpdates)
27+
While it is posible to poll this endpoint, the recomendatoin is to retrieve the initial
28+
state then use the [/ws](#statusUpdates)
2929
responses:
3030
'200':
3131
description: OK
@@ -78,7 +78,7 @@ paths:
7878
operationId: statusUpdates
7979
summary: EVSE status updates
8080
description: |
81-
As the state changes on the EVSE a websocket frame will be sent over the socket.
81+
As the state changes on the EVSE a websocket frame will be sent over the socket.
8282
The frame will contain a JSON document conntaining only the updated state.
8383
responses:
8484
'200':
@@ -404,6 +404,24 @@ paths:
404404
tags:
405405
- Schedule
406406
summary: Remove event
407+
/schedule/plan:
408+
get:
409+
summary: Get planned events and state
410+
description: This will return the planned events by day and also the current state of the scheduler
411+
responses:
412+
'200':
413+
description: List of planed events
414+
content:
415+
application/json:
416+
schema:
417+
type: object
418+
properties:
419+
current_day:
420+
$ref: '#/components/schemas/Day'
421+
422+
operationId: getSchedulePlan
423+
tags:
424+
- Schedule
407425
/logs:
408426
get:
409427
summary: Get event block information
@@ -512,6 +530,16 @@ components:
512530
msg:
513531
type: string
514532
description: The message
533+
Day:
534+
type: string
535+
enum:
536+
- monday
537+
- tuesday
538+
- wednesday
539+
- thursday
540+
- friday
541+
- saturday
542+
- sunday
515543
ScheduleEvent:
516544
type: object
517545
properties:
@@ -527,15 +555,7 @@ components:
527555
type: array
528556
uniqueItems: true
529557
items:
530-
type: string
531-
enum:
532-
- monday
533-
- tuesday
534-
- wednesday
535-
- thursday
536-
- friday
537-
- saturday
538-
- sunday
558+
$ref: '#/components/schemas/Day'
539559
required:
540560
- state
541561
- time

min_spiffs_debug.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
nvs, data, nvs, 0x9000, 0x5000,
3+
otadata, data, ota, 0xe000, 0x2000,
4+
app0, app, ota_0, 0x10000, 0x3C0000,
5+
spiffs, data, spiffs, 0x3D0000,0x30000,

models/Config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,10 @@ properties:
356356
charge_mode:
357357
type: string
358358
minLength: 1
359+
scheduler_start_window:
360+
type: number
361+
default: 600
362+
description: >
363+
The maximum number of seconds to randomly add/subtract from the a scheduled charge start time,
364+
eg a value of 600 will adjust the start time my +/- 10 minutes. This is to help prevent large
365+
syncrinised loads when multiple verchiles start charging at the same time.

platformio.ini

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ default_envs = openevse_wifi_v1
3030

3131
[common]
3232
version = -D BUILD_TAG=4.1.3
33-
monitor_speed = 115200
3433
lib_deps =
3534
3635
jeremypoulter/[email protected]
@@ -50,9 +49,10 @@ debug_flags =
5049
-D ENABLE_DEBUG
5150
#-D ENABLE_DEBUG_WEB
5251
#-D ENABLE_DEBUG_WEB_REQUEST
53-
#-D ENABLE_DEBUG_SCHEDULER
52+
-D ENABLE_DEBUG_SCHEDULER
53+
# -D ENABLE_DEBUG_TIME
5454
#-D ENABLE_DEBUG_EVSE_MAN
55-
#-D ENABLE_DEBUG_EVSE_MONITOR
55+
-D ENABLE_DEBUG_EVSE_MONITOR
5656
#-D ENABLE_DEBUG_DIVERT
5757
#-D ENABLE_DEBUG_LED
5858
#-D ENABLE_DEBUG_LCD
@@ -91,6 +91,7 @@ build_flags =
9191
-D USE_ESP32
9292
-D USE_ESP32_FRAMEWORK_ARDUINO
9393
build_partitions = min_spiffs.csv
94+
build_partitions_debug = min_spiffs_debug.csv
9495

9596
neopixel_lib = adafruit/Adafruit [email protected]
9697

@@ -101,7 +102,7 @@ neopixel_lib = adafruit/Adafruit [email protected]
101102
#platform = https://github.com/platformio/platform-espressif32.git#feature/stage
102103
#platform = https://github.com/platformio/platform-espressif32.git#develop
103104
#platform = [email protected]
104-
platform = espressif32@4.4.0
105+
platform = espressif32@5.0.0
105106
#framework = arduino, espidf
106107
framework = arduino
107108
lib_deps = ${common.lib_deps}
@@ -117,7 +118,8 @@ board_build.partitions = ${common.build_partitions}
117118
# ; use a special branch
118119
# framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
119120
# platformio/framework-arduinoespressif32 @ ~3.10006.0
120-
monitor_filters = esp32_exception_decoder
121+
monitor_filters =
122+
esp32_exception_decoder
121123

122124
[env:openevse_nodemcu-32s]
123125
board = nodemcu-32s
@@ -154,6 +156,8 @@ build_flags =
154156
#upload_protocol = espota
155157
upload_speed = 2000000
156158
#upload_protocol = ftdi
159+
#debug_tool = ftdi
160+
#board_build.partitions = ${common.build_partitions_debug}
157161

158162
# export PLATFORMIO_UPLOAD_PORT=172.16.0.157
159163
# export PLATFORMIO_UPLOAD_FLAGS="-p 3232"
@@ -262,10 +266,17 @@ build_flags =
262266
-D RANDOM_SEED_CHANNEL=1
263267
-D RX2=16
264268
-D TX2=32
269+
-D PHY_PWR=5
265270
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"
266271
upload_speed = 921600
267-
monitor_flags =
268-
--filter=esp32_exception_decoder
272+
273+
[env:openevse_esp32-gateway-e_dev]
274+
extends = env:openevse_esp32-gateway-e
275+
build_flags =
276+
${env:openevse_esp32-gateway-e.build_flags}
277+
${common.debug_flags}
278+
build_type = debug
279+
board_build.partitions = ${common.build_partitions_debug}
269280

270281
[env:openevse_esp32-heltec-wifi-lora-v2]
271282
board = heltec_wifi_lora_32_V2

src/app_config.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ String rfid_storage;
8989

9090
long max_current_soft;
9191

92+
// Scheduler settings
93+
uint32_t scheduler_start_window;
94+
9295
String esp_hostname_default = "openevse-"+ESPAL.getShortId();
9396

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

168+
// Scheduler options
169+
new ConfigOptDefenition<uint32_t>(scheduler_start_window, SCHEDULER_DEFAULT_START_WINDOW, "scheduler_start_window", "ssw"),
170+
165171
// Flags
166172
&flagsOpt,
167173

@@ -236,6 +242,8 @@ void config_changed(String name)
236242
ArduinoOcppTask::notifyConfigChanged();
237243
} else if(name.startsWith("emoncms_")) {
238244
emoncms_updated = true;
245+
} else if(name.startsWith("scheduler_")) {
246+
scheduler.notifyConfigChanged();
239247
} else if(name == "divert_enabled" || name == "charge_mode") {
240248
DBUGVAR(config_divert_enabled());
241249
DBUGVAR(config_charge_mode());

src/app_config.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ extern double divert_attack_smoothing_factor;
6363
extern double divert_decay_smoothing_factor;
6464
extern uint32_t divert_min_charge_time;
6565

66+
// Scheduler settings
67+
extern uint32_t scheduler_start_window;
68+
6669
// 24-bits of Flags
6770
extern uint32_t flags;
6871

@@ -137,7 +140,7 @@ inline bool config_pause_uses_disabled() {
137140
inline bool config_vehicle_range_miles() {
138141
return CONFIG_VEHICLE_RANGE_MILES == (flags & CONFIG_VEHICLE_RANGE_MILES);
139142
}
140-
143+
141144
inline bool config_rfid_enabled() {
142145
return CONFIG_RFID == (flags & CONFIG_RFID);
143146
}

src/divert.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ void divert_update_state()
225225
event["available_current"] = available_current;
226226
event["smoothed_available_current"] = smoothed_available_current;
227227
event["pilot"] = evse.getChargeCurrent();
228+
event["min_charge_end"] = (divert_active && divertmode_get_time() < min_charge_end) ?
229+
min_charge_end - divertmode_get_time() :
230+
0;
228231
} // end ecomode
229232

230233
event_send(event);

src/emonesp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
#define LED_DEFAULT_BRIGHTNESS 128
148148
#endif
149149

150+
#ifndef SCHEDULER_DEFAULT_START_WINDOW
151+
#define SCHEDULER_DEFAULT_START_WINDOW 600
152+
#endif
153+
150154
#ifndef FORMAT_LITTLEFS_IF_FAILED
151155
#define FORMAT_LITTLEFS_IF_FAILED true
152156
#endif // !FORMAT_LITTLEFS_IF_FAILED

src/net_manager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,14 @@ net_setup()
419419

420420
#ifdef ENABLE_WIRED_ETHERNET
421421
//ETH.setHostname(esp_hostname.c_str());
422+
423+
#ifdef PHY_PWR
424+
pinMode(PHY_PWR, OUTPUT);
425+
digitalWrite(PHY_PWR, LOW);
426+
delay(1000);
427+
digitalWrite(PHY_PWR, HIGH);
428+
#endif
429+
422430
ETH.begin();
423431
#endif
424432

0 commit comments

Comments
 (0)