- reportBase=ReportBaseType.ConfigurationInventory
- ) # Use correct ReportBaseType
- try:
- response = await self.call(request)
- logging.info("Send %s", Action.GetBaseReport)
-
- if response.status == ReportBaseType.accepted:
- logging.info("%s successful", Action.GetBaseReport)
- else:
- logging.info("%s failed", Action.GetBaseReport)
-
- except ConnectionClosed as e:
- logging.error("Connection closed: %s", str(e))
-
- except Exception as e:
- logging.error("Unexpected error occurred: %s", str(e))
-
- logging.info("send_get_base_report done.")
-
-
-
-# Function to send OCPP command
-async def send_ocpp_command(cp, command_name, delay=None, period=None):
- # If delay is not None, sleep for delay seconds
- if delay:
- await asyncio.sleep(delay)
-
- # If period is not None, send command repeatedly with period interval
- if period:
- async def send_command_repeatedly():
- while True:
- command_name = await cp.receive_command()
- try:
- match command_name:
- case Action.ClearCache:
- logging.info("ClearCache parser working")
- await cp.send_clear_cache()
- case Action.GetBaseReport:
- logging.info("GetBaseReport parser working")
- await cp.send_get_base_report()
- case _:
- logging.warning(f"Unsupported command {command_name}")
- except Exception as e:
- logging.exception(f"Failure while processing command {command_name}")
- finally:
- await asyncio.sleep(period)
-
- timer = RepeatTimer(period, send_command_repeatedly)
- await timer.start()
- await timer.wait_closed() # Wait for timer to finish before exiting