Replies: 4 comments 2 replies
-
Hello. Glad to hear that the library useful for you. I just created a PR #181 that explains how to write websocket adapters. Does that help you? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Not really. It's my first time in python and it's really hard for me ...
I'm trying to do something like that but I can't ... Thanks for your time.
from typing import List
import uvicorn
import logging
from datetime import datetime
from ocpp.routing import on
from ocpp.v16 import ChargePoint as cp
from ocpp.v16.enums import Action, RegistrationStatus
from ocpp.v16 import call_result
from fastapi import FastAPI, WebSocket
app = FastAPI()
@app.get("/")
async def get():
return 'index'
class ChargePoint(cp):
@on(Action.BootNotification)
def on_boot_notification(self, charge_point_vendor: str, charge_point_model:
str, **kwargs):
return call_result.BootNotificationPayload(
current_time=datetime.utcnow().isoformat(),
interval=10,
status=RegistrationStatus.accepted
)
class ConnectionManager:
def __init__(self):
self.active_connections: List[WebSocket] = []
async def connect(self, id: str, websocket: WebSocket):
await websocket.accept(subprotocol="ocpp1.6")
self.active_connections.append(websocket)
#websocket.recv = websocket.receive
cp = ChargePoint(id, websocket)
await cp.start()
def disconnect(self, websocket: WebSocket):
self.active_connections.remove(websocket)
async def send_personal_message(self, message: str, websocket: WebSocket):
await websocket.send_text(message)
async def broadcast(self, message: str):
for connection in self.active_connections:
await connection.send_text(message)
manager = ConnectionManager()
@app.websocket("/ws/{id}")
async def websocket_endpoint(websocket: WebSocket, id: str):
print(id)
await manager.connect(id, websocket)
while True:
data = await websocket.receive_text()
print(data)
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=5000)
El dom, 28 feb 2021 a las 9:20, Auke Willem Oosterhoff (<
notifications@github.com>) escribió:
… Hello. Glad to hear that the library useful for you.
I just created a PR #181 <#181>
that explains how to write websocket adapters. Does that help you?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#177 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFHQ6XRXTCU6KANOZFZB5BDTBIYI5ANCNFSM4YFKLOUQ>
.
--
GNUinos - Soluciones Informáticas
Martín R. Smith
|
Beta Was this translation helpful? Give feedback.
1 reply
-
It tells me that the websocket does not have the recv property. I
understand that I do not import the websockets library but I use the one
from fastapi ... the truth is that I do not know how to do it so that it
works together. I only manage to connect, but I can't do the .start (). It
really worked very well for me if I used fastapi ... :( Thank you for your
time, you are incredible and I am immensely grateful. I attach a program to
avoid indentation problems.
El mié, 3 mar 2021 a las 5:02, Auke Willem Oosterhoff (<
notifications@github.com>) escribió:
… Can you fix the indenting of the code? And can you elaborate on why this
code doesn't work?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#177 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFHQ6XUOYLAQSYGFW6DLTB3TBXUJBANCNFSM4YFKLOUQ>
.
--
GNUinos - Soluciones Informáticas
Martín R. Smith
fastapi==0.63.0
uvicorn[standard]
|
Beta Was this translation helpful? Give feedback.
1 reply
-
FAST API is not support for "wss"(secure), it is only for ws. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all Thanks for the library. I have a small program that works very well with websocket and aiohttp. For implementation reasons, they ask me to use a single port. I found "Flask-SocketIO", but I feel at a loss on how to make it work ... Did anyone? any ideas?
Beta Was this translation helpful? Give feedback.
All reactions