Outils pour utilisateurs

Outils du site


start:arduino:mqtt:esp32

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
start:arduino:mqtt:esp32 [2023/12/12 07:17] – [Utiliser le capteur DHT11 avec ESP32 et mqtt broker] gerardadminstart:arduino:mqtt:esp32 [2023/12/12 07:40] (Version actuelle) – [MQTT et ESP32] gerardadmin
Ligne 2: Ligne 2:
  
 [[https://letmeknow.fr/fr/blog/180-tuto-mqtt-sur-esp32--mosquitto|tuto-mqtt-sur-esp32--mosquitto]] [[https://letmeknow.fr/fr/blog/180-tuto-mqtt-sur-esp32--mosquitto|tuto-mqtt-sur-esp32--mosquitto]]
 +
 +[[https://randomnerdtutorials-com.translate.goog/esp32-mqtt-publish-subscribe-arduino-ide/?_x_tr_sl=auto&_x_tr_tl=fr&_x_tr_hl=fr|ESP32 MQTT – Publier et s'abonner avec l'IDE Arduino]]
  
  
Ligne 96: Ligne 98:
 void setup() { void setup() {
  
-  +    Serial.begin(115200); 
- +     
-Serial.begin(115200); +    dht.begin(); 
- +     
-dht.begin(); +    pinMode(hsensor1,INPUT); 
- +     
-pinMode(hsensor1,INPUT); +    WiFi.begin(ssid, password); 
- +     
-WiFi.begin(ssid, password); +    while (WiFi.status() != WL_CONNECTED) { 
- +     
-  +    delay(500); 
- +     
-while (WiFi.status() != WL_CONNECTED) { +    Serial.println("Connecting to WiFi.."); 
- +     
-delay(500); +    
- +     
-Serial.println("Connecting to WiFi.."); +    Serial.println("Connected to the WiFi network"); 
- +     
-+    client.setServer(mqttServer, mqttPort); 
- +     
-Serial.println("Connected to the WiFi network"); +    //client.setCallback(callback); 
- +     
-  +    while (!client.connected()) { 
- +     
-client.setServer(mqttServer, mqttPort); +    Serial.println("Connecting to MQTT..."); 
- +     
-//client.setCallback(callback); +    if (client.connect("ESP32Client", mqttUser, mqttPassword )) { 
- +     
-  +    Serial.println("connected"); 
- +     
-while (!client.connected()) { +    } else { 
- +     
-Serial.println("Connecting to MQTT..."); +    Serial.print("failed with state "); 
- +     
-  +    Serial.print(client.state()); 
- +     
-if (client.connect("ESP32Client", mqttUser, mqttPassword )) { +    delay(2000); 
- +     
-  +          
- +     
-Serial.println("connected"); +    
- +    
-  +
- +
-} else { +
- +
-  +
- +
-Serial.print("failed with state "); +
- +
-Serial.print(client.state()); +
- +
-delay(2000); +
- +
-  +
- +
-+
- +
-+
- +
-  +
 } }
  
Ligne 205: Ligne 187:
  
   client.loop();   client.loop();
- 
-  
- 
   long now = millis();   long now = millis();
  
Ligne 240: Ligne 219:
     Serial.print("la température est élevée");     Serial.print("la température est élevée");
  
-   client.publish("information", String("la température est élevée").c_str(), true); +    client.publish("information", String("la température est élevée").c_str(), true); 
- +   delay(500);
-   +
- +
-  delay(500);+
  
- }+       }
  
    Serial.print("Humidité:");    Serial.print("Humidité:");
/home/chanteri/www/fablab37110/data/attic/start/arduino/mqtt/esp32.1702361827.txt.gz · Dernière modification : 2023/12/12 07:17 de gerardadmin