#include #include #define PIN_BUTTON 37 int state_btn = HIGH; const char* wifi_ssid = "A6KE6K TEMP"; const char* wifi_password = "tempo8fi"; const char* mqtt_server = "172.24.1.22"; WiFiClient espClient; PubSubClient client(espClient); int count_sleep = 0; void setup() { pinMode(PIN_BUTTON,INPUT_PULLUP); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(wifi_ssid, wifi_password); Serial.print("Connecting to WiFi.."); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(1000); } Serial.println(""); Serial.println(WiFi.localIP()); client.setServer(mqtt_server, 1883); client.connect("esp32"); //client.setCallback(callback); } void loop() { // put your main code here, to run repeatedly: int state_new = digitalRead(PIN_BUTTON); if (state_btn && !state_new) { Serial.println("pressed"); client.publish("button_press","Bouton Presse"); } state_btn = state_new; delay(1); count_sleep++; if (count_sleep == 5000) { client.publish("esp32", "still connected"); count_sleep = 0; } }