@@ -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 });
0 commit comments