Skip to content

Commit

Permalink
Merge pull request #618 from KipK/newflags
Browse files Browse the repository at this point in the history
New settings / flags (#595)
  • Loading branch information
jeremypoulter authored May 21, 2023
2 parents 8ce9db4 + 57b0c93 commit beb2a21
Show file tree
Hide file tree
Showing 37 changed files with 10,132 additions and 9,800 deletions.
29 changes: 29 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_time: 8
divert_decay_smoothing_time: 300
Expand Down Expand Up @@ -529,6 +530,33 @@ paths:
name: index
in: path
required: true
/restart:
post:
summary: restart gateway or evse modules
description: restart wifi gateway or openevse module
operationId: restart
tags:
- Restart
requestBody:
content:
application/json:
schema:
type: object
properties:
device:
type: string
description: gateway|evse
responses:
'200':
description: Restart successfull
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: restart gateway|evse
/limit:
get:
summary: Get charge limit
Expand Down Expand Up @@ -930,3 +958,4 @@ tags:
- name: Limit
- name: Energy Meter
- name: Time
- name: Restart
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
10 changes: 5 additions & 5 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Claim & override properties can be set independantly. Sending json with only som
To remove a selected claim/override property, just send "clear" as property parameter ( i.e. `<base-topic>/claim/set {"charge_current": "clear"}` )

Scheduler data:
`<base-topic>/scheduler/` : get scheduler data ([json data]
`<base-topic>/scheduler/set <json data>` : set/update schedules ( data as refered from API: https://openevse.stoplight.io/docs/openevse-wifi-v4/e87e6f3f90787-batch-update-schedule )
`<base-topic>/scheduler/clear <id> :`remove related event
`<base-topic>/schedule/` : get scheduler data ([json data]
`<base-topic>/schedule/set <json data>` : set/update schedules ( data as refered from API: https://openevse.stoplight.io/docs/openevse-wifi-v4/e87e6f3f90787-batch-update-schedule )
`<base-topic>/schedule/clear <id> :`remove related event

Limit:
`<base-topic>/limit/` : get limit data ([json data]
Expand All @@ -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,6 +60,7 @@ x-examples:
ocpp_chargeBoxId: ''
ocpp_authkey: ''
ohm: ''
divert_type: -1
divert_PV_ratio: 1.1
divert_attack_smoothing_time: 20
divert_decay_smoothing_time: 200
Expand All @@ -66,12 +69,14 @@ x-examples:
current_shaper_min_pause_time: 300
current_shaper_data_maxinterval: 120
current_shaper_smoothing_time: 60
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 @@ -89,9 +94,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 @@ -170,6 +178,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 @@ -245,8 +259,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_time:
Expand All @@ -255,6 +273,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 @@ -309,3 +331,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/ArduinoMongoose@0.0.18
jeremypoulter/Micro Debug@0.0.5
jeremypoulter/ConfigJson@0.0.5
jeremypoulter/OpenEVSE@0.0.13
jeremypoulter/OpenEVSE@0.0.14
jeremypoulter/ESPAL@0.0.3
jeremypoulter/StreamSpy@0.0.1
jeremypoulter/MicroTasks@0.0.3
Expand Down
14 changes: 14 additions & 0 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;
uint32_t divert_attack_smoothing_time;
uint32_t divert_decay_smoothing_time;
Expand All @@ -106,6 +109,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 @@ -129,6 +135,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 @@ -179,6 +187,7 @@ 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<uint32_t>(divert_attack_smoothing_time, 20, "divert_attack_smoothing_time", "das"),
new ConfigOptDefenition<uint32_t>(divert_decay_smoothing_time, 600, "divert_decay_smoothing_time", "dds"),
Expand All @@ -190,6 +199,9 @@ ConfigOpt *opts[] =
new ConfigOptDefenition<uint32_t>(current_shaper_min_pause_time, 300, "current_shaper_min_pause_time", "spt"),
new ConfigOptDefenition<uint32_t>(current_shaper_data_maxinterval, 120, "current_shaper_data_maxinterval", "sdm"),

// 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"),
new ConfigOptSecret(tesla_refresh_token, "", "tesla_refresh_token", "trt"),
Expand Down Expand Up @@ -231,6 +243,8 @@ 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")};

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 uint32_t divert_attack_smoothing_time;
extern uint32_t divert_decay_smoothing_time;
Expand All @@ -88,6 +91,16 @@ extern uint32_t current_shaper_smoothing_time;
extern uint32_t current_shaper_min_pause_time;
extern uint32_t current_shaper_data_maxinterval;

// 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 @@ -112,7 +125,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 @@ -162,10 +176,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 @@ -198,6 +208,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
7 changes: 4 additions & 3 deletions src/current_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ unsigned long CurrentShaperTask::loop(MicroTasks::WakeReason reason) {
}
}


return EVSE_SHAPER_LOOP_TIME;
}

Expand Down Expand Up @@ -137,7 +136,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 Down Expand Up @@ -171,7 +170,7 @@ void CurrentShaperTask::shapeCurrent() {
}

if (config_divert_enabled() == true) {
if (mqtt_solar != "") {
if ( divert_type == DIVERT_TYPE_SOLAR ) {
max_pwr += solar;
}
}
Expand All @@ -186,6 +185,8 @@ void CurrentShaperTask::shapeCurrent() {
_max_cur = ((max_pwr - livepwr) / evse.getVoltage() / 3.0) + evse.getAmps();
}



_changed = true;
}

Expand Down
Loading

0 comments on commit beb2a21

Please sign in to comment.