Closed arpantechparticle closed 11 months ago
Can you provide a strack trace? Without more details, I can't help you.
thank you for reply @OrangeTux. i try this for last 4 days but no luck. here is my strack trace
ERROR:ocpp:Error while handling request '<Call - unique_id=ba63e555-a3c9-400f-8d0f-ce07f89dd680, action=RemoteStartTransaction, payload={'connectorId': 1, 'idTag': '123'}>'
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/queues.py", line 166, in get
await getter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
fut.result()
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 288, in call
response = await self._get_specific_response(
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 322, in _get_specific_response
response = await asyncio.wait_for(self._response_queue.get(), timeout)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 205, in _handle_call
response = await response
File "/Users/arpanpatel/projects/spotcharge-occp-api/sc_ocpp16.py", line 64, in remote_start_transaction
response = await self.call(request)
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 292, in call
raise asyncio.TimeoutError(
asyncio.exceptions.TimeoutError: Waited 30s for response on [2,"f4260f9f-cc73-45ea-a176-b57ad1c060c6","RemoteStartTransaction",{"idTag":"123","connectorId":1}].
self.sockets [<starlette.websockets.WebSocket object at 0x108afb6d0>]
The stack trace you've added doesn't mention asdict()
. Can post such stack trace?
while handle this error using CancelledError exception. I got asdict error in this function. is my implementation right for remoteStartTranscation
async def _pubsub_data_reader(self, pubsub_subscriber, cp):
"""
Reads and broadcasts messages received from Redis PubSub.
Args:
pubsub_subscriber (aioredis.ChannelSubscribe): PubSub object for the subscribed channel.
"""
try:
print('it come here')
while True:
message = await pubsub_subscriber.get_message(ignore_subscribe_messages=True)
if message is not None:
print("only if message available", message)
charger_id = message['channel'].decode('utf-8')
print("charger_id", charger_id)
cp.set_sockets(self.rooms[charger_id])
data = message['data'].decode('utf-8')
print("message form", data)
await cp.route_message(data)
except asyncio.CancelledError as e:
reason = str(e)
print(f"An error occurred in _pubsub_data_reader: {reason}")
except Exception as e:
# Handle other exceptions that may occur
print(f"An error occurred in _pubsub_data_reader: {e}")
finally:
# Perform cleanup if necessary
pass
when i call
/start/{charge_point_id}
end point. it create message like this
[2,"fae42889-978d-471c-865a-5611a0126506","RemoteStartTransaction",{"idTag":"123","connectorId":1}]
then send broadcast this message. now this message comes in
async def _pubsub_data_reader(self, pubsub_subscriber, cp):
"""
Reads and broadcasts messages received from Redis PubSub.
Args:
pubsub_subscriber (aioredis.ChannelSubscribe): PubSub object for the subscribed channel.
"""
try:
print('it come here')
while True:
message = await pubsub_subscriber.get_message(ignore_subscribe_messages=True)
if message is not None:
print("only if message available", message)
charger_id = message['channel'].decode('utf-8')
print("charger_id", charger_id)
cp.set_sockets(self.rooms[charger_id])
data = message['data'].decode('utf-8')
print("message form", data)
await cp.route_message(data)
except asyncio.CancelledError as e:
reason = str(e)
print(f"An error occurred in _pubsub_data_reader: {reason}")
except Exception as e:
# Handle other exceptions that may occur
print(f"An error occurred in _pubsub_data_reader: {e}")
finally:
# Perform cleanup if necessary
pass
this message now goes to
@on(Action.RemoteStartTransaction)
async def remote_start_transaction(self, id_tag, connector_id, **kwargs):
try:
print('kwargs', kwargs)
request = call.RemoteStartTransactionPayload(id_tag=id_tag, connector_id=connector_id)
print('is data class', is_dataclass(request))
response = await self.call(request)
print('response.status', response.status)
if response.status == RemoteStartStopStatus.accepted:
print("Transaction Started!!!")
return response
except asyncio.CancelledError as e:
reason = str(e)
print(f"An error occurred in remote_start_transaction: {reason}")
except Exception as e:
# Handle other exceptions that may occur
print(f"An error occurred in remote_start_transaction: {e}")
finally:
# Perform cleanup if necessary
pass
here i got error.
I'm sorry to be annoying, but you still didn't posted a stack trace with that includes the exception from the opening post. Please provide it.
It's alright, and I appreciate your patience. Here's my understanding of what you want from me.
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-8' coro=<WebSocketManager._pubsub_data_reader() done, defined at /Users/arpanpatel/projects/spotcharge-occp-api/pubsub.py:154> exception=TypeError('asdict() should be called on dataclass instances')>
Traceback (most recent call last):
File "/Users/arpanpatel/projects/spotcharge-occp-api/pubsub.py", line 181, in _pubsub_data_reader
await cp.route_message(data)
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 154, in route_message
await self._handle_call(msg)
File "/Users/arpanpatel/projects/spotcharge-occp-api/venv/lib/python3.9/site-packages/ocpp/charge_point.py", line 214, in _handle_call
temp_response_payload = asdict(response)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/dataclasses.py", line 1074, in asdict
raise TypeError("asdict() should be called on dataclass instances")
TypeError: asdict() should be called on dataclass instances
On line - temp_response_payload = asdict(response) - response is not a dataclass; asdict requires a dataclass - see https://docs.python.org/3/library/dataclasses.html
an example of a dataclass (note the decorator) could be a ChargingScheduleType datatype from OCPP 2.0.1:
@dataclass
class ChargingScheduleType:
"""
Charging schedule structure defines a list of charging periods, as used in:
GetCompositeSchedule.conf and ChargingProfile.
ChargingScheduleType is used by: ChargingProfileType,
NotifyChargingLimitRequest, NotifyEVChargingScheduleRequest
"""
id: int
charging_rate_unit: enums.ChargingRateUnitType
charging_schedule_period: ChargingSchedulePeriodType
start_schedule: Optional[str] = None
duration: Optional[int] = None
min_charging_rate: Optional[float] = None
sales_tariff: Optional[SalesTariffType] = None
You could check response's type with type() to confirm,
However, as this is not directly related to this library, I'll close the issue for now
I am using this awesome library and here is my code. I got following error asdict() should be called on dataclass instances. when calling start api
charging system file
Fast api route
@app.post("/start/{charge_point_id}")
and pubsub code