63 lines
1.5 KiB
Python
Executable File
63 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
|
|
def read_env(path=".env"):
|
|
env = {}
|
|
p = Path(path)
|
|
|
|
for raw in p.read_text().splitlines():
|
|
line = raw.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
k, v = line.split("=", 1)
|
|
env[k.strip()] = v.strip().strip('"').strip("'")
|
|
|
|
return env
|
|
|
|
|
|
def load_machine_ids():
|
|
data = json.loads(Path("wise_nodes.json").read_text())
|
|
return [
|
|
n["machine_id"]
|
|
for n in data.get("nodes", [])
|
|
if n.get("enabled", True)
|
|
]
|
|
|
|
|
|
env = read_env()
|
|
|
|
mqtt_host = env.get("MQTT_HOST", "127.0.0.1")
|
|
mqtt_port = int(env.get("MQTT_PORT", "1883"))
|
|
mqtt_user = env.get("MQTT_USERNAME") or env.get("MQTT_USER")
|
|
mqtt_password = env.get("MQTT_PASSWORD")
|
|
|
|
tenant = env.get("TENANT", "ucepsa")
|
|
site = env.get("SITE", "ucepsa_onpremise")
|
|
vertical = env.get("VERTICAL", "edge_oee")
|
|
|
|
client = mqtt.Client(client_id="clear_order_state_retained")
|
|
|
|
if mqtt_user:
|
|
client.username_pw_set(mqtt_user, mqtt_password)
|
|
|
|
client.connect(mqtt_host, mqtt_port, 60)
|
|
client.loop_start()
|
|
|
|
for machine_id in load_machine_ids():
|
|
topic = f"vertical/{tenant}/{site}/{vertical}/order_state/{machine_id}"
|
|
|
|
# Payload vacío + retain=True borra el mensaje retenido del broker.
|
|
info = client.publish(topic, payload=b"", qos=0, retain=True)
|
|
info.wait_for_publish(timeout=5)
|
|
|
|
print(f"Retained eliminado: {topic}")
|
|
|
|
client.loop_stop()
|
|
client.disconnect()
|
|
|
|
print("OK: estados simulados de Odoo eliminados")
|