Skip to content

Commit 1c80d13

Browse files
committed
fix workflows
1 parent 44f05c3 commit 1c80d13

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

examples/ESP/main.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ESP8266WiFiMulti WiFiMulti;
2424
//
2525
// Settings which worked for my SteVe instance:
2626
//
27-
//#define OCPP_BACKEND_URL "ws://192.168.178.100:8180/steve/websocket/CentralSystemService"
27+
//#define OCPP_BACKEND_URL "ws://192.168.178.100:8080/steve/websocket/CentralSystemService"
2828
//#define OCPP_CHARGE_BOX_ID "esp-charger"
2929

3030
void setup() {
@@ -58,22 +58,32 @@ void setup() {
5858
/*
5959
* Initialize the OCPP library
6060
*/
61-
mocpp_initialize(OCPP_BACKEND_URL, OCPP_CHARGE_BOX_ID, "My Charging Station", "My company name");
61+
mo_initialize();
62+
63+
mo_setWebsocketUrl(
64+
OCPP_BACKEND_URL, //OCPP backend URL
65+
OCPP_CHARGE_BOX_ID, //ChargeBoxId, assigned by OCPP backend
66+
nullptr, //Authorization key (`nullptr` disables Basic Auth)
67+
nullptr); //OCPP backend TLS certificate (`nullptr` disables certificate check)
68+
69+
mo_setBootNotificationData("My Charging Station", "My company name");
70+
71+
mo_setOcppVersion(MO_OCPP_V16); //Run OCPP 1.6. For v2.0.1, pass argument `MO_OCPP_V201`
6272

6373
/*
6474
* Integrate OCPP functionality. You can leave out the following part if your EVSE doesn't need it.
6575
*/
66-
setEnergyMeterInput([]() {
76+
mo_setEnergyMeterInput([]() {
6777
//take the energy register of the main electricity meter and return the value in watt-hours
68-
return 0.f;
78+
return 0;
6979
});
7080

71-
setSmartChargingCurrentOutput([](float limit) {
81+
mo_setSmartChargingCurrentOutput([](float limit) {
7282
//set the SAE J1772 Control Pilot value here
7383
Serial.printf("[main] Smart Charging allows maximum charge rate: %.0f\n", limit);
7484
});
7585

76-
setConnectorPluggedInput([]() {
86+
mo_setConnectorPluggedInput([]() {
7787
//return true if an EV is plugged to this EVSE
7888
return false;
7989
});
@@ -86,12 +96,12 @@ void loop() {
8696
/*
8797
* Do all OCPP stuff (process WebSocket input, send recorded meter values to Central System, etc.)
8898
*/
89-
mocpp_loop();
99+
mo_loop();
90100

91101
/*
92102
* Energize EV plug if OCPP transaction is up and running
93103
*/
94-
if (ocppPermitsCharge()) {
104+
if (mo_ocppPermitsCharge()) {
95105
//OCPP set up and transaction running. Energize the EV plug here
96106
} else {
97107
//No transaction running at the moment. De-energize EV plug
@@ -103,7 +113,7 @@ void loop() {
103113
if (/* RFID chip detected? */ false) {
104114
String idTag = "0123456789ABCD"; //e.g. idTag = RFID.readIdTag();
105115

106-
if (!getTransaction()) {
116+
if (!mo_getTransactionIdTag()) {
107117
//no transaction running or preparing. Begin a new transaction
108118
Serial.printf("[main] Begin Transaction with idTag %s\n", idTag.c_str());
109119

@@ -112,7 +122,7 @@ void loop() {
112122
* and listen to the ConnectorPlugged Input. When the Authorization succeeds and an EV
113123
* is plugged, the OCPP lib will send the StartTransaction
114124
*/
115-
auto ret = beginTransaction(idTag.c_str());
125+
auto ret = mo_beginTransaction(idTag.c_str());
116126

117127
if (ret) {
118128
Serial.println(F("[main] Transaction initiated. OCPP lib will send a StartTransaction when" \
@@ -122,15 +132,10 @@ void loop() {
122132
}
123133

124134
} else {
125-
//Transaction already initiated. Check if to stop current Tx by RFID card
126-
if (idTag.equals(getTransactionIdTag())) {
127-
//card matches -> user can stop Tx
128-
Serial.println(F("[main] End transaction by RFID card"));
129-
130-
endTransaction(idTag.c_str());
131-
} else {
132-
Serial.println(F("[main] Cannot end transaction by RFID card (different card?)"));
133-
}
135+
//Transaction already initiated. Attempt to stop current Tx by RFID card. If idTag is the same,
136+
//or in the same group, then MO will stop the transaction and `mo_ocppPermitsCharge()` becomes
137+
//false
138+
mo_endTransaction(idTag.c_str(), nullptr); //`idTag` and `reason` can be nullptr
134139
}
135140
}
136141

0 commit comments

Comments
 (0)