Outils pour utilisateurs

Outils du site


start:arduino:esp32:now

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:esp32:now [2024/11/06 16:55] – [Code de l'émetteur] gerardadminstart:arduino:esp32:now [2024/11/06 21:08] (Version actuelle) – [Tester et aller plus loin] gerardadmin
Ligne 171: Ligne 171:
     Serial.println("Error sending the data");     Serial.println("Error sending the data");
   }   }
-  delay(10000);+  delay(10000);// envoie des données toutes les 10 secondes
 } }
  
Ligne 183: Ligne 183:
 <code c recepteur001.ino> <code c recepteur001.ino>
  
-// Inclure les librairies+/
 +  Rui Santos & Sara Santos - Random Nerd Tutorials 
 +  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/   
 +  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. 
 +  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 
 +*/ 
 #include <esp_now.h> #include <esp_now.h>
 #include <WiFi.h> #include <WiFi.h>
  
-// La variable qui sera envoyée au récepteur (nous générerons une valeur aléatoire pour l'exemple) +// Structure example to receive data 
-float maValeurRecue;+// Must match the sender structure 
 +typedef struct struct_message { 
 +    char a[32]; 
 +    int b; 
 +    float c; 
 +    bool d; 
 +} struct_message;
  
-// La fonction de rappel qui nous assurera de la bonne livraison du message +// Create a struct_message called myData 
-void quand_donnees_Recues(const uint8_t * mac, const uint8_t *data_reception, int taille) { +struct_message myData; 
-  memcpy(&maValeurRecuedata_reception, sizeof(maValeurRecue));+ 
 +// callback function that will be executed when data is received 
 +void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { 
 +  memcpy(&myDataincomingData, sizeof(myData));
   Serial.print("Bytes received: ");   Serial.print("Bytes received: ");
-  Serial.println(taille); +  Serial.println(len); 
-  Serial.print("valeur reçue: "); +  Serial.print("Char: "); 
-  Serial.println(maValeurRecue);+  Serial.println(myData.a); 
 +  Serial.print("Int: "); 
 +  Serial.println(myData.b); 
 +  Serial.print("Float: "); 
 +  Serial.println(myData.c); 
 +  Serial.print("Bool: "); 
 +  Serial.println(myData.d);
   Serial.println();   Serial.println();
 } }
    
 void setup() { void setup() {
-  // On initie la comm série à 115200 Bauds+  // Initialize Serial Monitor
   Serial.begin(115200);   Serial.begin(115200);
-  +   
-  // On démarre le Wifi en mode Station+  // Set device as a Wi-Fi Station
   WiFi.mode(WIFI_STA);   WiFi.mode(WIFI_STA);
  
-  // Puis on initialise ESP-NOW+  // Init ESP-NOW
   if (esp_now_init() != ESP_OK) {   if (esp_now_init() != ESP_OK) {
-    Serial.println("Erreur d'initialisation ESP-NOW");+    Serial.println("Error initializing ESP-NOW");
     return;     return;
   }   }
- 
-  // Si ESP-NOW a correctement démarré, il est temps d'enregistrer la fonction de rappel: 
-  esp_now_register_recv_cb(quand_donnees_Recues); 
      
 +  // Once ESPNow is successfully Init, we will register for recv CB to
 +  // get recv packer info
 +  esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
 } }
    
 void loop() { void loop() {
-  +
 } }
 +
  
 </code> </code>
Ligne 230: Ligne 252:
 Nous vous renvoyons aux exemples disponibles dans la bibliothèque Arduino pour aller plus loin ! Nous vous renvoyons aux exemples disponibles dans la bibliothèque Arduino pour aller plus loin !
  
-[[https://wiki-fablab.grandbesancon.fr/lib/exe/fetch.php?media=howto:arduino-esp:esp-now_programmes.zip|arduino-esp:esp-now_programmes.zip]]+===== Travaux pratique Esp32 Now ====
  
 +[[start:arduino:esp32:TP:now|Travaux pratique Esp32 Now]]
  
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/now.1730908516.txt.gz · Dernière modification : de gerardadmin