from machine import Pin
from time import sleep
from umqtt.simple import MQTTClient

mqtt_broker = "votre_broker_mqtt"
mqtt_topic = "etat_de_led"
client = MQTTClient("esp32", mqtt_broker)

# Configuration du GPIO pour la LED
pin_led = Pin(2, Pin.OUT)  # Changer le numéro de pin selon votre configuration

def toggle_led(state):
    pin_led.value(state)
    if state == 1:
        client.publish(mqtt_topic, b"Le led est allume")
    else:
        client.publish(mqtt_topic, b"Le led est eteint")

while True:
    toggle_led(1)  # Allumer la LED
    sleep(1)
    toggle_led(0)  # Éteindre la LED
    sleep(1)