Skip to content

Commit 3b302d7

Browse files
committed
update example, fix compiler warnings
1 parent df0af45 commit 3b302d7

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

examples/ESP/main.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ ESP8266WiFiMulti WiFiMulti;
1515

1616
#include <ArduinoOcpp.h>
1717

18-
#define STASSID "YOUR_WLAN_SSID"
19-
#define STAPSK "YOUR_WLAN_PW"
18+
#define STASSID "YOUR_WIFI_SSID"
19+
#define STAPSK "YOUR_WIFI_PW"
2020

2121
#define OCPP_HOST "echo.websocket.events"
2222
#define OCPP_PORT 80
@@ -110,19 +110,30 @@ void loop() {
110110
* Detect if something physical happened at your EVSE and trigger the corresponding OCPP messages
111111
*/
112112
if (/* RFID chip detected? */ false) {
113-
const char *idTag = "my-id-tag"; //e.g. idTag = RFID.readIdTag();
114-
authorize(idTag);
113+
const char *idTag = "0123456789abcd"; //e.g. idTag = RFID.readIdTag();
114+
authorize(idTag, [] (JsonObject response) {
115+
//check if user with idTag is authorized
116+
if (!strcmp("Accepted", response["idTagInfo"]["status"] | "Invalid")){
117+
Serial.println(F("[main] User is authorized to start charging"));
118+
} else {
119+
Serial.printf("[main] Authorize denied. Reason: %s\n", response["idTagInfo"]["status"] | "");
120+
}
121+
});
122+
Serial.printf("[main] Authorizing user with idTag %s\n", idTag);
115123
}
116124

117-
if (/* EV plugged in? */ false) {
118-
startTransaction("my-id-tag", [] (JsonObject payload) {
125+
if (/* EV plugged in and user authorized? */ false) {
126+
const char *idTag = "0123456789abcd"; //e.g. authorized idTag from above
127+
startTransaction(idTag, [] (JsonObject response) {
119128
//Callback: Central System has answered. Could flash a confirmation light here.
120-
Serial.print(F("[main] Started OCPP transaction\n"));
129+
Serial.printf("[main] Started OCPP transaction. Status: %s, transactionId: %u\n",
130+
response["idTagInfo"]["status"] | "Invalid",
131+
response["transactionId"] | -1);
121132
});
122133
}
123134

124135
if (/* EV unplugged? */ false) {
125-
stopTransaction([] (JsonObject payload) {
136+
stopTransaction([] (JsonObject response) {
126137
//Callback: Central System has answered.
127138
Serial.print(F("[main] Stopped OCPP transaction\n"));
128139
});

src/ArduinoOcpp/MessagesV16/Reset.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ void Reset::processReq(JsonObject payload) {
2525

2626
if (ocppModel && ocppModel->getChargePointStatusService()) {
2727
auto cpsService = ocppModel->getChargePointStatusService();
28-
unsigned int connId = 0;
29-
for (unsigned int i = 0; i < cpsService->getNumConnectors(); i++) {
28+
int connId = 0;
29+
for (int i = 0; i < cpsService->getNumConnectors(); i++) {
3030
auto connector = cpsService->getConnector(connId);
3131
if (connector) {
3232
connector->endSession();

src/ArduinoOcpp/Tasks/ChargePointStatus/ChargePointStatusService.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace ArduinoOcpp;
1717
ChargePointStatusService::ChargePointStatusService(OcppEngine& context, unsigned int numConn)
1818
: context(context) {
1919

20-
for (int i = 0; i < numConn; i++) {
20+
for (unsigned int i = 0; i < numConn; i++) {
2121
connectors.push_back(std::unique_ptr<ConnectorStatus>(new ConnectorStatus(context.getOcppModel(), i)));
2222
}
2323

@@ -61,7 +61,7 @@ void ChargePointStatusService::loop() {
6161
}
6262

6363
ConnectorStatus *ChargePointStatusService::getConnector(int connectorId) {
64-
if (connectorId < 0 || connectorId >= connectors.size()) {
64+
if (connectorId < 0 || connectorId >= (int) connectors.size()) {
6565
AO_DBG_ERR("connectorId is out of bounds");
6666
return nullptr;
6767
}

src/ArduinoOcpp/Tasks/Metering/MeteringService.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MeteringService::MeteringService(OcppEngine& context, int numConn)
1919

2020
void MeteringService::loop(){
2121

22-
for (int i = 0; i < connectors.size(); i++){
22+
for (unsigned int i = 0; i < connectors.size(); i++){
2323
auto meterValuesMsg = connectors[i]->loop();
2424
if (meterValuesMsg != nullptr) {
2525
auto meterValues = makeOcppOperation(meterValuesMsg);
@@ -30,31 +30,31 @@ void MeteringService::loop(){
3030
}
3131

3232
void MeteringService::setPowerSampler(int connectorId, PowerSampler ps){
33-
if (connectorId < 0 || connectorId >= connectors.size()) {
33+
if (connectorId < 0 || connectorId >= (int) connectors.size()) {
3434
AO_DBG_ERR("connectorId is out of bounds");
3535
return;
3636
}
3737
connectors[connectorId]->setPowerSampler(ps);
3838
}
3939

4040
void MeteringService::setEnergySampler(int connectorId, EnergySampler es){
41-
if (connectorId < 0 || connectorId >= connectors.size()) {
41+
if (connectorId < 0 || connectorId >= (int) connectors.size()) {
4242
AO_DBG_ERR("connectorId is out of bounds");
4343
return;
4444
}
4545
connectors[connectorId]->setEnergySampler(es);
4646
}
4747

4848
float MeteringService::readEnergyActiveImportRegister(int connectorId) {
49-
if (connectorId < 0 || connectorId >= connectors.size()) {
49+
if (connectorId < 0 || connectorId >= (int) connectors.size()) {
5050
AO_DBG_ERR("connectorId is out of bounds");
5151
return 0.f;
5252
}
5353
return connectors[connectorId]->readEnergyActiveImportRegister();
5454
}
5555

5656
std::unique_ptr<OcppOperation> MeteringService::takeMeterValuesNow(int connectorId) {
57-
if (connectorId < 0 || connectorId >= connectors.size()) {
57+
if (connectorId < 0 || connectorId >= (int) connectors.size()) {
5858
AO_DBG_ERR("connectorId out of bounds. Ignore");
5959
return nullptr;
6060
}

0 commit comments

Comments
 (0)