lpcmanager

45715d2aaaf4
Parents c231fd7fd244
Children c996edcec59a
Fix SmartehCloud updates applying multiple times when re-connecting.
Ensure that LPCMQTT command execution is serialized.
This is a consequence of duplicate messages sent at init.
Seems to happen either because server or client ignores "cleansession"/"cleanstart".
  • +24 -24
    LPCMQTT.py
  • --- a/LPCMQTT.py Fri Feb 21 16:34:47 2025 +0100
    +++ b/LPCMQTT.py Mon Feb 24 15:58:21 2025 +0100
    @@ -30,36 +30,36 @@
    LPCTopic = "/smarteh/"+common_functions.getLPCSerialFromMAC()+"/command"
    +_{location}_lock = threading.Lock()
    +
    def _{location}_topic_callback(topic, payload):
    GetPLCObjectSingleton().LogMessage(
    LogLevelsDict["INFO"],
    "LPC MQTT {name} rcv: "+topic)
    -
    - lock = threading.RLock()
    -
    - with lock:
    - proc = Popen([os.path.join(os.path.dirname(common_functions.__file__), 'mqtt_command.sh')], stdin=PIPE, stdout=PIPE)
    - proc.stdin.write(payload)
    - proc.stdin.close()
    - proc.stdin = None
    +
    + _{location}_lock.acquire()
    + proc = Popen([os.path.join(os.path.dirname(common_functions.__file__), 'mqtt_command.sh')], stdin=PIPE, stdout=PIPE)
    + proc.stdin.write(payload)
    + proc.stdin.close()
    + proc.stdin = None
    - def WaitForCommandEnd():
    - with lock:
    - stdoutdata, stderrdata = proc.communicate()
    - returncode = proc.returncode
    - if returncode == 0:
    - GetPLCObjectSingleton().LogMessage(
    - LogLevelsDict["INFO"],
    - "LPC MQTT {name} command success: "+stdoutdata)
    - else:
    - GetPLCObjectSingleton().LogMessage(
    - LogLevelsDict["WARNING"],
    - "LPC MQTT {name} command error: rc="+str(returncode)+
    - " stdout: "+stdoutdata+
    - " stderr: "+stderrdata)
    + def WaitForCommandEnd():
    + stdoutdata, stderrdata = proc.communicate()
    + returncode = proc.returncode
    + _{location}_lock.release()
    + if returncode == 0:
    + GetPLCObjectSingleton().LogMessage(
    + LogLevelsDict["INFO"],
    + "LPC MQTT {name} command success: "+stdoutdata)
    + else:
    + GetPLCObjectSingleton().LogMessage(
    + LogLevelsDict["WARNING"],
    + "LPC MQTT {name} command error: rc="+str(returncode)+
    + " stdout: "+stdoutdata+
    + " stderr: "+stderrdata)
    - stdout_thread = threading.Thread(target=WaitForCommandEnd)
    - stdout_thread.start()
    + stdout_thread = threading.Thread(target=WaitForCommandEnd)
    + stdout_thread.start()
    def _runtime_{location}_mqtt_start():
    GetPLCObjectSingleton().LogMessage(