-
Notifications
You must be signed in to change notification settings - Fork 3
/
charge_point.py
56 lines (42 loc) · 1.41 KB
/
charge_point.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import asyncio
import logging
try:
import websockets
except ModuleNotFoundError:
print("This example relies on the 'websockets' package.")
print("Please install it by running: ")
print()
print(" $ pip install websockets")
import sys
sys.exit(1)
from ocpp.v16 import call
from ocpp.v16 import ChargePoint as cp
from ocpp.v16.enums import RegistrationStatus
logging.basicConfig(level=logging.INFO)
class ChargePoint(cp):
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charge_point_model="Optimus",
charge_point_vendor="The Mobility House"
)
response = await self.call(request)
if response.status == RegistrationStatus.accepted:
print("Connected to central system.")
async def main():
async with websockets.connect(
'ws://localhost:9000/CP_1',
subprotocols=['ocpp1.6']
) as ws:
cp = ChargePoint('CP_1', ws)
await asyncio.gather(cp.start(), cp.send_boot_notification())
if __name__ == '__main__':
try:
# asyncio.run() is used when running this example with Python 3.7 and
# higher.
asyncio.run(main())
except AttributeError:
# For Python 3.6 a bit more code is required to run the main() task on
# an event loop.
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()