Skip to content

Commit

Permalink
Merge pull request #535 from KipK/limits
Browse files Browse the repository at this point in the history
New Limit engine for Wifi module.
  • Loading branch information
jeremypoulter committed Feb 6, 2023
2 parents 751d837 + f8a265d commit 7c2a177
Show file tree
Hide file tree
Showing 15 changed files with 643 additions and 117 deletions.
96 changes: 94 additions & 2 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ paths:
state: active
charge_current: 0
max_current: 0
energy_limit: 0
time_limit: 0
auto_release: true
responses:
'200':
Expand Down Expand Up @@ -526,6 +524,100 @@ paths:
name: index
in: path
required: true
/limit:
get:
summary: Get charge limit
description: This will return the limit type, value and auto_release (true|false) defined if there's one
responses:
'200':
description: Limit properties
content:
application/json:
schema:
$ref: ./models/Limit.yaml
'404':
description: No limit
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: No limit
operationId: limit_get
tags:
- Limit
post:
summary: Set charge limit
description: This will set the limit type, value and auto_release (true|false)
responses:
'200':
description: Limit set
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: created
'500':
description: Failed to parse data
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: Failed to parse JSON
requestBody:
content:
application/json:
schema:
$ref: ./models/Limit.yaml
operationId: limit_set
tags:
- Limit
delete:
summary: Get charge limit
description: This will clear current limit
responses:
'200':
description: Clear Limit ok
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: Deleted
'404':
description: No limit
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: No limit to clear
'500':
description: Failed to clear limit
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: Failed to clear limit
operationId: limit_clear
tags:
- Limit

/tesla/vehicles:
get:
summary: Get Tesla vehicle list
Expand Down
11 changes: 11 additions & 0 deletions models/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ x-examples:
hostname: openevse-a7d4
sntp_hostname: pool.ntp.org
time_zone: 'Europe/London|GMT0BST,M3.5.0/1,M10.5.0'
limit_default_type: none
limit_default_value": 0
emoncms_server: 'https://emoncms.org'
emoncms_node: openevse-a7d4
emoncms_apikey: _DUMMY_PASSWORD
Expand Down Expand Up @@ -86,6 +88,7 @@ x-examples:
ocpp_auth_offline: true
mqtt_protocol: mqtt
charge_mode: fast
is_threephase: false
x-tags:
- Config
properties:
Expand Down Expand Up @@ -177,6 +180,12 @@ properties:
time_zone:
type: string
minLength: 1
limit_default_type:
type: string
minLength: 1
limit_default_value:
type: integer
minLength: 1
emoncms_server:
type: string
minLength: 1
Expand Down Expand Up @@ -295,3 +304,5 @@ properties:
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.
is_threephase:
type: boolean
15 changes: 15 additions & 0 deletions models/Limit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: EVSE limit
allOf:
- type: object
properties:
type:
type: string
description: 'Limit type: time (minutes), energy (watts/h), soc (%), range (km or miles)'
value:
type: integer
description: 'The limit value'
auto_release:
type: bool
description: 'Release current limit when car is disconnected. (default: true)'
x-tags:
- Limit
16 changes: 0 additions & 16 deletions models/Properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ properties:
type: integer
minimum: 0
description: Dynamically alter the max current while still allowing other claims to very the current via `charge_current` that can not exceede this value. This is primerialy designed for load sharing situations while still allowing things like PV divert to work so the charge current is the minimum of `charge_current` <= `max_current` <= configured soft limit <= hard coded limit
energy_limit:
type: integer
minimum: 0
format: int32
description: |-
Stop the charge after `energy_limit` Wh of energy have been transfered.
> Note: Not currently implemented
time_limit:
type: integer
minimum: 0
format: int32
description: |-
Stop the charge after the duration of the charging session has exceeded `time_limit` seconds
> Note: Not currently implemented
auto_release:
type: boolean
description: |
Expand Down
6 changes: 6 additions & 0 deletions models/Status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ properties:
offset:
type: string
description: The current timezone
has_limit:
type: boolean
description: A limit has been set
limit_version:
type: integer
description: /limit endpoint current version
1 change: 1 addition & 0 deletions openevse-gui-v2
Submodule openevse-gui-v2 added at 3f2c8a
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ debug_flags =
#-D ENABLE_DEBUG_MQTT
#-D ENABLE_DEBUG_EMONCMS
#-D ENABLE_DEBUG_TESLA_CLIENT
#-D ENABLE_DEBUG_LIMIT
#-D ENABLE_PROFILE
src_build_flags =
# -D ARDUINOJSON_USE_LONG_LONG
Expand Down
24 changes: 24 additions & 0 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "input.h"
#include "LedManagerTask.h"
#include "current_shaper.h"
#include "limit.h"

#include "app_config.h"
#include "app_config_mqtt.h"
Expand Down Expand Up @@ -41,6 +42,10 @@ String www_password;
String esp_hostname;
String sntp_hostname;

// LIMIT Settings
String limit_default_type;
uint32_t limit_default_value;

// EMONCMS SERVER strings
String emoncms_server;
String emoncms_node;
Expand Down Expand Up @@ -132,6 +137,10 @@ ConfigOpt *opts[] =
// Time
new ConfigOptDefenition<String>(time_zone, "", "time_zone", "tz"),

// Limit
new ConfigOptDefenition<String>(limit_default_type, {}, "limit_default_type", "ldt"),
new ConfigOptDefenition<uint32_t>(limit_default_value, {}, "limit_default_value", "ldv"),

// EMONCMS SERVER strings
new ConfigOptDefenition<String>(emoncms_server, "https://data.openevse.com/emoncms", "emoncms_server", "es"),
new ConfigOptDefenition<String>(emoncms_node, esp_hostname, "emoncms_node", "en"),
Expand Down Expand Up @@ -287,6 +296,21 @@ void config_changed(String name)
} else if(name == "led_brightness") {
ledManager.setBrightness(led_brightness);
#endif
} else if(name.startsWith("limit_default_")) {
LimitProperties limitprops;
LimitType limitType;
limitType.fromString(limit_default_type.c_str());
limitprops.setType(limitType);
limitprops.setValue(limit_default_value);
limitprops.setAutoRelease(false);
if (limitType == LimitType::None) {
uint32_t val = 0;
config_set("limit_default_value", val);
config_commit();
limit.clear();
}
else
limit.set(limitprops);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extern String esp_hostname;
extern String esp_hostname_default;
extern String sntp_hostname;

// LIMIT Settings
extern String limit_default_type;
extern uint32_t limit_default_value;

// EMONCMS SERVER strings
extern String emoncms_server;
extern String emoncms_node;
Expand Down
Loading

0 comments on commit 7c2a177

Please sign in to comment.