ocpp
ocpp copied to clipboard
Query about implementing OCPP messages
Hi,
I am fairly new to the OCPP world and I am trying to implement ocpp.v201
messages. While I implemented the example explained in the readme successfully, I ran into doubt regarding the way the library is being set up. Explaining the query via an example would consider that the controller will follow these series of actions: cold boot notification -> authorize. Now these commands in terms of hardware sending the data should essentially work sequentially so should I add the authorize method in asyncio.gather()
itself?
Attaching the code below, to explain better:
import logging
import websockets
from ocpp.v201 import call
from ocpp.v201 import ChargePoint as cp
logging.basicConfig(level=logging.INFO)
class ChargePoint(cp):
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charging_station={
'model': 'Wallbox XYZ',
'vendor_name': 'anewone'
},
reason="PowerUp"
)
response = await self.call(request)
# if response.status == 'Accepted':
# print("Connected to central system.")
async def send_authorize_notification(self):
request = call.AuthorizePayload(
id_token={
'idToken': 'id_token',
'type': 'Central'
}
)
response = await self.call(request)
async def main():
async with websockets.connect(
'ws://localhost:9000/CP_1',
subprotocols=['ocpp2.0.1']
) as ws:
cp = ChargePoint('CP_1', ws)
await asyncio.gather(cp.start(), cp.send_boot_notification(), cp.send_authorize_notification())
if __name__ == '__main__':
asyncio.run(main())
Just to reiterator, the question is just where and how to call the .send_authorize_notification()
coroutine now. In this code, it will run in parallel which I think is not correct if thought in hardware terms as the CP will completely boot first and then authorize a user.
PS: Please correct me if my understanding of the architecture is not correct anywhere.