matth-x / MicroOcpp

OCPP 1.6 client for microcontrollers
MIT License
340 stars 149 forks source link

How to restore previous charging session when power cut off during charging #174

Closed demirschmid61 closed 1 year ago

demirschmid61 commented 1 year ago

Hi @matth-x,

Thank you very much for this beautiful OCPP library, congratulations to you and your team.

I am able to complete one charging cycle remotely as well as locally. The meter values are also sending with the 15 sec sampling time.

I am facing one problem when the charging is in progress and sudden power fails, then how do I regain the previous charging session?

The following steps I did for the scenario:

Step 1: Connect the GUN (Preparing) Step 2: Start Charging (Charging) Step 3: Sending MeterValues Step 4: OFF the ESP32 board..

When I turned ON the board the board is not able to communicate with the OCPP server, the error logs is mentioned below.

*****LOG Started** rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5828 entry 0x400806a8 [main] Wait for WiFi: ... connected! [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /arduino-ocpp.cnf

[AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /opstore.cnf

[AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /txstore.jsn

[AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /volatile

[E][WiFiClient.cpp:485] flush(): fail on fd 54, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

[E][WiFiClient.cpp:485] flush(): fail on fd 55, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

[E][WiFiClient.cpp:485] flush(): fail on fd 56, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

[E][WiFiClient.cpp:485] flush(): fail on fd 57, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

*LOG END*****

Can you please go through my issue and suggest any solution for the issue.

matth-x commented 1 year ago

Hi @demirschmid61,

Thanks for the detailed report! Did you use the master or the develop branch and can you find out the download date or the commit hash?

demirschmid61 commented 1 year ago

Hi @matth-x ,

Did you use the master or the develop branch? : No.

Can you find out the download date or the commit hash? : Can you please elaborate more about it?

########### Power Given to Charger ########## [main] Wait for WiFi: .. connected! [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /arduino-ocpp.cnf [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /opstore.cnf [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /txstore.jsn [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /volatile [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:34): Connected to url: /ACTestCharger [AO] Send: [2,"1000000","BootNotification",{"chargePointModel":"ABCD","chargePointSerialNumber":"01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:34): Connected to url: /ACTestCharger [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:34): Connected to url: /ACTestCharger [AO] Send: [2,"1000000","BootNotification",{"chargePointModel":"S1-01","chargePointSerialNumber":"DK-01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] Recv: WS pong [AO] Recv: [3,"1000000",{"currentTime":"2023-08-15T13:32:44.835877300Z","interval":900,"status":"Accepted"}] [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/BootNotification.cpp:94): Request has been accepted [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 0) [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 1) [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 2) [AO] Send: [2,"1000001","StatusNotification",{"connectorId":0,"errorCode":"NoError","status":"Available","timestamp":"2023-08-15T13:32:44.000Z"}] [AO] Recv: [3,"1000001",{}] [AO] Send: [2,"1000002","StatusNotification",{"connectorId":1,"errorCode":"NoError","status":"Available","timestamp":"2023-08-15T13:32:44.000Z"}] [AO] Recv: [3,"1000002",{}] [AO] Send: [2,"1000003","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Available","timestamp":"2023-08-15T13:32:44.000Z"}] [AO] Recv: [3,"1000003",{}] Your Charger Status:ev_connect [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp.cpp:308): Added ConnectorPluggedSampler. Transaction-management is in auto mode now [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Preparing (connectorId 2) ############# EV Connected (Preparing) ############### [AO] Send: [2,"1000004","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Preparing","timestamp":"2023-08-15T13:32:49.000Z"}] [AO] Recv: [3,"1000004",{}] Your Charger Status:start_charging [main] Transaction initiated. StartTransaction will be sent when ConnectorPlugged Input becomes true [main] Authorizing user with idTag 123ABCD [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Tasks/ChargePointStatus/ConnectorStatus.cpp:284): Session mngt: trigger StartTransaction [AO] Send: [2,"1000005","StartTransaction",{"connectorId":2,"idTag":"123ABCD","meterStart":1311,"timestamp":"2023-08-15T13:32:56.000Z"}] [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Charging (connectorId 2) [AO] Recv: WS pong [AO] Recv: [3,"1000005",{"idTagInfo":{"status":"Accepted"},"transactionId":245217}] [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StartTransaction.cpp:145): Request has been accepted ################ EV Charging Started (Charging) ################ [AO] Send: [2,"1000006","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Charging","timestamp":"2023-08-15T13:32:59.000Z"}] [AO] Recv: [3,"1000006",{}] [AO] Recv: WS pong [AO] Send: [2,"1000007","MeterValues",{"connectorId":2,"transactionId":245217,"meterValue":[{"timestamp":"2023-08-15T13:33:11.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"1422","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000007",{}] [AO] Recv: WS pong [AO] Send: [2,"1000008","MeterValues",{"connectorId":2,"transactionId":245217,"meterValue":[{"timestamp":"2023-08-15T13:33:27.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"1533","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000008",{}] [AO] Recv: WS ping [AO] Recv: WS pong [AO] Send: [2,"1000009","MeterValues",{"connectorId":2,"transactionId":245217,"meterValue":[{"timestamp":"2023-08-15T13:33:42.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"1644","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000009",{}]

################## Assuming Power Cut off at this point ############ rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5828 entry 0x400806a8 [main] Wait for WiFi: .. connected! [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /arduino-ocpp.cnf [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /opstore.cnf [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /txstore.jsn [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /volatile [E][WiFiClient.cpp:485] flush(): fail on fd 54, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected [E][WiFiClient.cpp:485] flush(): fail on fd 55, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected [E][WiFiClient.cpp:485] flush(): fail on fd 56, errno: 11, "No more processes" [AO] info (.pio/libdeps/esp32-development-board/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

What is Expected at this point, the charger is trying to establish a connection between the server and the client My questions are:

  1. Should the CP begin from the same point where it ended or start a new transaction? OR
  2. The CP should send a stopTransaction request with the reason “Power Failure” and again start a new startTransaction request or something else.
  3. Do I need to send a stopTransaction request by calling endTransaction(reason.c_str(), connectorId) function at the start of the program after every reboot with reason as "Reboot"?
matth-x commented 1 year ago

This looks like an issue with the WebSocket library integration. There has been quite a lot of work to optimize it. Can you upgrade to the latest version? (i.e. the current code of this GitHub repo)

To answer your questions: it really depends on the target system if a reboot of the ESP should trigger a transaction stop. In commercial systems where the user pays for the electricity this is typically required. When OCPP is just used for supervision, it is not necessary.

In doubt, you can place endTransaction(nullptr, "PowerLoss"); at the beginning of the program. It will stop a potentially interrupted transaction or do nothing in case no transaction is still active.

demirschmid61 commented 1 year ago

Thank you very much @matth-x for your suggestion.

I have tried with the endTransaction(nullptr, "PowerLoss"); at the beginning of the program. The previous session get stopped after ESP32 get powered up.

But from a commercial point of view, meterStart value in startTransaction request is available with the OCPP server and it needs the meterStop value from the stopTransaction to calculate total energy consumed.

In my case, the meterStop value before power failure is not fetched properly. It'll affect the transaction amount during power loss.

Please have a look at the logs.

##########Log Started########## [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:34): Connected to url: /ACTestCharger [AO] Send: [2,"1000000","BootNotification",{"chargePointModel":"ABCD","chargePointSerialNumber":"01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] Recv: WS pong [AO] Recv: [3,"1000000",{"currentTime":"2023-08-16T17:55:11.120260300Z","interval":900,"status":"Accepted"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/BootNotification.cpp:94): Request has been accepted he boot notification accepted flag [AO] Send: [2,"1000001","BootNotification",{"chargePointModel":"ABCD","chargePointSerialNumber":"01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 0) [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 1) [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 2) [AO] Recv: [3,"1000001",{"currentTime":"2023-08-16T17:55:12.135003700Z","interval":900,"status":"Accepted"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/BootNotification.cpp:94): Request has been accepted The boot notification accepted flag 1 [AO] Send: [2,"1000002","StatusNotification",{"connectorId":0,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:55:11.000Z"}] [AO] Recv: [3,"1000002",{}] [AO] Send: [2,"1000003","StatusNotification",{"connectorId":1,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:55:11.000Z"}] [AO] Recv: [3,"1000003",{}] [AO] Send: [2,"1000004","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:55:11.000Z"}] [AO] Recv: [3,"1000004",{}] [AO] Recv: WS pong Your Charger Status:ev_connect ########EV Connected###### [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp.cpp:308): Added ConnectorPluggedSampler. Transaction-management is in auto mode now 0 [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Preparing (connectorId 2) [AO] Send: [2,"1000005","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Preparing","timestamp":"2023-08-16T17:55:34.000Z"}] [AO] Recv: [3,"1000005",{}] [AO] Recv: WS pong Your Charger Status:start_charging ########Charging Started###### [main] Transaction initiated. StartTransaction will be sent when ConnectorPlugged Input becomes true [main] Authorizing user with idTag ABCD123 0 [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Tasks/ChargePointStatus/ConnectorStatus.cpp:237): Session mngt: trigger StartTransaction [AO] Send: [2,"1000006","StartTransaction",{"connectorId":2,"idTag":"ABCD123","meterStart":0,"timestamp":"2023-08-16T17:55:45.000Z"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Charging (connectorId 2) [AO] Recv: [3,"1000006",{"idTagInfo":{"status":"Accepted"},"transactionId":939800}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StartTransaction.cpp:145): Request has been accepted [AO] Send: [2,"1000007","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Charging","timestamp":"2023-08-16T17:55:49.000Z"}] [AO] Recv: [3,"1000007",{}] [AO] Recv: WS pong [AO] Recv: WS ping [AO] Send: [2,"1000008","MeterValues",{"connectorId":2,"transactionId":939800,"meterValue":[{"timestamp":"2023-08-16T17:56:01.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"242","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000008",{}] [AO] Recv: WS pong [AO] Send: [2,"1000009","MeterValues",{"connectorId":2,"transactionId":939800,"meterValue":[{"timestamp":"2023-08-16T17:56:16.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"363","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000009",{}] [AO] Recv: WS pong [AO] Send: [2,"1000010","MeterValues",{"connectorId":2,"transactionId":939800,"meterValue":[{"timestamp":"2023-08-16T17:56:31.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"484","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000010",{}] [AO] Recv: WS pong [AO] Send: [2,"1000011","MeterValues",{"connectorId":2,"transactionId":939800,"meterValue":[{"timestamp":"2023-08-16T17:56:46.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"605","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000011",{}] [AO] Recv: WS pong [AO] Recv: WS ping [AO] Send: [2,"1000012","MeterValues",{"connectorId":2,"transactionId":939800,"meterValue":[{"timestamp":"2023-08-16T17:57:01.000Z","sampledValue":[{"value":"230","context":"Sample.Periodic","measurand":"Voltage","phase":"L1","unit":"V"},{"value":"124","context":"Sample.Periodic","measurand":"Current.import","phase":"L1","unit":"A"},{"value":"726","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","unit":"Wh"},{"value":"50","context":"Sample.Periodic","measurand":"Frequency","unit":"Hz"},{"value":"37","context":"Sample.Periodic","measurand":"Temperature","unit":"Celsius"}]}]}] [AO] Recv: [3,"1000012",{}] ets Jul 29 2019 12:21:46

########Assuming Power Loss###### rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1184 load:0x40078000,len:13192 load:0x40080400,len:3028 entry 0x400805e4 [main] Wait for WiFi: . connected! [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /arduino-ocpp.cnf
[AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /opstore.cnf [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /txstore.jsn [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/Configuration.cpp:96): init new configurations container: /volatile

[AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:31): Disconnected

[AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Core/OcppSocket.cpp:34): Connected to url: /ACTestCharger [AO] Send: [2,"1000000","BootNotification",{"chargePointModel":"ABCD","chargePointSerialNumber":"01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] Recv: WS pong [AO] Recv: [3,"1000000",{"currentTime":"2023-08-16T17:58:10.944069900Z","interval":900,"status":"Accepted"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/BootNotification.cpp:94): Request has been accepted he boot notification accepted flag [AO] Send: [2,"1000001","BootNotification",{"chargePointModel":"ABCD","chargePointSerialNumber":"01901","chargePointVendor":"Demirschmid","firmwareVersion":"0.0.1","meterSerialNumber":"0.0.1"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 0) [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 1) [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/Tasks/ChargePointStatus/ConnectorStatus.cpp:280): Session mngt: trigger StopTransaction ########stopTransaction request sent at the beginning of program and meterStop value is 0, it should be >=726 ######## [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StatusNotification.cpp:50): New status: Available (connectorId 2) [AO] Recv: [3,"1000001",{"currentTime":"2023-08-16T17:58:11.781642800Z","interval":900,"status":"Accepted"}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/BootNotification.cpp:94): Request has been accepted The boot notification accepted flag 1 [AO] Send: [2,"1000002","StatusNotification",{"connectorId":0,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:58:10.000Z"}] [AO] Recv: [3,"1000002",{}] [AO] Send: [2,"1000003","StatusNotification",{"connectorId":1,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:58:10.000Z"}] [AO] Recv: [3,"1000003",{}] ########Here meterStop is 0 Wh ######### [AO] Send: [2,"1000004","StopTransaction",{"meterStop":0,"timestamp":"2023-08-16T17:58:10.000Z","transactionId":939800,"reason":"Power Loss"}] [AO] Recv: [3,"1000004",{"idTagInfo":{"status":"Accepted"}}] [AO] info (.pio/libdeps/esp32dev/ArduinoOcpp/src/ArduinoOcpp/MessagesV16/StopTransaction.cpp:187): Request has been accepted! [AO] Send: [2,"1000005","StatusNotification",{"connectorId":2,"errorCode":"NoError","status":"Available","timestamp":"2023-08-16T17:58:11.000Z"}] [AO] Recv: [3,"1000005",{}] [AO] Recv: WS pong [AO] Recv: WS pong

##########Log End##########

As per the logs, the user has consumed 726 Wh but, the user will not have to pay any charges. (meterStop(0) - meterStart (0) = 0 kWh).

Is there any way to tackle this kind of situation?

matth-x commented 1 year ago

I tried to reproduce the first issue (WebSocket connection issue) on the master branch but it works in my case. Probably it has been fixed already and I won't investigate it any further, anyway thanks for the detailed and well commented report.

The second issue (meterStart and meterStop being 0) is probably due to the order of the ArduinoOcpp setup functions. In general, the order is

//create OCPP client instance
ocpp_initialize(...);

//set read access to device sensors
setEnergyMeterInput(...); //meterStart and meterStop will be initialized using this Input function

//(...) after setting up available sensors

//stop transaction from previous run (optional)
endTransaction(nullptr, "PowerLoss"); //this function will read the EnergyMeter Input

//(...) in loop():
ocpp_loop();

The important thing here is that ArduinoOcpp can read the device sensors only after setting up the corresponding Input functions. And all setup should be done before the program enters the loop stage.

In your logs I can see that the EnergyMeter Input is used correctly, but it's just set a little too late.

demirschmid61 commented 1 year ago

Thank you @matth-x for your kind reply,

The websocket is working in my case as well after updating the library.

For energy meter input, I'll do all setup function in proper way and check.

demirschmid61 commented 1 year ago

Hi @matth-x ,

I followed the setup function as mentioned by you. Used readEnergy function to read dummy whImport values and created dummy states using serial input.

Is there anything I am missing? Do I need to store meterStop value before power failure or OCPP library is managing it by storing it in the file system?

/**Order of the Setup Function **** OCPP_initialize(OCPP_HOST, OCPP_PORT, OCPP_URL); // OCPP Instance

setEnergyMeterInput([]() { return readEnergy(); }); // meterStart and meterStop will be initialized using this Input function

setConnectorPluggedInput([]() { return false; });

if (isTransactionRunning()) { endTransaction("PowerLoss"); // End transaction if any Serial.println(F(" Previous transaction was running now it is closed")); } else { Serial.println(F("No previous transaction running..")); } auto evseDetailsDoc = std::unique_ptr(new DynamicJsonDocument( JSON_OBJECT_SIZE(5) + 5 + 5 + 5)); JsonObject evseDetails = evseDetailsDoc->to(); evseDetails["chargePointModel"] = "ABCD"; evseDetails["chargePointSerialNumber"] = "01901"; evseDetails["chargePointVendor"] = "Demirschmid"; evseDetails["firmwareVersion"] = "0.0.1"; evseDetails["meterSerialNumber"] = "0.0.1"; bootNotification(std::move(evseDetailsDoc), [](JsonObject response) {}); // bootNotification /*****/

ino.txt main.txt

matth-x commented 1 year ago

This looks correct. However, note that in your example, the reboot also resets the mocked energy meter. When you call endTransaction(...) the library reads the EnergyMeterInput at that moment for the meterStop value.

demirschmid61 commented 1 year ago

@matth-x,

Is there any way to use the previous(which was stored in flash) meterStop value for endTransaction().

matth-x commented 1 year ago

This library doesn't save the energy meter reading while the transaction is running. It only stores the values sent with StartTransaction and StopTransaction. The non-volatile energy register needs to be implemented in the firmware code. A possible solution is to store the energy reading every minute in a file and after a blackout, to restore the energy reading before initializing the OCPP lib.

Feel free to reopen if you have follow-up questions.

demirschmid61 commented 1 year ago

@matth-x

Thank you very much for your suggestions. It's clear now.