- response = await self.call(request)
- logging.info("Send GetBaseReport")
-
- if (
- response.status == "Accepted"
- ): # Adjust depending on the structure of your response
- logging.info("Send GetBaseReport successful")
- else:
- logging.info("Send GetBaseReport failed")
- except Exception as e:
- logging.error(f"Send GetBaseReport failed: {str(e)}")
- logging.info("send_get_base_report done.")
-
-
-# Define argument parser
-parser = argparse.ArgumentParser(description="OCPP Charge Point Simulator")
-parser.add_argument("--request", type=str, help="OCPP 2 Command Name")
-parser.add_argument("--delay", type=int, help="Delay in seconds")
-parser.add_argument("--period", type=int, help="Period in seconds")
-
-args = parser.parse_args()
-
-
-# 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:
- while True:
- if command_name == "GetBaseReport":
- logging.info("GetBaseReport parser working")
- await cp.send_get_base_report()
-
- await asyncio.sleep(period)
- else:
- if command_name == "GetBaseReport":
- await cp.send_get_base_report()
+ if delay and not self._command_timer:
+ self._command_timer = Timer(
+ delay,
+ False,
+ self._send_command,
+ [command_name],
+ )
+ if period and not self._command_timer:
+ self._command_timer = Timer(
+ period,
+ True,
+ self._send_command,
+ [command_name],
+ )
+ except ConnectionClosed:
+ self.handle_connection_closed()
+
+ def handle_connection_closed(self):
+ logging.info("ChargePoint %s closed connection", self.id)
+ if self._command_timer:
+ self._command_timer.cancel()
+ ChargePoints.remove(self)
+ logging.debug("Connected ChargePoint(s): %d", len(ChargePoints))