Skip to content

Commit

Permalink
Merge pull request #13 from villekr/issue/12
Browse files Browse the repository at this point in the history
Updated dependencies' versions #12
  • Loading branch information
villekr authored Sep 25, 2022
2 parents ee0bc07 + 687d4e5 commit 2abec3f
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 620 deletions.
39 changes: 3 additions & 36 deletions examples/central_system/standalone/central_system.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import asyncio

from ocpp.v16 import call as call16
from ocpp.v20 import call as call20
from ocpp.v201 import call as call201

from examples.central_system.routers.v16.provisioning_router import (
router as v16_provisioning_router,
)
Expand All @@ -30,7 +26,7 @@ async def on_connect(self, context: RouterContext) -> bool:
allow_connection = True

if allow_connection:
# Create task for running any logic that happens during connection setup
# Create task for running any logic that happens during connection set up
# The reasoning is that response from on_connect is quick and then allows
# processing to continue in central system
asyncio.create_task(self.after_on_connect(context))
Expand All @@ -44,37 +40,8 @@ async def on_disconnect(
)

async def after_on_connect(self, context: RouterContext):
# Example on how to send message to Charging Station e.g. after connection setup
# Note! This is just an example, and it's not recommended to tie communication
# towards Charging Station is on_connect event like this.
await asyncio.sleep(1) # Give Charging Station some time once connected
if context.subprotocol == Subprotocol.ocpp16.value:
message = call16.RemoteStartTransactionPayload(id_tag="abc")
router = self.routers[context.subprotocol]
elif context.subprotocol == Subprotocol.ocpp20.value:
id_token = {"idToken": "abc", "type": "Central"}
message = call20.RequestStartTransactionPayload(
id_token=id_token, remote_start_id=123
)
router = self.routers[context.subprotocol]
elif context.subprotocol == Subprotocol.ocpp201.value:
id_token = {"idToken": "abc", "type": "Central"}
message = call201.RequestStartTransactionPayload(
id_token=id_token, remote_start_id=123
)
router = self.routers[context.subprotocol]
else:
raise ValueError(f"Unknown sub-protocol value: {context.subprotocol=}")
try:
response = await router.call(message=message, context=context)
print(
f"(Central System) Charging Station {context.charging_station_id} {response=}" # noqa: E501
)
except Exception as e:
print(
f"(Central System) Failure sending message to Charging Station {context.charging_station_id} {e=}" # noqa: E501
)
pass
# Put any connection set up related logic here
pass


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 2abec3f

Please sign in to comment.