Limit publish frequency of state and power supply commands to not overload MQTT server

Combine function for displaying state and SoC for easier implementation
Announce state PreCharging without port voltage for easier matching downstream
This commit is contained in:
johannes 2024-12-02 10:35:08 +01:00
parent 3fe929541e
commit 866624eac0
2 changed files with 15 additions and 13 deletions

View file

@ -25,12 +25,11 @@ class fsmEvse():
def addToTrace(self, s):
self.callbackAddToTrace("[EVSE] " + s)
def publishStatus(self, s):
def publishStatus(self, s, soc=-1):
self.callbackShowStatus(s, "evseState")
self.hardwareInterface.displayState(s)
self.hardwareInterface.displayStateAndSoc(s, soc)
def publishSoCs(self, current_soc: int, full_soc: int = -1, energy_capacity: int = -1, energy_request: int = -1, evccid: str = "", origin: str = ""):
self.hardwareInterface.displaySoc(current_soc)
if self.callbackSoCStatus is not None:
self.callbackSoCStatus(current_soc, full_soc, energy_capacity, energy_request, self.evccid, origin)
@ -243,7 +242,7 @@ class fsmEvse():
msg = addV2GTPHeader("809a0125e6cecc5020804080000400")
self.addToTrace("responding " + prettyHexMessage(msg))
self.showDecodedTransmitMessage(msg)
self.publishStatus("CableCheck")
self.publishStatus("CableCheck", current_soc)
if (not testsuite_faultinjection_is_triggered(TC_EVSE_Timeout_during_CableCheck)):
self.Tcp.transmit(msg)
self.enterState(stateWaitForFlexibleRequest) # todo: not clear, what is specified in DIN
@ -284,7 +283,7 @@ class fsmEvse():
msg = addV2GTPHeader("809a0125e6cecc516080408000008284de880800")
self.addToTrace("responding " + prettyHexMessage(msg))
self.showDecodedTransmitMessage(msg)
self.publishStatus("PreCharging " + strPresentVoltage)
self.publishStatus("PreCharging")
if (not testsuite_faultinjection_is_triggered(TC_EVSE_Timeout_during_PreCharge)):
self.Tcp.transmit(msg)
self.enterState(stateWaitForFlexibleRequest) # todo: not clear, what is specified in DIN
@ -368,7 +367,7 @@ class fsmEvse():
msg = addV2GTPHeader("809a0125e6cecc50e0804080000082867dc8081818000000040a1b64802030882702038486580800")
self.addToTrace("responding " + prettyHexMessage(msg))
self.showDecodedTransmitMessage(msg)
self.publishStatus("CurrentDemand")
self.publishStatus("CurrentDemand", current_soc)
if (not testsuite_faultinjection_is_triggered(TC_EVSE_Timeout_during_CurrentDemand)):
self.Tcp.transmit(msg)
self.enterState(stateWaitForFlexibleRequest) # todo: not clear, what is specified in DIN

View file

@ -90,13 +90,12 @@ class hardwareInterface():
def addToTrace(self, s):
self.callbackAddToTrace("[HARDWAREINTERFACE] " + s)
def displayState(self, state):
if (getConfigValue("digital_output_device")=="mqtt"):
def displayStateAndSoc(self, state, soc):
if (getConfigValue("digital_output_device")=="mqtt") and (time() - self.lastStatePublish) >= 1:
self.mqttclient.publish(getConfigValue("mqtt_topic") + "/fsm_state", state)
def displaySoc(self, soc):
if getConfigValue("charge_parameter_backend") == "mqtt":
self.mqttclient.publish(getConfigValue("mqtt_topic") + "/soc", str(soc))
if soc > 0:
self.mqttclient.publish(getConfigValue("mqtt_topic") + "/soc", str(soc))
self.lastStatePublish = time()
def setStateB(self):
self.addToTrace("Setting CP line into state B.")
@ -194,9 +193,10 @@ class hardwareInterface():
# if we are the charger, and have a real power supply which we want to control, we do it here
self.homeplughandler.sendSpecialMessageToControlThePowerSupply(targetVoltage, targetCurrent)
#here we can publish the voltage and current requests received from the PEV side
if getConfigValue("charge_parameter_backend") == "mqtt":
if getConfigValue("charge_parameter_backend") == "mqtt" and (time() - self.lastPowerReqPublish) >= 1:
self.mqttclient.publish(getConfigValue("mqtt_topic") + "/target_voltage", str(targetVoltage))
self.mqttclient.publish(getConfigValue("mqtt_topic") + "/target_current", str(targetCurrent))
self.lastPowerReqPublish = time()
def getInletVoltage(self):
# uncomment this line, to take the simulated inlet voltage instead of the really measured
@ -324,6 +324,9 @@ class hardwareInterface():
self.logged_plugged_in = None
self.rxbuffer = ""
self.lastStatePublish = 0
self.lastPowerReqPublish = 0
self.findSerialPort()
self.initPorts()