Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with README Examples and WebSocket Compatibility #709

Closed
AlessandroAmadoriTNO opened this issue Feb 13, 2025 · 5 comments
Closed

Comments

@AlessandroAmadoriTNO
Copy link

Hello everyone,

I encountered several issues while trying to install and reproduce the examples provided in the README and the scripts in the example folder. Here are the details:

  1. Variable Naming Inconsistency:

    • In the README, the variables RegistrationStatusType should be renamed to RegistrationStatusEnumType for both csms and cp.
  2. WebSocket Compatibility Issues:

    • The README recommends installing a generic version of websockets, which is at the moment version 14. However, this version introduces breaking changes compared to version 13, resulting in the following errors:

      • For cp:
        websockets.exceptions.ConnectionClosedError: received 1011 (internal error); then sent 1011 (internal error)
        INFO:websockets.server:server listening on 0.0.0.0:9000
        INFO:root:WebSocket Server Started
        INFO:websockets.server:connection open
        ERROR:websockets.server:connection handler failed
        TypeError: on_connect() missing 1 required positional argument: 'path'
        
      • For csms:
        INFO:websockets.server:server listening on 0.0.0.0:9000
        INFO:root:WebSocket Server Started
        INFO:websockets.server:connection open
        INFO:root:Protocols Matched: ocpp2.0.1
        INFO:ocpp:CP_1: receive message [2,"0b2c05c7-6945-4327-8003-4f6ae9c7ce7c","BootNotification",{"chargingStation":{"model":"Wallbox XYZ","vendorName":"anewone"},"reason":"PowerUp"}]
        INFO:root:Received BootNotification: {'model': 'Wallbox XYZ', 'vendor_name': 'anewone'}, PowerUp
        ERROR:ocpp:Error while handling request '<Call - unique_id=0b2c05c7-6945-4327-8003-4f6ae9c7ce7c, action=BootNotification, payload={'chargingStation': {'model': 'Wallbox XYZ', 'vendorName': 'anewone'}, 'reason': 'PowerUp'}>'
        websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
        INFO:websockets.server:connection closed
        
    • Downgrading to version 13.1 of websockets resolves some issues, but I still encounter the following errors:

      • For /examples/v201/central_system.py :
        INFO:websockets.server:server listening on 0.0.0.0:9000
        INFO:root:WebSocket Server Started
        INFO:websockets.server:connection open
        INFO:root:Protocols Matched: ocpp2.0.1
        INFO:ocpp:CP_1: receive message [2,"0b2c05c7-6945-4327-8003-4f6ae9c7ce7c","BootNotification",{"chargingStation":{"model":"Wallbox XYZ","vendorName":"anewone"},"reason":"PowerUp"}]
        INFO:root:Received BootNotification: {'model': 'Wallbox XYZ', 'vendor_name': 'anewone'}, PowerUp
        ERROR:ocpp:Error while handling request '<Call - unique_id=0b2c05c7-6945-4327-8003-4f6ae9c7ce7c, action=BootNotification, payload={'chargingStation': {'model': 'Wallbox XYZ', 'vendorName': 'anewone'}, 'reason': 'PowerUp'}>'
        websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
        INFO:websockets.server:connection closed
        
      • For /examples/v201/charge_point:
        AttributeError: module 'ocpp.v201.call' has no attribute 'BootNotificationPayload'. Did you mean: 'BootNotification'?
        
    • Similarly, for csms:

     INFO:websockets.server:server listening on 0.0.0.0:9000
     INFO:root:WebSocket Server Started
     INFO:websockets.server:connection open
     INFO:root:Protocols Matched: ocpp2.0.1
     INFO:ocpp:CP_1: receive message [2,"0b2c05c7-6945-4327-8003-4f6ae9c7ce7c","BootNotification",{"chargingStation":{"model":"Wallbox XYZ","vendorName":"anewone"},"reason":"PowerUp"}]
     INFO:root:Received BootNotification: {'model': 'Wallbox XYZ', 'vendor_name': 'anewone'}, PowerUp
     ERROR:ocpp:Error while handling request '<Call - unique_id=0b2c05c7-6945-4327-8003-4f6ae9c7ce7c, action=BootNotification, payload={'chargingStation': {'model': 'Wallbox XYZ', 'vendorName': 'anewone'}, 'reason': 'PowerUp'}>'
     websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
     INFO:websockets.server:connection closed
    
    • for cp:
    INFO:ocpp:CP_1: receive message [4,"0b2c05c7-6945-4327-8003-4f6ae9c7ce7c","InternalError","An unexpected error occurred.",{}]
    WARNING:ocpp:Received a CALLError: <CallError - unique_id=0b2c05c7-6945-4327-8003-4f6ae9c7ce7c, error_code=InternalError, error_description=An unexpected error occurred., error_details={}>'
    
  3. Working Commit:

    • All examples work correctly if I checkout the commit d25580c9a66c68843d49ebe8dbec24056654e27c.

Questions:

  1. Is it possible to update the examples in the README to reflect the correct variable names and ensure compatibility with the latest release?
  2. Can we have running examples for the latest release?
  3. Are there any plans to add support for websockets version 14?
@a-alak
Copy link
Contributor

a-alak commented Feb 13, 2025

  1. Agree, the README could really use an upgrade, and the current maintainers have an open issue on this was well: Improve documentation #702. I have it on my to do, to suggest something, but I just haven't found time to it yet.

  2. As I can see "websockets" library is not a dependency, but this library expects some behavior from the websocket connection. The only expected behaviour is asynchronous .send() and .recv() methods, and those have not been changed in websockets v14. So this library supports v14. However of course the examples given in README is not compatible with v14.

As of the issues you are having I can only identify the first issue as due to incompatibility with websockets v14. You can find a solution for that here #708.

The second issue you have is actually due to the example in README not being compatible with v2 of this library. The "Payload"-suffix is deprecated and you should just delete that. BootNotificationPayload is now just called BootNotification.

The third issue I can't really identify the problems from the added logs, could you maybe show the code?

@a-alak
Copy link
Contributor

a-alak commented Feb 13, 2025

Also I think the websocket compatibility is maybe an interesting topic to discuss. It could be to enable different websocket interfaces. Some of the webframeworks that support websockets use .recieve() instead of .recv() and maybe I saw somewhere .call() instead of .send().

I don't have good suggestion on how to make this library compatible with all different websocket implementations, but might be interesting to look in to.

@AlessandroAmadoriTNO
Copy link
Author

AlessandroAmadoriTNO commented Feb 13, 2025

Hello Ali,

Thank you for your reply,

On point 3 I have not written any code, the only thing I did was:

  1. clone the repository,
  2. checkout commit d25580c,
  3. $ pip install .
  4. run the python scripts in the example folder

The reason I checkout that commit was simply because it was the last one involving the scripts in /examples/v201 .

On the websocket, I was actually trying to see if I could run OCPP with some websockets with specific SSL contexts which have their special requirements (which we are starting to develop) and use the provided examples as starting point, but unfortunately they were not working out of the box with the latest release. I'll checkout if issue #708 can help.
Also, I wanted to understand if we needed to start working with websockets version 14 or 13 due to the fact that I could make the examples work for v13.

@a-alak a-alak mentioned this issue Feb 13, 2025
3 tasks
proelke pushed a commit that referenced this issue Feb 13, 2025
### Changes included in this PR 

Updates to the example usage of the library (doc update).

### Current behavior

#708 and #709 describe how the current examples in the documentation
fail due to 1) they still use the "Payload" suffix on payload data
classes, this is not part of the latest version of this library 2)
breaking changes from the WebSockets library, primarily regarding the
path parameter passed to the connection handler and where to find the
request headers.

### New behavior

This PR updates the example code both for v16 and v201, so that the
payload dataclass is correct and is compatible with the latest
websockets library.

### Impact

Only changes to documentation. However the documentation currently
wouldn't support older versions of websockets library.

### Checklist

1. [x] Does your submission pass the existing tests?
2. [ ] Are there new tests that cover these additions/changes? 
3. [x] Have you linted your code locally before submission?
@a-alak
Copy link
Contributor

a-alak commented Feb 13, 2025

I created the updates to the examples code that makes it compatible with websockets v14 and ocpp v2 in this PR #710. I think you can safely work with websockets version 14.

@AlessandroAmadoriTNO
Copy link
Author

Works like a charm! Thank you for your assistance

pabloariasmora added a commit to pabloariasmora/guidance-for-modernizing-electric-vehicle-charging-on-aws that referenced this issue Feb 27, 2025
- feat: specify exact package versions in requirements.txt per AWS MWAA best practices
- fix: restrict websockets to <14.0 due to OCPP v2.0.0 compatibility
- refactor: rename RegistrationStatusType to RegistrationStatusEnumType
- refactor: replace deprecated BootNotificationPayload with BootNotification
- refactor: replace deprecated HeartbeatPayload with Heartbeat()

Ref:
https://aws.amazon.com/blogs/big-data/amazon-mwaa-best-practices-for-managing-python-dependencies/
mobilityhouse/ocpp#709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants