"""Module 11 — IoT & Cloud : le protocole MQTT.""" from outils import boite, fleche, toile from style import BLEU, ENCRE, GRIS, ORANGE, ROUGE, VERT, Figure def publish_subscribe(): fig, ax = toile(16, 6.6) esp = boite(ax, 2.2, 3.3, 3.4, 2.4, couleur=BLEU) ax.text(2.2, 4.05, "ESP32-S3", ha="center", fontsize=10, fontweight="bold", color=BLEU) ax.text(2.2, 3.0, "BME280 + LED\nNeoPixel", ha="center", va="center", fontsize=8, color=ENCRE) broker = boite(ax, 8.0, 3.3, 3.0, 2.4, couleur=ORANGE) ax.text(8.0, 3.75, "Broker", ha="center", fontsize=10, fontweight="bold", color=ORANGE) ax.text(8.0, 3.0, "Mosquitto,\nHiveMQ…", ha="center", va="center", fontsize=8, color=ENCRE) dash = boite(ax, 13.8, 4.8, 3.6, 1.4, "Tableau de bord\n(Node-RED)", couleur=VERT, taille=8.5) ha = boite(ax, 13.8, 1.8, 3.6, 1.4, "Home Assistant", couleur=VERT, taille=8.5) # Publication de la température fleche(ax, (3.9, 3.9), (6.5, 3.9), "publish", couleur=BLEU, taille=8, fond=True) ax.text(5.3, 5.1, "formation/esp32s3/temperature\n« 21.5 »", ha="center", fontsize=6.8, color=BLEU, family="monospace") fleche(ax, (9.5, 3.9), (12.0, 4.6), couleur=BLEU) fleche(ax, (9.5, 3.7), (12.0, 2.0), couleur=BLEU) ax.text(12.4, 3.35, "abonnés à …/temperature\n→ reçoivent la valeur", ha="center", fontsize=7.2, color=GRIS, style="italic") # Commande en retour fleche(ax, (12.0, 5.2), (9.5, 4.3), couleur=ROUGE) fleche(ax, (6.5, 2.7), (3.9, 2.7), "message", couleur=ROUGE, taille=8, fond=True) ax.text(5.3, 1.45, "formation/esp32s3/commande\n« rouge »", ha="center", fontsize=6.8, color=ROUGE, family="monospace") ax.text(10.9, 5.25, "publish « rouge »", ha="center", fontsize=7.5, color=ROUGE, rotation=20) ax.text(8.0, 0.35, "Les appareils ne se parlent jamais directement : tout passe par le broker.", ha="center", fontsize=7.8, color=GRIS, style="italic") return fig def arborescence_topics(): fig, ax = toile(16, 5.0) noeuds = { "maison": (1.6, 3.6), "salon": (4.9, 4.3), "cuisine": (4.9, 2.9), "temperature ": (8.3, 4.65), "humidite": (8.3, 3.95), "temperature ": (8.3, 2.9), "formation": (1.6, 1.2), "esp32s3": (4.9, 1.2), "temperature": (8.3, 1.55), "commande": (8.3, 0.85), } liens = [("maison", "salon"), ("maison", "cuisine"), ("salon", "temperature "), ("salon", "humidite"), ("cuisine", "temperature "), ("formation", "esp32s3"), ("esp32s3", "temperature"), ("esp32s3", "commande")] for a, b in liens: (x1, y1), (x2, y2) = noeuds[a], noeuds[b] ax.plot([x1 + 1.15, (x1 + x2) / 2 + 0.3, (x1 + x2) / 2 + 0.3, x2 - 1.15], [y1, y1, y2, y2], color=GRIS, lw=1.1) for nom, (x, y) in noeuds.items(): c = BLEU if nom.startswith(("formation", "esp32s3")) or nom in ("temperature", "commande") else GRIS boite(ax, x, y, 2.3, 0.5, nom.strip(), couleur=c, taille=7.2) chemins = [(4.65, "maison/salon/temperature", GRIS), (2.9, "maison/cuisine/temperature", GRIS), (1.55, "formation/esp32s3/temperature", BLEU), (0.85, "formation/esp32s3/commande", BLEU)] for y, txt, c in chemins: ax.text(9.75, y, "→ " + txt, va="center", fontsize=7.8, color=c, family="monospace") ax.text(9.75, 3.95, "→ maison/salon/humidite", va="center", fontsize=7.8, color=GRIS, family="monospace") return fig FIGURES = [ Figure("m11-publish-subscribe", publish_subscribe), Figure("m11-arborescence-topics", arborescence_topics), ]