start:arduino:esp32:now
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
start:arduino:esp32:now [2024/11/06 16:55] – [Code de l'émetteur] gerardadmin | start:arduino:esp32:now [2024/11/06 21:08] (Version actuelle) – [Tester et aller plus loin] gerardadmin | ||
---|---|---|---|
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:// | ||
+ | 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 < | #include < | ||
#include < | #include < | ||
- | // La variable qui sera envoyée au récepteur (nous générerons une valeur aléatoire pour l' | + | // Structure example to receive data |
- | float maValeurRecue; | + | // Must match the sender structure |
+ | typedef struct struct_message { | ||
+ | char a[32]; | ||
+ | int b; | ||
+ | | ||
+ | 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(& | + | |
+ | // callback function that will be executed when data is received | ||
+ | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { | ||
+ | memcpy(& | ||
Serial.print(" | Serial.print(" | ||
- | Serial.println(taille); | + | Serial.println(len); |
- | Serial.print(" | + | Serial.print(" |
- | Serial.println(maValeurRecue); | + | Serial.println(myData.a); |
+ | Serial.print(" | ||
+ | Serial.println(myData.b); | ||
+ | Serial.print(" | ||
+ | Serial.println(myData.c); | ||
+ | Serial.print(" | ||
+ | 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 | + | // Init ESP-NOW |
if (esp_now_init() != ESP_OK) { | if (esp_now_init() != ESP_OK) { | ||
- | Serial.println(" | + | Serial.println(" |
return; | return; | ||
} | } | ||
- | |||
- | // Si ESP-NOW a correctement démarré, il est temps d' | ||
- | 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() { | ||
- | | + | |
} | } | ||
+ | |||
</ | </ | ||
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:// | + | ===== Travaux pratique Esp32 Now ==== |
+ | [[start: | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/now.1730908549.txt.gz · Dernière modification : de gerardadmin