Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New settings / flags (#595) #618

Merged
merged 36 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6f36c27
add new config properties: divert_type, wizard_passed (-1 unset, 0 so…
KipK Apr 5, 2023
f7a89e6
use divert_type instead of checking mqtt fields
KipK Apr 26, 2023
1195f69
added vehicle_data_src config prop
KipK Apr 27, 2023
0e7651f
trailing space
KipK May 1, 2023
0e1520a
default openevse to disabled state at boot
KipK May 1, 2023
eeb7555
new default_state flag
KipK May 2, 2023
6d46c44
use new divert_type in divert_sim
KipK May 2, 2023
8265edc
trailing mqtt_solar condition in current_shaper
KipK May 3, 2023
040132b
start EnergyMeter sooner to prevent divert_sim crash
KipK May 6, 2023
d77f20d
set AP SSID & PASS
KipK May 7, 2023
bfb7557
edited api.yml config.yaml
KipK May 9, 2023
62f258f
use enum instead of #define
KipK May 9, 2023
3ef63d5
changed bootlock handling
KipK May 10, 2023
b4c0cd0
bump openevse lib version
KipK May 13, 2023
6266db6
added /restartevse endpoint + added payload to mqtt /restart => /rest…
KipK May 15, 2023
cfaab5a
put back unlock openevse to evseBoot
KipK May 15, 2023
cd0ae07
enum divert_type rename
KipK May 16, 2023
b6da9e7
changed http api & mqtt /restart {"device": "gateway|evse"}
KipK May 16, 2023
01fa11b
added doc
KipK May 16, 2023
c51a12b
update gui
KipK May 16, 2023
41e3967
fix bootlock unlock missed in some conditions
KipK May 18, 2023
ff0f69e
add missing evse_connected property in create_rapi_json ( connection …
KipK May 18, 2023
d3a9177
Adding write permission to PRs
jeremypoulter May 18, 2023
3cb80e3
Attempt 2 to fix permissions issue
jeremypoulter May 18, 2023
065e4eb
More permissions changes
jeremypoulter May 19, 2023
e1791c3
Trying all permissions
jeremypoulter May 19, 2023
01be5ba
Not apermission issue we can solve here :(
jeremypoulter May 19, 2023
5e66081
indent api.yml
KipK May 21, 2023
f63be11
Merge branch 'newflags' of https://github.com/KipK/ESP32_WiFi_V4.x in…
KipK May 21, 2023
0769da8
update static files
KipK May 21, 2023
566cd4e
fix mqtt doc #650
KipK May 21, 2023
31a1776
fix api.yml
KipK May 21, 2023
fa212aa
Revert "update static files"
KipK May 21, 2023
94cef5a
cleanup static files
KipK May 21, 2023
246c42c
Merge branch 'master' into newflags
KipK May 21, 2023
57b0c93
updated gui statics
KipK May 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ paths:
emoncms_fingerprint: ''
Configure Solar divert:
value:
divert_type: 0
divert_enabled: true
divert_attack_smoothing_factor: 0.4
divert_decay_smoothing_factor: 0.05
Expand Down Expand Up @@ -529,6 +530,28 @@ paths:
name: index
in: path
required: true
/restart:
post:
summary: restart gateway or evse modules
requestBody:
content:
application/json:
schema:
type: object
properties:
device:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device should be indented

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KipK still seeing several lint errors, no idea why the action is not reporting them, some weird permission issue because it is a PR from a fork...

but please take a look:

$ spectral lint api.yml 

/home/jpoulter/Dev/JeremyPoulter/ESP32_WiFi_V3.x/api.yml
 172:10  warning  operation-description  Operation "description" must be present and non-empty string.  paths./config.post
 235:10  warning  operation-description  Operation "description" must be present and non-empty string.  paths./override.post
  281:9  warning  operation-description  Operation "description" must be present and non-empty string.  paths./claims.get
  296:9  warning  operation-description  Operation "description" must be present and non-empty string.  paths./claims/{client}.get
  432:9  warning  operation-description  Operation "description" must be present and non-empty string.  paths./schedule/{id}.get
 444:10  warning  operation-description  Operation "description" must be present and non-empty string.  paths./schedule/{id}.post
 458:12  warning  operation-description  Operation "description" must be present and non-empty string.  paths./schedule/{id}.delete
 526:20  warning  operation-description  Operation "description" must be present and non-empty string.  paths./logs/{index}.get.description
 534:10  warning  operation-description  Operation "description" must be present and non-empty string.  paths./restart.post
 534:10  warning  operation-operationId  Operation must have "operationId".                             paths./restart.post
 534:10  warning  operation-tags         Operation must have non-empty "tags" array.                    paths./restart.post
 536:20    error  parser                 Bad indentation of a mapping entry
 536:21    error  parser                 Incomplete explicit mapping pair; a key node is missed
  546:9    error  parser                 Mapping key must be a string scalar rather than number         paths./restart.post.responses[200]
 546:13    error  oas3-schema            "200" property type must be object.                            paths./restart.post.responses[200]
 547:17    error  oas3-schema            Property "content" is not expected to be here.                 paths./restart.post.responses.content
 551:27    error  parser                 Bad indentation of a mapping entry
 551:28    error  parser                 Incomplete explicit mapping pair; a key node is missed

✖ 18 problems (7 errors, 11 warnings, 0 infos, 0 hints)

If you use VSCode there is an extension: https://marketplace.visualstudio.com/items?itemName=stoplight.spectral

type: string
description: gateway|evse
responses:
200:
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: restart gateway|evse
/limit:
get:
summary: Get charge limit
Expand Down
5 changes: 2 additions & 3 deletions divert_sim/divert_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ int main(int argc, char** argv)

kw = result.count("kw") > 0;

mqtt_solar = grid_ie_col >= 0 ? "" : "yes";
mqtt_grid_ie = grid_ie_col >= 0 ? "yes" : "";

divert_type = grid_ie_col >= 0 ? 1 : 0;

if(voltage_arg >= 0) {
if(voltage_arg < 50) {
voltage_col = voltage_arg;
Expand Down
4 changes: 2 additions & 2 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Limit:

Main settings:

`<base-topic>/divertmode/set [1 | 2]` : enable (1)/ disable (2) divert mode
`<base-topic>/divertmode/set [1 | 2]` : enable (1)/ disable (2) divert mode
`<base-topic>/shaper/set [0 | 1]` : temporary enable (1)/ disable (0) current shaper ( doesn't survive reboot )
`<base-topic>/restart` : restarts the gateway
`<base-topic>/restart {"device": "gateway|evse"}` : restart the gateway or openevse module



Expand Down
35 changes: 34 additions & 1 deletion models/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ x-examples:
- https
ssid: wibble_ext
pass: _DUMMY_PASSWORD
ap_ssid: openevse-2343
ap_pass: _DUMMY_PASSWORD
lang: en
www_username: ''
www_password: ''
Expand Down Expand Up @@ -58,17 +60,20 @@ x-examples:
ocpp_chargeBoxId: ''
ocpp_authkey: ''
ohm: ''
divert_type: -1
divert_PV_ratio: 1.1
divert_attack_smoothing_factor: 0.4
divert_decay_smoothing_factor: 0.05
divert_min_charge_time: 10
current_shaper_max_pwr: 9000
vehicle_data_src: 0
tesla_access_token: _DUMMY_PASSWORD
tesla_refresh_token: _DUMMY_PASSWORD
tesla_created_at: 2479357952
tesla_expires_in: 3888000
tesla_vehicle_id: '142960157278'
led_brightness: 51
scheduler_start_window: 60
flags: 115467
emoncms_enabled: true
mqtt_enabled: true
Expand All @@ -86,9 +91,12 @@ x-examples:
ocpp_auth_auto: true
ocpp_idtag: '0E000000'
ocpp_auth_offline: true
rfid_enabled: false
mqtt_protocol: mqtt
charge_mode: fast
is_threephase: false
wizard_passed: false
default_state: false
charge_mode: fast
x-tags:
- Config
properties:
Expand Down Expand Up @@ -167,6 +175,12 @@ properties:
pass:
type: string
minLength: 1
ap_ssid:
type: string
minLength: 1
ap_pass:
type: string
minLength: 1
www_username:
type: string
www_password:
Expand Down Expand Up @@ -242,8 +256,12 @@ properties:
type: string
ocpp_auth_offline:
type: boolean
rfid_enabled:
type: boolean
ohm:
type: string
divert_type:
type: number
divert_PV_ratio:
type: number
divert_attack_smoothing_factor:
Expand All @@ -252,6 +270,10 @@ properties:
type: number
divert_min_charge_time:
type: number
current_shaper_max_pwr:
type: number
vehicle_data_src:
type: number
tesla_access_token:
type: string
minLength: 1
Expand Down Expand Up @@ -306,3 +328,14 @@ properties:
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
description: |
Needs to be enabled if charging with 3 phases setup for proper calculations
wizard_passed:
type: boolean
description: |
define if wizard has been passed or not
default_state:
type: boolean
description: |
OpenEVSE default state when no claims are running ( 0: disabled | 1: active)

2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lib_deps =
jeremypoulter/[email protected]
jeremypoulter/Micro [email protected]
jeremypoulter/[email protected]
jeremypoulter/[email protected].13
jeremypoulter/[email protected].14
jeremypoulter/[email protected]
jeremypoulter/[email protected]
jeremypoulter/[email protected]
Expand Down
18 changes: 16 additions & 2 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
// Wifi Network Strings
String esid;
String epass;
String ap_ssid;
String ap_pass;

// Language
String lang;
Expand Down Expand Up @@ -87,6 +89,7 @@ uint32_t flags;
String ohm;

// Divert settings
int8_t divert_type;
double divert_PV_ratio;
double divert_attack_smoothing_factor;
double divert_decay_smoothing_factor;
Expand All @@ -103,6 +106,9 @@ uint64_t tesla_expires_in;

String tesla_vehicle_id;

// Vehicle
uint8_t vehicle_data_src;

#if RGB_LED
uint8_t led_brightness;
#endif
Expand All @@ -126,6 +132,8 @@ ConfigOpt *opts[] =
// Wifi Network Strings
new ConfigOptDefenition<String>(esid, "", "ssid", "ws"),
new ConfigOptSecret(epass, "", "pass", "wp"),
new ConfigOptDefenition<String>(ap_ssid, "", "ap_ssid", "as"),
new ConfigOptSecret(ap_pass, "", "ap_pass", "ap"),

// Language String
new ConfigOptDefenition<String>(lang, "", "lang", "lan"),
Expand Down Expand Up @@ -176,13 +184,17 @@ ConfigOpt *opts[] =
new ConfigOptDefenition<String>(ohm, "", "ohm", "o"),

// Divert settings
new ConfigOptDefenition<int8_t>(divert_type, -1, "divert_type", "dm"),
new ConfigOptDefenition<double>(divert_PV_ratio, 1.1, "divert_PV_ratio", "dpr"),
new ConfigOptDefenition<double>(divert_attack_smoothing_factor, 0.4, "divert_attack_smoothing_factor", "da"),
new ConfigOptDefenition<double>(divert_decay_smoothing_factor, 0.05, "divert_decay_smoothing_factor", "dd"),
new ConfigOptDefenition<uint32_t>(divert_min_charge_time, (10 * 60), "divert_min_charge_time", "dt"),

// Current Shaper settings
new ConfigOptDefenition<uint32_t>(current_shaper_max_pwr, 0 , "current_shaper_max_pwr", "smp"),
new ConfigOptDefenition<uint32_t>(current_shaper_max_pwr, 0, "current_shaper_max_pwr", "smp"),

// Vehicle settings
new ConfigOptDefenition<uint8_t>(vehicle_data_src, 0, "vehicle_data_src", "vds"),

// Tesla client settings
new ConfigOptSecret(tesla_access_token, "", "tesla_access_token", "tat"),
Expand Down Expand Up @@ -225,9 +237,11 @@ ConfigOpt *opts[] =
new ConfigOptVirtualBool(flagsOpt, CONFIG_RFID, CONFIG_RFID, "rfid_enabled", "rf"),
new ConfigOptVirtualBool(flagsOpt, CONFIG_FACTORY_WRITE_LOCK, CONFIG_FACTORY_WRITE_LOCK, "factory_write_lock", "fwl"),
new ConfigOptVirtualBool(flagsOpt, CONFIG_THREEPHASE, CONFIG_THREEPHASE, "is_threephase", "itp"),
new ConfigOptVirtualBool(flagsOpt, CONFIG_WIZARD, CONFIG_WIZARD, "wizard_passed", "wzp"),
new ConfigOptVirtualBool(flagsOpt, CONFIG_DEFAULT_STATE, CONFIG_DEFAULT_STATE, "default_state", "dfs"),
new ConfigOptVirtualMqttProtocol(flagsOpt, "mqtt_protocol", "mprt"),
new ConfigOptVirtualChargeMode(flagsOpt, "charge_mode", "chmd")
};
};

ConfigJson user_config(opts, sizeof(opts) / sizeof(opts[0]), EEPROM_SIZE, CONFIG_OFFSET);
ConfigJson factory_config(opts, sizeof(opts) / sizeof(opts[0]), EEPROM_SIZE, FACTORY_OFFSET);
Expand Down
32 changes: 26 additions & 6 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Arduino.h>
#include <ArduinoJson.h>
#include "evse_state.h"

#ifndef ENABLE_CONFIG_V1_IMPORT
#define ENABLE_CONFIG_V1_IMPORT 1
Expand All @@ -23,7 +24,8 @@
// Wifi Network Strings
extern String esid;
extern String epass;

extern String ap_ssid;
extern String ap_pass;
// Language
extern String lang;

Expand Down Expand Up @@ -74,6 +76,7 @@ extern String rfid_storage;
extern String time_zone;

// Divert settings
extern int8_t divert_type;
extern double divert_PV_ratio;
extern double divert_attack_smoothing_factor;
extern double divert_decay_smoothing_factor;
Expand All @@ -85,6 +88,16 @@ extern uint32_t scheduler_start_window;
//Shaper settings
extern uint32_t current_shaper_max_pwr;

// Vehicle
extern uint8_t vehicle_data_src;

enum vehicle_data_src {
VEHICLE_DATA_SRC_NONE,
VEHICLE_DATA_SRC_TESLA,
VEHICLE_DATA_SRC_MQTT,
VEHICLE_DATA_SRC_HTTP
};

// 24-bits of Flags
extern uint32_t flags;

Expand All @@ -109,7 +122,8 @@ extern uint32_t flags;
#define CONFIG_OCPP_AUTO_AUTH (1 << 22)
#define CONFIG_OCPP_OFFLINE_AUTH (1 << 23)
#define CONFIG_THREEPHASE (1 << 24)

#define CONFIG_WIZARD (1 << 25)
#define CONFIG_DEFAULT_STATE (1 << 26)

inline bool config_emoncms_enabled() {
return CONFIG_SERVICE_EMONCMS == (flags & CONFIG_SERVICE_EMONCMS);
Expand Down Expand Up @@ -159,10 +173,6 @@ inline bool config_ocpp_offline_authorization() {
return CONFIG_OCPP_OFFLINE_AUTH == (flags & CONFIG_OCPP_OFFLINE_AUTH);
}

inline bool config_tesla_enabled() {
return CONFIG_SERVICE_TESLA == (flags & CONFIG_SERVICE_TESLA);
}

inline bool config_divert_enabled() {
return CONFIG_SERVICE_DIVERT == (flags & CONFIG_SERVICE_DIVERT);
}
Expand Down Expand Up @@ -195,6 +205,16 @@ inline bool config_threephase_enabled() {
return CONFIG_THREEPHASE == (flags & CONFIG_THREEPHASE);
}

inline bool config_wizard_passed()
{
return CONFIG_WIZARD == (flags & CONFIG_WIZARD);
}

inline EvseState config_default_state()
{
return CONFIG_DEFAULT_STATE == (flags & CONFIG_DEFAULT_STATE) ? EvseState::Active : EvseState::Disabled;
}

// Ohm Connect Settings
extern String ohm;

Expand Down
20 changes: 10 additions & 10 deletions src/current_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
_evse->release(EvseClient_OpenEVSE_Shaper);
}
}


return EVSE_SHAPER_LOOP_TIME;
}

void CurrentShaperTask::begin(EvseManager &evse) {
this -> _timer = millis();
this -> _enabled = config_current_shaper_enabled();
this -> _evse = &evse;
this -> _max_pwr = current_shaper_max_pwr;
this -> _max_pwr = current_shaper_max_pwr;
this -> _live_pwr = 0;
this -> _max_cur = 0;
this -> _updated = false;
this -> _updated = false;
MicroTask.startTask(this);
StaticJsonDocument<128> event;
event["shaper"] = 1;
Expand Down Expand Up @@ -102,7 +102,7 @@ void CurrentShaperTask::setLivePwr(int live_pwr) {
shapeCurrent();
}

// temporary change Current Shaper state without changing configuration
// temporary change Current Shaper state without changing configuration
void CurrentShaperTask::setState(bool state) {
_enabled = state;
if (!_enabled) {
Expand All @@ -119,21 +119,21 @@ void CurrentShaperTask::shapeCurrent() {
// adding self produced energy to total
int max_pwr = _max_pwr;
if (config_divert_enabled() == true) {
if (mqtt_solar != "") {
if ( divert_type == DIVERT_TYPE_SOLAR ) {
max_pwr += solar;
}
}
}
if(!config_threephase_enabled()) {
_max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps()));
}

else {
_max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage() / 3) + (evse.getAmps()));
}



_changed = true;

_changed = true;
}

int CurrentShaperTask::getMaxPwr() {
Expand Down
Loading