Skip to content

Commit ea86b10

Browse files
committed
Merge branch 'master' of github.com:OpenEVSE/ESP32_WiFi_V3.x into jeremypoulter/issue147
2 parents 9e3cbbf + 796e142 commit ea86b10

File tree

8 files changed

+89
-27
lines changed

8 files changed

+89
-27
lines changed

docs/wired-ethernet.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Network connection can be made with a standard Ethernet cable. For new installat
1313

1414
## Hardware Connections
1515

16+
See [photos ](https://photos.google.com/share/AF1QipNvANgeR_NRmLrq0lhKnA0BR7ieD8DGRoaJFoilMIwQ8c7QpxR4X7hSfGj3XiTTUw) of hardware connectors for new OpenEVSE V5.5 controller.
17+
1618
*Note: The these hardware connections apply to the current Rev.E & Rev.F ESP32-gateway hardware revisions. See section below for older units.*
1719

1820

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ build_flags =
7575
-DMG_ENABLE_SNTP=1
7676
-DCS_PLATFORM=CS_P_ESP32
7777
-DAO_CUSTOM_WS ; ArduinoOcpp: don't use built-in WS library
78+
-DRAPI_MAX_COMMANDS=20
7879
build_partitions = min_spiffs.csv
7980
monitor_flags = --filter=esp32_exception_decoder
8081

src/divert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void divertmode_update(byte newmode)
9292
event["smoothed_available_current"] = smoothed_available_current = 0;
9393

9494
EvseProperties props(EvseState::Disabled);
95-
evse.claim(EvseClient_OpenEVSE_Divert, EvseManager_Priority_Divert, props);
95+
evse.claim(EvseClient_OpenEVSE_Divert, EvseManager_Priority_Default, props);
9696
} break;
9797

9898
default:
@@ -208,7 +208,7 @@ void divert_update_state()
208208
if(divert_active && divertmode_get_time() >= min_charge_end)
209209
{
210210
EvseProperties props(EvseState::Disabled);
211-
evse.claim(EvseClient_OpenEVSE_Divert, EvseManager_Priority_Divert, props);
211+
evse.claim(EvseClient_OpenEVSE_Divert, EvseManager_Priority_Default, props);
212212

213213
if(previousState != evse.getState())
214214
{

src/evse_man.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,19 @@ EvseManager::Claim::Claim() :
109109
{
110110
}
111111

112-
void EvseManager::Claim::claim(EvseClient client, int priority, EvseProperties &target)
112+
bool EvseManager::Claim::claim(EvseClient client, int priority, EvseProperties &target)
113113
{
114-
_client = client;
115-
_priority = priority;
116-
_properties = target;
114+
if(_client != client ||
115+
_priority != priority ||
116+
_properties != target)
117+
{
118+
_client = client;
119+
_priority = priority;
120+
_properties = target;
121+
return true;
122+
}
123+
124+
return false;
117125
}
118126

119127
void EvseManager::Claim::release()
@@ -385,7 +393,7 @@ bool EvseManager::claim(EvseClient client, int priority, EvseProperties &target)
385393
{
386394
Claim *slot = NULL;
387395

388-
DBUGF("New claim from 0x%08x, priority %d, %s", client, priority, target.getState().toString());
396+
DBUGF("Claim from 0x%08x, priority %d, %s", client, priority, target.getState().toString());
389397

390398
for (size_t i = 0; i < EVSE_MANAGER_MAX_CLIENT_CLAIMS; i++)
391399
{
@@ -400,10 +408,13 @@ bool EvseManager::claim(EvseClient client, int priority, EvseProperties &target)
400408

401409
if(slot)
402410
{
403-
DBUGF("Found slot, waking task");
404-
slot->claim(client, priority, target);
405-
_evaluateClaims = true;
406-
MicroTask.wakeTask(this);
411+
DBUGF("Found slot");
412+
if(slot->claim(client, priority, target))
413+
{
414+
DBUGF("Claim added/updated, waking task");
415+
_evaluateClaims = true;
416+
MicroTask.wakeTask(this);
417+
}
407418
return true;
408419
}
409420

@@ -525,6 +536,10 @@ uint32_t EvseManager::getTimeLimit(EvseClient client)
525536
return getClaimProperties(client).getTimeLimit();
526537
}
527538

539+
bool EvseManager::isRapiCommandBlocked(String rapi)
540+
{
541+
return rapi.startsWith("$ST");
542+
}
528543

529544
bool EvseManager::serializeClaims(DynamicJsonDocument &doc)
530545
{

src/evse_man.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ class EvseProperties : virtual public JsonSerialize<512>
164164
return *this;
165165
}
166166

167+
bool equals(EvseProperties &rhs) {
168+
return this->_state == rhs._state &&
169+
this->_charge_current == rhs._charge_current &&
170+
this->_max_current == rhs._max_current &&
171+
this->_energy_limit == rhs._energy_limit &&
172+
this->_time_limit == rhs._time_limit &&
173+
this->_auto_release == rhs._auto_release;
174+
175+
}
176+
bool equals(EvseState &rhs) {
177+
return this->_state == rhs;
178+
}
179+
180+
bool operator == (EvseProperties &rhs) {
181+
return this->equals(rhs);
182+
}
183+
bool operator == (EvseState &rhs) {
184+
return this->equals(rhs);
185+
}
186+
187+
bool operator != (EvseProperties &rhs) {
188+
return !equals(rhs);
189+
}
190+
bool operator != (EvseState &rhs) {
191+
return !equals(rhs);
192+
}
193+
194+
167195
using JsonSerialize::deserialize;
168196
virtual bool deserialize(JsonObject &obj);
169197
using JsonSerialize::serialize;
@@ -183,7 +211,7 @@ class EvseManager : public MicroTasks::Task
183211
public:
184212
Claim();
185213

186-
void claim(EvseClient client, int priority, EvseProperties &target);
214+
bool claim(EvseClient client, int priority, EvseProperties &target);
187215
void release();
188216

189217
bool isValid() {
@@ -402,6 +430,8 @@ class EvseManager : public MicroTasks::Task
402430
void onSessionComplete(MicroTasks::EventListener *listner) {
403431
_monitor.onSessionComplete(listner);
404432
}
433+
434+
bool isRapiCommandBlocked(String rapi);
405435
};
406436

407437
#endif // !_OPENEVSE_EVSE_MAN_H

src/mqtt.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
9595
cmd += " "+payload_str;
9696
}
9797

98-
rapiSender.sendCmd(cmd, [](int ret)
98+
if(!evse.isRapiCommandBlocked(cmd))
9999
{
100-
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
100+
rapiSender.sendCmd(cmd, [](int ret)
101101
{
102-
String rapiString = rapiSender.getResponse();
103-
String mqtt_data = rapiString;
104-
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
105-
mqttclient.publish(mqtt_sub_topic, mqtt_data);
106-
}
107-
});
102+
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
103+
{
104+
String rapiString = rapiSender.getResponse();
105+
String mqtt_data = rapiString;
106+
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
107+
mqttclient.publish(mqtt_sub_topic, mqtt_data);
108+
}
109+
});
110+
}
108111
}
109112
}
110113
} //end call back

src/scheduler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ unsigned long Scheduler::loop(MicroTasks::WakeReason reason)
204204
DBUGF("Starting %s claim",
205205
currentEvent.getState().toString());
206206
EvseProperties properties(currentEvent.getState());
207-
_evse->claim(EvseClient_OpenEVSE_Schedule, EvseManager_Priority_Timer, properties);
207+
_evse->claim(EvseClient_OpenEVSE_Schedule,
208+
EvseState::Active == currentEvent.getState() ? EvseManager_Priority_Timer : EvseManager_Priority_Default,
209+
properties);
208210
} else {
209211
// No scheduled events, release any claims
210212
DBUGLN("releasing claims");

src/web_server.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const char _CONTENT_TYPE_JPEG[] PROGMEM = "image/jpeg";
5858
const char _CONTENT_TYPE_PNG[] PROGMEM = "image/png";
5959
const char _CONTENT_TYPE_SVG[] PROGMEM = "image/svg+xml";
6060

61+
#define RAPI_RESPONSE_BLOCKED -300
62+
6163
void handleEvseClaims(MongooseHttpServerRequest *request);
6264

6365
void dumpRequest(MongooseHttpServerRequest *request)
@@ -1101,12 +1103,18 @@ handleRapi(MongooseHttpServerRequest *request) {
11011103
if (request->hasParam("rapi"))
11021104
{
11031105
String rapi = request->getParam("rapi");
1106+
int ret = RAPI_RESPONSE_NK;
11041107

1105-
// BUG: Really we should do this in the main loop not here...
1106-
RAPI_PORT.flush();
1107-
DBUGVAR(rapi);
1108-
int ret = rapiSender.sendCmdSync(rapi);
1109-
DBUGVAR(ret);
1108+
if(!evse.isRapiCommandBlocked(rapi))
1109+
{
1110+
// BUG: Really we should do this in the main loop not here...
1111+
RAPI_PORT.flush();
1112+
DBUGVAR(rapi);
1113+
ret = rapiSender.sendCmdSync(rapi);
1114+
DBUGVAR(ret);
1115+
} else {
1116+
ret = RAPI_RESPONSE_BLOCKED;
1117+
}
11101118

11111119
if(RAPI_RESPONSE_OK == ret ||
11121120
RAPI_RESPONSE_NK == ret)
@@ -1162,6 +1170,7 @@ handleRapi(MongooseHttpServerRequest *request) {
11621170
RAPI_RESPONSE_BAD_CHECKSUM == ret ? F("RAPI_RESPONSE_BAD_CHECKSUM") :
11631171
RAPI_RESPONSE_BAD_SEQUENCE_ID == ret ? F("RAPI_RESPONSE_BAD_SEQUENCE_ID") :
11641172
RAPI_RESPONSE_ASYNC_EVENT == ret ? F("RAPI_RESPONSE_ASYNC_EVENT") :
1173+
RAPI_RESPONSE_BLOCKED == ret ? F("RAPI_RESPONSE_BLOCKED") :
11651174
F("UNKNOWN");
11661175

11671176
if (json) {
@@ -1172,7 +1181,7 @@ handleRapi(MongooseHttpServerRequest *request) {
11721181
s += errorString;
11731182
}
11741183

1175-
code = 500;
1184+
code = RAPI_RESPONSE_BLOCKED == ret ? 400 : 500;
11761185
}
11771186
}
11781187
if (false == json) {

0 commit comments

Comments
 (0)