Skip to content

Commit 923bba4

Browse files
Merge pull request #325 from matth-x/master
Add RFID support and upgrade OCPP library
2 parents 9732b0b + 8da38a4 commit 923bba4

23 files changed

+1062
-216
lines changed

platformio.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ default_envs = openevse_wifi_v1
3232
version = -D BUILD_TAG=4.1.3
3333
monitor_speed = 115200
3434
lib_deps =
35-
bblanchon/ArduinoJson@6.15.1
36-
jeremypoulter/[email protected].17
35+
bblanchon/ArduinoJson@6.19.1
36+
jeremypoulter/[email protected].18
3737
jeremypoulter/Micro [email protected]
3838
jeremypoulter/[email protected]
3939
jeremypoulter/[email protected]
@@ -42,7 +42,7 @@ lib_deps =
4242
jeremypoulter/[email protected]
4343
erropix/ESP32 [email protected]
4444
45-
matth-x/ArduinoOcpp@0.0.4
45+
matth-x/ArduinoOcpp@0.1.0
4646
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
4747
extra_scripts = scripts/extra_script.py
4848
debug_flags =
@@ -79,7 +79,8 @@ build_flags =
7979
-D MG_ENABLE_SNTP=1
8080
-D CS_PLATFORM=CS_P_ESP32
8181
-D AO_CUSTOM_WS ; ArduinoOcpp: don't use built-in WS library
82-
-D AO_CUSTOM_DIAGNOSTICS ; ArduinoOcpp: don't do internal logging
82+
-D AO_CUSTOM_CONSOLE ; ArduinoOcpp: use custom debug out
83+
-D AO_DBG_LEVEL=AO_DL_WARN
8384
#-D ENABLE_DEBUG
8485
#-D ENABLE_DEBUG_MONGOOSE_HTTP_CLIENT
8586
-D RAPI_MAX_COMMANDS=20
@@ -246,6 +247,7 @@ src_build_flags =
246247
-D I2C_SDA=21
247248
-D I2C_SCL=22
248249
-D ENABLE_MCP9808
250+
-D ENABLE_PN532
249251
build_flags =
250252
${common.build_flags}
251253
-D TX1=16

src/MongooseOcppSocketClient.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
* Created: 2021-04-10
44
*/
55

6+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_OCPPSOCKET)
7+
#undef ENABLE_DEBUG
8+
#endif
9+
610
#include "MongooseOcppSocketClient.h"
711
#include "net_manager.h"
812
#include "debug.h"
@@ -203,7 +207,7 @@ void MongooseOcppSocketClient::reconnect(const String &ws_url) {
203207
maintainWsConn();
204208
}
205209

206-
bool MongooseOcppSocketClient::sendTXT(String &out) {
210+
bool MongooseOcppSocketClient::sendTXT(std::string &out) {
207211
/*
208212
* Check if the EVSE is able to send the data at the moment. This fuzzy check can be useful to
209213
* to diagnose connection problems at upper layers. It gives no guarantee that packages will
@@ -243,7 +247,7 @@ bool MongooseOcppSocketClient::isValidUrl(const char *url) {
243247
if (url[1] != 'S' && url[1] != 's')
244248
return false;
245249

246-
if (url[2] == 'S' && url[2] == 's') {
250+
if (url[2] == 'S' || url[2] == 's') {
247251
if (url[3] != ':')
248252
return false;
249253
//else: passed

src/MongooseOcppSocketClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class MongooseOcppSocketClient : public ArduinoOcpp::OcppSocket {
3232

3333
MongooseOcppSocketClient(const String &ws_url);
3434

35-
~MongooseOcppSocketClient();
35+
~MongooseOcppSocketClient() override;
3636

37-
void loop();
37+
void loop() override;
3838

3939
void maintainWsConn();
4040

41-
bool sendTXT(String &out);
41+
bool sendTXT(std::string &out) override;
4242

4343
bool receiveTXT(const char* msg, size_t len);
4444

45-
void setReceiveTXTcallback(ArduinoOcpp::ReceiveTXTcallback &receiveTXT) {
45+
void setReceiveTXTcallback(ArduinoOcpp::ReceiveTXTcallback &receiveTXT) override {
4646
this->receiveTXTcallback = receiveTXT;
4747
}; //ReceiveTXTcallback is defined in OcppServer.h
4848

src/app_config.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ String tesla_vehicle_id;
8484
uint8_t led_brightness;
8585
#endif
8686

87+
// RFID storage
88+
String rfid_storage;
89+
90+
long max_current_soft;
91+
8792
String esp_hostname_default = "openevse-"+ESPAL.getShortId();
8893

8994
void config_changed(String name);
@@ -149,6 +154,9 @@ ConfigOpt *opts[] =
149154
new ConfigOptDefenition<uint64_t>(tesla_expires_in, -1, "tesla_expires_in", "tx"),
150155
new ConfigOptDefenition<String>(tesla_vehicle_id, "", "tesla_vehicle_id", "ti"),
151156

157+
// RFID storage
158+
new ConfigOptDefenition<String>(rfid_storage, "", "rfid_storage", "rs"),
159+
152160
#if RGB_LED
153161
// LED brightness
154162
new ConfigOptDefenition<uint8_t>(led_brightness, LED_DEFAULT_BRIGHTNESS, "led_brightness", "lb"),
@@ -170,6 +178,7 @@ ConfigOpt *opts[] =
170178
new ConfigOptVirtualBool(flagsOpt, CONFIG_SERVICE_OCPP, CONFIG_SERVICE_OCPP, "ocpp_enabled", "ope"),
171179
new ConfigOptVirtualBool(flagsOpt, CONFIG_OCPP_ACCESS_SUSPEND, CONFIG_OCPP_ACCESS_SUSPEND, "ocpp_suspend_evse", "ops"),
172180
new ConfigOptVirtualBool(flagsOpt, CONFIG_OCPP_ACCESS_ENERGIZE, CONFIG_OCPP_ACCESS_ENERGIZE, "ocpp_energize_plug", "opn"),
181+
new ConfigOptVirtualBool(flagsOpt, CONFIG_RFID, CONFIG_RFID, "rfid_enabled", "rf"),
173182
new ConfigOptVirtualMqttProtocol(flagsOpt, "mqtt_protocol", "mprt"),
174183
new ConfigOptVirtualChargeMode(flagsOpt, "charge_mode", "chmd")
175184
};
@@ -384,6 +393,17 @@ config_save_ohm(bool enable, String qohm)
384393
config.commit();
385394
}
386395

396+
void
397+
config_save_rfid(bool enable, String storage){
398+
uint32_t newflags = flags & ~CONFIG_RFID;
399+
if(enable) {
400+
newflags |= CONFIG_RFID;
401+
}
402+
config.set("flags", newflags);
403+
config.set("rfid_storage", rfid_storage);
404+
config.commit();
405+
}
406+
387407
void
388408
config_save_flags(uint32_t newFlags) {
389409
config.set("flags", newFlags);

src/app_config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ extern String ocpp_chargeBoxId;
5151
extern String ocpp_idTag;
5252
extern String tx_start_point;
5353

54+
// RFID storage
55+
extern String rfid_storage;
56+
5457
// Time
5558
extern String time_zone;
5659

@@ -77,6 +80,7 @@ extern uint32_t flags;
7780
#define CONFIG_OCPP_ACCESS_SUSPEND (1 << 15)
7881
#define CONFIG_OCPP_ACCESS_ENERGIZE (1 << 16)
7982
#define CONFIG_VEHICLE_RANGE_MILES (1 << 17)
83+
#define CONFIG_RFID (1 << 18)
8084

8185
inline bool config_emoncms_enabled() {
8286
return CONFIG_SERVICE_EMONCMS == (flags & CONFIG_SERVICE_EMONCMS);
@@ -133,6 +137,10 @@ inline bool config_pause_uses_disabled() {
133137
inline bool config_vehicle_range_miles() {
134138
return CONFIG_VEHICLE_RANGE_MILES == (flags & CONFIG_VEHICLE_RANGE_MILES);
135139
}
140+
141+
inline bool config_rfid_enabled() {
142+
return CONFIG_RFID == (flags & CONFIG_RFID);
143+
}
136144

137145
// Ohm Connect Settings
138146
extern String ohm;
@@ -178,6 +186,11 @@ extern void config_save_wifi(String qsid, String qpass);
178186
// -------------------------------------------------------------------
179187
extern void config_save_ohm(bool enable, String qohm);
180188

189+
// -------------------------------------------------------------------
190+
// Save RFID settings
191+
// -------------------------------------------------------------------
192+
extern void config_save_rfid(bool enable, String storage);
193+
181194
// -------------------------------------------------------------------
182195
// Save the flags
183196
// -------------------------------------------------------------------

src/evse_man.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef uint32_t EvseClient;
3232
#define EvseClient_OpenEVSE_Error EVC(EvseClient_Vendor_OpenEVSE, 0x0007)
3333
#define EvseClient_OpenEVSE_Ohm EVC(EvseClient_Vendor_OpenEVSE, 0x0008)
3434
#define EvseClient_OpenEVSE_Ocpp EVC(EvseClient_Vendor_OpenEVSE, 0x0009)
35+
#define EvseClient_OpenEVSE_RFID EVC(EvseClient_Vendor_OpenEVSE, 0x000A)
3536

3637
#define EvseClient_OpenEnergyMonitor_DemandShaper EVC(EvseClient_Vendor_OpenEnergyMonitor, 0x0001)
3738

@@ -44,6 +45,7 @@ typedef uint32_t EvseClient;
4445
#define EvseManager_Priority_API 500
4546
#define EvseManager_Priority_Ohm 500
4647
#define EvseManager_Priority_Manual 1000
48+
#define EvseManager_Priority_RFID 1030
4749
#define EvseManager_Priority_Ocpp 1050
4850
#define EvseManager_Priority_Limit 1100
4951
#define EvseManager_Priority_Error 10000

src/input.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "emoncms.h"
1818
#include "tesla_client.h"
1919
#include "manual.h"
20+
#include "rfid.h"
2021

2122
#include "LedManagerTask.h"
2223

@@ -84,6 +85,9 @@ class InputTask : public MicroTasks::Task
8485

8586
void create_rapi_json(JsonDocument &doc)
8687
{
88+
if(config_rfid_enabled()) {
89+
doc["rfid_auth"] = rfid.getAuthenticatedTag();
90+
}
8791
doc["amp"] = evse.getAmps() * AMPS_SCALE_FACTOR;
8892
doc["voltage"] = evse.getVoltage() * VOLTS_SCALE_FACTOR;
8993
doc["pilot"] = evse.getChargeCurrent();

src/main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <MongooseCore.h>
3131
#include <MicroTasks.h>
3232
#include <LITTLEFS.h>
33-
#include <ArduinoOcpp.h>
3433

3534
#include "emonesp.h"
3635
#include "app_config.h"
@@ -50,6 +49,11 @@
5049
#include "tesla_client.h"
5150
#include "event.h"
5251
#include "ocpp.h"
52+
#include "rfid.h"
53+
54+
#if defined(ENABLE_PN532)
55+
#include "pn532.h"
56+
#endif
5357

5458
#include "LedManagerTask.h"
5559
#include "event_log.h"
@@ -117,6 +121,12 @@ void setup()
117121
scheduler.begin();
118122

119123
lcd.begin(evse, scheduler, manual);
124+
#if defined(ENABLE_PN532)
125+
pn532.begin();
126+
rfid.begin(evse, pn532);
127+
#else
128+
rfid.begin(evse, rfidNullDevice);
129+
#endif
120130
ledManager.begin(evse);
121131

122132
// Initialise the WiFi
@@ -138,7 +148,7 @@ void setup()
138148

139149
input_setup();
140150

141-
ocpp.begin(evse, lcd, eventLog);
151+
ocpp.begin(evse, lcd, eventLog, rfid);
142152

143153
lcd.display(F("OpenEVSE WiFI"), 0, 0, 0, LCD_CLEAR_LINE);
144154
lcd.display(currentfirmware, 0, 1, 5 * 1000, LCD_CLEAR_LINE);

0 commit comments

Comments
 (0)