import threading import time import os import paho.mqtt.client as mqtt from dotenv import load_dotenv import state # يحتوي على `singlas_state` # ------------------ Load .env ------------------ # load_dotenv(dotenv_path="keys.env") mqtt_broker = os.getenv("MQTT_BROKER") mqtt_port = int(os.getenv("MQTT_PORT")) MQTT_PARTOPIC_state = os.getenv("MQTT_PARTOPIC_state") MQTT_SUBTOPIC_reply = os.getenv("MQTT_SUBTOPIC_reply") MQTT_SUBTOPIC_msg = os.getenv("MQTT_SUBTOPIC_msg") def topic_msg(tl_id): return f"{MQTT_PARTOPIC_state}/{tl_id}/{MQTT_SUBTOPIC_msg}" def topic_rep(tl_id): return f"{MQTT_PARTOPIC_state}/{tl_id}/{MQTT_SUBTOPIC_reply}" # ------------------ Get state ------------------ # def get_State(tl_id): return state.singlas_state.get(tl_id, "FREE") def checked_ql(ql): max_queue_length = 16 # 15 # this is the maximum queue length for the road return int(ql)