ESP32 Bluetooth Applications Multiples - Combiner Toutes les Applications Bluetooth dans un Projet Tutoriel

Aperçu

L'exemple d'applications Bluetooth multiples démontre comment combiner plusieurs interfaces d'applications Bluetooth dans un seul projet ESP32. Exécutez Monitor, Chat, Slider, Joystick, Temperature, Plotter, Table, Analog Gauge et Rotator toutes simultanément — accessibles via l'application DIYables Bluetooth STEM. Conçu pour les cartes ESP32 avec prise en charge de BLE (Bluetooth Low Energy) et des connexions Classic Bluetooth. C'est idéal pour les projets complexes nécessitant plusieurs interfaces de contrôle et d'affichage simultanément.

Cet exemple prend en charge deux modes Bluetooth :

  • ESP32 BLE (Bluetooth Low Energy) : Fonctionne sur Android et iOS
  • ESP32 Classic Bluetooth : Fonctionne sur Android uniquement. iOS ne prend pas en charge Classic Bluetooth. Utilisez BLE si vous avez besoin du support iOS.
ESP32 Bluetooth Applications Multiples - Combiner Toutes les Applications Bluetooth dans un Projet Tutoriel

Fonctionnalités

  • 9 Applications en Une : Monitor, Chat, Slider, Joystick, Temperature, Plotter, Table, Analog Gauge et Rotator fonctionnant simultanément
  • Callbacks Indépendants : Chaque application a ses propres gestionnaires d'événements
  • Timing Indépendant : Intervalles de mise à jour différents pour chaque application
  • Commutation d'Applications : Basculez librement entre les applications dans l'application mobile
  • BLE & Classic Bluetooth : Choisissez le mode Bluetooth qui convient à votre projet
  • Multi-plateforme : Le mode BLE fonctionne sur Android et iOS ; Classic Bluetooth fonctionne sur Android
  • Option Faible Consommation : Le mode BLE consomme moins d'énergie que Classic Bluetooth

Matériel Requis

1×Module de développement ESP32 ESP-WROOM-32
1×Alternativement: ESP32 Uno-form board
1×Alternativement: ESP32 S3 Uno-form board
1×Câble USB Type-C
1×Breadboard (plaque d'essai)
1×Fils de Connexion
1×Recommandé: Carte d'extension à bornier à vis pour ESP32
1×Recommandé: Breakout Expansion Board for ESP32
1×Recommandé: Répartiteur d'alimentation pour ESP32

Ou vous pouvez acheter les kits suivants:

1×Kit de Démarrage DIYables ESP32 (ESP32 inclus)
1×Kit de Capteurs DIYables (30 capteurs/écrans)
1×Kit de Capteurs DIYables (18 capteurs/écrans)
Divulgation : Certains des liens fournis dans cette section sont des liens affiliés Amazon. Nous pouvons recevoir une commission pour tout achat effectué via ces liens, sans coût supplémentaire pour vous. Nous vous remercions de votre soutien.

Code ESP32

Étapes Rapides

Suivez ces instructions étape par étape :

  • Si c'est votre première fois avec l'ESP32, consultez le tutoriel sur Installation du logiciel ESP32..
  • Connectez la carte ESP32 à votre ordinateur avec un câble USB.
  • Lancez l'Arduino IDE sur votre ordinateur.
  • Sélectionnez la carte ESP32 appropriée et le port COM.
  • Naviguez vers l'icône Libraries dans la barre de gauche d'Arduino IDE.
  • Recherchez "DIYables Bluetooth", puis trouvez la bibliothèque DIYables Bluetooth par DIYables
  • Cliquez sur le bouton Install pour installer la bibliothèque.
Bibliothèque ESP32 DIYables Bluetooth
  • Il vous sera demandé d'installer d'autres dépendances de bibliothèques
  • Cliquez sur le bouton Install All pour installer toutes les dépendances de bibliothèques.
Dépendance ESP32 DIYables Bluetooth

> Important : Puisque cet exemple inclut de nombreuses bibliothèques d'applications Bluetooth, le sketch compilé est plus volumineux que d'habitude. Vous devez sélectionner le schéma de partition correct (voir ci-dessous).

Choisissez l'un des deux modes Bluetooth ci-dessous selon vos besoins :

Code ESP32 Classic Bluetooth (fonctionne avec l'application sur Android uniquement)

Note : Classic Bluetooth n'est PAS pris en charge sur iOS. Si vous avez besoin du support iOS, utilisez le code BLE ci-dessous.

  • Dans Arduino IDE, allez à File Examples DIYables Bluetooth Esp32Bluetooth_MultipleApps exemple, ou copiez le code ci-dessus et collez-le dans l'éditeur d'Arduino IDE
/* * DIYables Bluetooth Library - ESP32 Classic Bluetooth Multiple Apps Example * Works with DIYables Bluetooth STEM app on Android * Note: Classic Bluetooth is NOT supported on iOS. Use BLE examples for iOS support. * * This example demonstrates how to use multiple Bluetooth apps simultaneously: * - Monitor: Real-time serial monitoring and logging * - Chat: Bi-directional text messaging * - Slider: Dual slider control (0-255 range) * - Joystick: Interactive joystick control (X, Y coordinates) * - Temperature: Temperature monitoring and display * - Plotter: Real-time data plotting (3 channels) * - Table: Two-column data table with real-time updates * - Analog Gauge: Circular gauge for sensor monitoring * - Rotator: Rotatable disc/knob control * - Pin Control: Digital pin control and monitoring * * Features: * - All apps run simultaneously on a single Bluetooth connection * - Automatic message routing to appropriate app handlers * - Simplified callback system - no manual parsing needed * - All Bluetooth protocol details handled by the library * - Compatible with DIYables Bluetooth Mobile App * * Compatible Boards: * - ESP32 (all variants with Classic Bluetooth) * - ESP32-WROOM-32 * - ESP32-DevKitC * - ESP32-WROVER * * Note: Select "Huge APP (3MB No OTA/1MB SPIFFS)" partition scheme * in Arduino IDE: Tools > Partition Scheme * * Setup: * 1. Upload the sketch to your ESP32 * 2. Open Serial Monitor (115200 baud) * 3. Open DIYables Bluetooth App on your phone * 4. Connect to "ESP32 Multi-App" * 5. Navigate to different screens to test each app * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothMonitor.h> #include <DIYables_BluetoothChat.h> #include <DIYables_BluetoothSlider.h> #include <DIYables_BluetoothJoystick.h> #include <DIYables_BluetoothTemperature.h> #include <DIYables_BluetoothPlotter.h> #include <DIYables_BluetoothTable.h> #include <DIYables_BluetoothAnalogGauge.h> #include <DIYables_BluetoothRotator.h> #include <platforms/DIYables_Esp32Bluetooth.h> // Create Bluetooth instances DIYables_Esp32Bluetooth bluetooth("ESP32 Multi-App"); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create app instances DIYables_BluetoothMonitor bluetoothMonitor; DIYables_BluetoothChat bluetoothChat; DIYables_BluetoothSlider bluetoothSlider(0, 255, 1); DIYables_BluetoothJoystick bluetoothJoystick(false, 5); DIYables_BluetoothTemperature bluetoothTemperature(-10.0, 50.0, "°C"); DIYables_BluetoothPlotter bluetoothPlotter; DIYables_BluetoothTable bluetoothTable; DIYables_BluetoothAnalogGauge bluetoothGauge(0.0, 100.0, "%"); DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_CONTINUOUS); // ESP32 built-in LED (may vary by board) const int LED_PIN = 2; // State variables int currentSlider1 = 128; int currentSlider2 = 64; int currentJoystickX = 0; int currentJoystickY = 0; float currentTemperature = 25.0; float currentGaugeValue = 50.0; float currentRotatorAngle = 0.0; int messageCount = 0; // Timing variables unsigned long lastMonitorUpdate = 0; unsigned long lastTempUpdate = 0; unsigned long lastPlotUpdate = 0; unsigned long lastTableUpdate = 0; unsigned long lastGaugeUpdate = 0; float plotPhase = 0; void setup() { Serial.begin(115200); delay(1000); Serial.println("DIYables Bluetooth - ESP32 Multiple Apps Example"); // Initialize built-in LED pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // Initialize Bluetooth server bluetoothServer.begin(); // Register all apps with the server bluetoothServer.addApp(&bluetoothMonitor); bluetoothServer.addApp(&bluetoothChat); bluetoothServer.addApp(&bluetoothSlider); bluetoothServer.addApp(&bluetoothJoystick); bluetoothServer.addApp(&bluetoothTemperature); bluetoothServer.addApp(&bluetoothPlotter); bluetoothServer.addApp(&bluetoothTable); bluetoothServer.addApp(&bluetoothGauge); bluetoothServer.addApp(&bluetoothRotator); Serial.print("Registered apps: "); Serial.println(bluetoothServer.getAppCount()); // Configure Plotter bluetoothPlotter.setPlotTitle("Sensor Data"); bluetoothPlotter.setAxisLabels("Time", "Value"); bluetoothPlotter.setYAxisRange(-1.5, 1.5); bluetoothPlotter.setMaxSamples(100); bluetoothPlotter.setLegendLabels("Sine", "Cosine", "Random"); // Configure Table rows bluetoothTable.addRow("Status"); bluetoothTable.addRow("Uptime"); bluetoothTable.addRow("Slider 1"); bluetoothTable.addRow("Slider 2"); bluetoothTable.addRow("Joystick X"); bluetoothTable.addRow("Joystick Y"); bluetoothTable.addRow("Temperature"); bluetoothTable.addRow("Gauge Value"); bluetoothTable.addRow("Rotator Angle"); bluetoothTable.addRow("Free Heap"); // Set up all callbacks setupCallbacks(); Serial.println("Waiting for Bluetooth connection..."); } void setupCallbacks() { // ---- Connection events ---- bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); digitalWrite(LED_PIN, HIGH); bluetoothMonitor.send("=== ESP32 Multi-App Connected ==="); bluetoothMonitor.send("All apps are ready!"); bluetoothChat.send("Hello! ESP32 Multi-App is connected."); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); digitalWrite(LED_PIN, LOW); }); // ---- Monitor callbacks ---- bluetoothMonitor.onMonitorMessage([](const String& message) { Serial.println("Monitor cmd: " + message); if (message == "HELP") { bluetoothMonitor.send("Commands: STATUS, HELP, LED_ON, LED_OFF, HEAP"); } else if (message == "STATUS") { bluetoothMonitor.send("Slider1=" + String(currentSlider1) + " Slider2=" + String(currentSlider2)); bluetoothMonitor.send("Joystick X=" + String(currentJoystickX) + " Y=" + String(currentJoystickY)); bluetoothMonitor.send("Temp=" + String(currentTemperature, 1) + "°C"); bluetoothMonitor.send("Gauge=" + String(currentGaugeValue, 1) + "%"); bluetoothMonitor.send("Rotator=" + String(currentRotatorAngle, 0) + "°"); } else if (message == "LED_ON") { digitalWrite(LED_PIN, HIGH); bluetoothMonitor.send("LED turned ON"); } else if (message == "LED_OFF") { digitalWrite(LED_PIN, LOW); bluetoothMonitor.send("LED turned OFF"); } else if (message == "HEAP") { bluetoothMonitor.send("Free Heap: " + String(ESP.getFreeHeap()) + " bytes"); } else { bluetoothMonitor.send("Unknown: " + message + " (type HELP)"); } }); // ---- Chat callbacks ---- bluetoothChat.onChatMessage([](const String& message) { Serial.println("Chat: " + message); bluetoothChat.send("Echo: " + message); if (message.equalsIgnoreCase("ping")) { bluetoothChat.send("pong!"); } else if (message.equalsIgnoreCase("status")) { bluetoothChat.send("Uptime: " + String(millis() / 1000) + "s, Apps: " + String(bluetoothServer.getAppCount())); } else if (message.equalsIgnoreCase("heap")) { bluetoothChat.send("Free heap: " + String(ESP.getFreeHeap()) + " bytes"); } }); // ---- Slider callbacks ---- bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; Serial.print("Slider 1: "); Serial.print(slider1); Serial.print(", Slider 2: "); Serial.println(slider2); // Update gauge based on slider 1 currentGaugeValue = map(slider1, 0, 255, 0, 100); bluetoothGauge.send(currentGaugeValue); // Update table bluetoothTable.sendValueUpdate("Slider 1", String(slider1)); bluetoothTable.sendValueUpdate("Slider 2", String(slider2)); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); }); bluetoothSlider.onGetConfig([]() { bluetoothSlider.send(currentSlider1, currentSlider2); }); // ---- Joystick callbacks ---- bluetoothJoystick.onJoystickValue([](int x, int y) { currentJoystickX = x; currentJoystickY = y; Serial.print("Joystick X: "); Serial.print(x); Serial.print(", Y: "); Serial.println(y); // Update table bluetoothTable.sendValueUpdate("Joystick X", String(x)); bluetoothTable.sendValueUpdate("Joystick Y", String(y)); }); bluetoothJoystick.onGetConfig([]() { bluetoothJoystick.send(currentJoystickX, currentJoystickY); }); // ---- Temperature callbacks ---- bluetoothTemperature.onTemperatureRequest([]() { bluetoothTemperature.send(currentTemperature); }); // ---- Plotter callbacks ---- bluetoothPlotter.onDataRequest([]() { Serial.println("Plotter data requested"); }); // ---- Table callbacks ---- bluetoothTable.onDataRequest([]() { Serial.println("Table data requested"); bluetoothTable.sendTableStructure(); updateAllTableValues(); }); // ---- Gauge callbacks ---- bluetoothGauge.onValueRequest([]() { bluetoothGauge.send(currentGaugeValue); }); // ---- Rotator callbacks ---- bluetoothRotator.onRotatorAngle([](float angle) { currentRotatorAngle = angle; Serial.print("Rotator: "); Serial.print(angle); Serial.println("°"); bluetoothTable.sendValueUpdate("Rotator Angle", String(angle, 0) + "°"); }); } void updateAllTableValues() { bluetoothTable.sendValueUpdate("Status", "Running"); unsigned long uptime = millis() / 1000; String uptimeStr; if (uptime >= 60) { uptimeStr = String(uptime / 60) + "m " + String(uptime % 60) + "s"; } else { uptimeStr = String(uptime) + "s"; } bluetoothTable.sendValueUpdate("Uptime", uptimeStr); bluetoothTable.sendValueUpdate("Slider 1", String(currentSlider1)); bluetoothTable.sendValueUpdate("Slider 2", String(currentSlider2)); bluetoothTable.sendValueUpdate("Joystick X", String(currentJoystickX)); bluetoothTable.sendValueUpdate("Joystick Y", String(currentJoystickY)); bluetoothTable.sendValueUpdate("Temperature", String(currentTemperature, 1) + " °C"); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); bluetoothTable.sendValueUpdate("Rotator Angle", String(currentRotatorAngle, 0) + "°"); bluetoothTable.sendValueUpdate("Free Heap", String(ESP.getFreeHeap()) + " bytes"); } void loop() { bluetoothServer.loop(); if (!bluetooth.isConnected()) { delay(10); return; } // ---- Monitor: periodic status every 5 seconds ---- if (millis() - lastMonitorUpdate >= 5000) { lastMonitorUpdate = millis(); messageCount++; bluetoothMonitor.send("[INFO] Heartbeat #" + String(messageCount) + " - Uptime: " + String(millis() / 1000) + "s"); } // ---- Temperature: update every 2 seconds ---- if (millis() - lastTempUpdate >= 2000) { lastTempUpdate = millis(); // Simulate temperature with slight variation static float tempOffset = 0; tempOffset += random(-10, 11) / 10.0; if (tempOffset > 5.0) tempOffset = 5.0; if (tempOffset < -5.0) tempOffset = -5.0; currentTemperature = 25.0 + tempOffset; bluetoothTemperature.send(currentTemperature); bluetoothTable.sendValueUpdate("Temperature", String(currentTemperature, 1) + " °C"); } // ---- Plotter: update every 100ms ---- if (millis() - lastPlotUpdate >= 100) { lastPlotUpdate = millis(); float sine = sin(plotPhase); float cosine = cos(plotPhase); float noise = random(-50, 51) / 100.0; bluetoothPlotter.send(sine, cosine, noise); plotPhase += 0.1; if (plotPhase > 2 * PI) plotPhase = 0; } // ---- Table: update uptime every 5 seconds ---- if (millis() - lastTableUpdate >= 5000) { lastTableUpdate = millis(); unsigned long uptime = millis() / 1000; String uptimeStr; if (uptime >= 60) { uptimeStr = String(uptime / 60) + "m " + String(uptime % 60) + "s"; } else { uptimeStr = String(uptime) + "s"; } bluetoothTable.sendValueUpdate("Uptime", uptimeStr); bluetoothTable.sendValueUpdate("Free Heap", String(ESP.getFreeHeap()) + " bytes"); } // ---- Gauge: simulate sensor every 3 seconds ---- if (millis() - lastGaugeUpdate >= 3000) { lastGaugeUpdate = millis(); float sensorValue = 50.0 + 30.0 * sin(millis() / 10000.0); currentGaugeValue = sensorValue; bluetoothGauge.send(currentGaugeValue); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); } delay(10); }
  • Important : Allez à Tools > Partition Scheme et sélectionnez "Huge APP (3MB No OTA/1MB SPIFFS)". Ceci est requis car l'exemple d'applications multiples utilise significativement plus d'espace flash.
  • Cliquez sur le bouton Upload dans Arduino IDE pour télécharger le code vers l'ESP32
  • Ouvrez le Serial Monitor
  • Vérifiez le résultat dans le Serial Monitor. Cela ressemble à ceci :
COM6
Send
DIYables Bluetooth - ESP32 Multiple Apps Example Waiting for Bluetooth connection...
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Code ESP32 BLE (fonctionne avec l'application sur Android et iOS)

  • Dans Arduino IDE, allez à File Examples DIYables Bluetooth Esp32BLE_MultipleApps exemple, ou copiez le code ci-dessus et collez-le dans l'éditeur d'Arduino IDE
/* * DIYables Bluetooth Library - ESP32 BLE Multiple Apps Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates how to use multiple Bluetooth apps simultaneously: * - Monitor, Chat, Slider, Joystick, Temperature, Plotter, * Table, Analog Gauge, Rotator * * Compatible Boards: * - ESP32-WROOM-32 * - ESP32-DevKitC * - ESP32-WROVER * - ESP32-S3 * - ESP32-C3 * - Any ESP32 board supporting BLE * * Note: Select "Huge APP (3MB No OTA/1MB SPIFFS)" partition scheme * in Arduino IDE: Tools > Partition Scheme * * Setup: * 1. Upload the sketch to your ESP32 * 2. Open Serial Monitor (115200 baud) * 3. Open DIYables Bluetooth App on your phone * 4. Connect to "ESP32BLE Multi-App" * 5. Navigate to different screens to test each app * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothMonitor.h> #include <DIYables_BluetoothChat.h> #include <DIYables_BluetoothSlider.h> #include <DIYables_BluetoothJoystick.h> #include <DIYables_BluetoothTemperature.h> #include <DIYables_BluetoothPlotter.h> #include <DIYables_BluetoothTable.h> #include <DIYables_BluetoothAnalogGauge.h> #include <DIYables_BluetoothRotator.h> #include <platforms/DIYables_Esp32BLE.h> // BLE Configuration const char* DEVICE_NAME = "ESP32BLE Multi-App"; const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214"; const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214"; const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214"; // Create Bluetooth instances DIYables_Esp32BLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create app instances DIYables_BluetoothMonitor bluetoothMonitor; DIYables_BluetoothChat bluetoothChat; DIYables_BluetoothSlider bluetoothSlider(0, 255, 1); DIYables_BluetoothJoystick bluetoothJoystick(false, 5); DIYables_BluetoothTemperature bluetoothTemperature(-10.0, 50.0, "°C"); DIYables_BluetoothPlotter bluetoothPlotter; DIYables_BluetoothTable bluetoothTable; DIYables_BluetoothAnalogGauge bluetoothGauge(0.0, 100.0, "%"); DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_CONTINUOUS); // State variables int currentSlider1 = 128; int currentSlider2 = 64; int currentJoystickX = 0; int currentJoystickY = 0; float currentTemperature = 25.0; float currentGaugeValue = 50.0; float currentRotatorAngle = 0.0; int messageCount = 0; // Timing variables unsigned long lastMonitorUpdate = 0; unsigned long lastTempUpdate = 0; unsigned long lastPlotUpdate = 0; unsigned long lastTableUpdate = 0; unsigned long lastGaugeUpdate = 0; float plotPhase = 0; void setup() { Serial.begin(115200); delay(1000); Serial.println("DIYables Bluetooth - ESP32 BLE Multiple Apps Example"); pinMode(2, OUTPUT); digitalWrite(2, LOW); bluetoothServer.begin(); bluetoothServer.addApp(&bluetoothMonitor); bluetoothServer.addApp(&bluetoothChat); bluetoothServer.addApp(&bluetoothSlider); bluetoothServer.addApp(&bluetoothJoystick); bluetoothServer.addApp(&bluetoothTemperature); bluetoothServer.addApp(&bluetoothPlotter); bluetoothServer.addApp(&bluetoothTable); bluetoothServer.addApp(&bluetoothGauge); bluetoothServer.addApp(&bluetoothRotator); Serial.print("Registered apps: "); Serial.println(bluetoothServer.getAppCount()); bluetoothPlotter.setPlotTitle("Sensor Data"); bluetoothPlotter.setAxisLabels("Time", "Value"); bluetoothPlotter.setYAxisRange(-1.5, 1.5); bluetoothPlotter.setMaxSamples(100); bluetoothPlotter.setLegendLabels("Sine", "Cosine", "Random"); bluetoothTable.addRow("Status"); bluetoothTable.addRow("Uptime"); bluetoothTable.addRow("Slider 1"); bluetoothTable.addRow("Slider 2"); bluetoothTable.addRow("Joystick X"); bluetoothTable.addRow("Joystick Y"); bluetoothTable.addRow("Temperature"); bluetoothTable.addRow("Gauge Value"); bluetoothTable.addRow("Rotator Angle"); bluetoothTable.addRow("Messages"); setupCallbacks(); Serial.println("Waiting for Bluetooth connection..."); } void setupCallbacks() { bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); digitalWrite(2, HIGH); bluetoothMonitor.send("=== ESP32 BLE Multi-App Connected ==="); bluetoothMonitor.send("All apps are ready!"); bluetoothChat.send("Hello! ESP32 BLE Multi-App is connected."); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); digitalWrite(2, LOW); }); bluetoothMonitor.onMonitorMessage([](const String& message) { Serial.println("Monitor cmd: " + message); if (message == "HELP") { bluetoothMonitor.send("Commands: STATUS, HELP, LED_ON, LED_OFF, HEAP"); } else if (message == "STATUS") { bluetoothMonitor.send("Slider1=" + String(currentSlider1) + " Slider2=" + String(currentSlider2)); bluetoothMonitor.send("Joystick X=" + String(currentJoystickX) + " Y=" + String(currentJoystickY)); bluetoothMonitor.send("Temp=" + String(currentTemperature, 1) + "°C"); bluetoothMonitor.send("Gauge=" + String(currentGaugeValue, 1) + "%"); bluetoothMonitor.send("Rotator=" + String(currentRotatorAngle, 0) + "°"); } else if (message == "LED_ON") { digitalWrite(2, HIGH); bluetoothMonitor.send("LED turned ON"); } else if (message == "LED_OFF") { digitalWrite(2, LOW); bluetoothMonitor.send("LED turned OFF"); } else if (message == "HEAP") { bluetoothMonitor.send("Free heap: " + String(ESP.getFreeHeap()) + " bytes"); } else { bluetoothMonitor.send("Unknown: " + message + " (type HELP)"); } }); bluetoothChat.onChatMessage([](const String& message) { Serial.println("Chat: " + message); bluetoothChat.send("Echo: " + message); if (message.equalsIgnoreCase("ping")) { bluetoothChat.send("pong!"); } else if (message.equalsIgnoreCase("status")) { bluetoothChat.send("Uptime: " + String(millis() / 1000) + "s, Apps: " + String(bluetoothServer.getAppCount())); } }); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; Serial.print("Slider 1: "); Serial.print(slider1); Serial.print(", Slider 2: "); Serial.println(slider2); currentGaugeValue = map(slider1, 0, 255, 0, 100); bluetoothGauge.send(currentGaugeValue); bluetoothTable.sendValueUpdate("Slider 1", String(slider1)); bluetoothTable.sendValueUpdate("Slider 2", String(slider2)); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); }); bluetoothSlider.onGetConfig([]() { bluetoothSlider.send(currentSlider1, currentSlider2); }); bluetoothJoystick.onJoystickValue([](int x, int y) { currentJoystickX = x; currentJoystickY = y; Serial.print("Joystick X: "); Serial.print(x); Serial.print(", Y: "); Serial.println(y); bluetoothTable.sendValueUpdate("Joystick X", String(x)); bluetoothTable.sendValueUpdate("Joystick Y", String(y)); }); bluetoothJoystick.onGetConfig([]() { bluetoothJoystick.send(currentJoystickX, currentJoystickY); }); bluetoothTemperature.onTemperatureRequest([]() { bluetoothTemperature.send(currentTemperature); }); bluetoothPlotter.onDataRequest([]() { Serial.println("Plotter data requested"); }); bluetoothTable.onDataRequest([]() { Serial.println("Table data requested"); bluetoothTable.sendTableStructure(); updateAllTableValues(); }); bluetoothGauge.onValueRequest([]() { bluetoothGauge.send(currentGaugeValue); }); bluetoothRotator.onRotatorAngle([](float angle) { currentRotatorAngle = angle; Serial.print("Rotator: "); Serial.print(angle); Serial.println("°"); bluetoothTable.sendValueUpdate("Rotator Angle", String(angle, 0) + "°"); }); } void updateAllTableValues() { bluetoothTable.sendValueUpdate("Status", "Running"); unsigned long uptime = millis() / 1000; String uptimeStr; if (uptime >= 60) { uptimeStr = String(uptime / 60) + "m " + String(uptime % 60) + "s"; } else { uptimeStr = String(uptime) + "s"; } bluetoothTable.sendValueUpdate("Uptime", uptimeStr); bluetoothTable.sendValueUpdate("Slider 1", String(currentSlider1)); bluetoothTable.sendValueUpdate("Slider 2", String(currentSlider2)); bluetoothTable.sendValueUpdate("Joystick X", String(currentJoystickX)); bluetoothTable.sendValueUpdate("Joystick Y", String(currentJoystickY)); bluetoothTable.sendValueUpdate("Temperature", String(currentTemperature, 1) + " °C"); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); bluetoothTable.sendValueUpdate("Rotator Angle", String(currentRotatorAngle, 0) + "°"); bluetoothTable.sendValueUpdate("Messages", String(messageCount)); } void loop() { bluetoothServer.loop(); if (!bluetooth.isConnected()) { delay(10); return; } if (millis() - lastMonitorUpdate >= 5000) { lastMonitorUpdate = millis(); messageCount++; bluetoothMonitor.send("[INFO] Heartbeat #" + String(messageCount) + " - Uptime: " + String(millis() / 1000) + "s"); } if (millis() - lastTempUpdate >= 2000) { lastTempUpdate = millis(); static float tempOffset = 0; tempOffset += random(-10, 11) / 10.0; if (tempOffset > 5.0) tempOffset = 5.0; if (tempOffset < -5.0) tempOffset = -5.0; currentTemperature = 25.0 + tempOffset; bluetoothTemperature.send(currentTemperature); bluetoothTable.sendValueUpdate("Temperature", String(currentTemperature, 1) + " °C"); } if (millis() - lastPlotUpdate >= 100) { lastPlotUpdate = millis(); float sine = sin(plotPhase); float cosine = cos(plotPhase); float noise = random(-50, 51) / 100.0; bluetoothPlotter.send(sine, cosine, noise); plotPhase += 0.1; if (plotPhase > 2 * PI) plotPhase = 0; } if (millis() - lastTableUpdate >= 5000) { lastTableUpdate = millis(); unsigned long uptime = millis() / 1000; String uptimeStr; if (uptime >= 60) { uptimeStr = String(uptime / 60) + "m " + String(uptime % 60) + "s"; } else { uptimeStr = String(uptime) + "s"; } bluetoothTable.sendValueUpdate("Uptime", uptimeStr); bluetoothTable.sendValueUpdate("Messages", String(messageCount)); } if (millis() - lastGaugeUpdate >= 3000) { lastGaugeUpdate = millis(); float sensorValue = 50.0 + 30.0 * sin(millis() / 10000.0); currentGaugeValue = sensorValue; bluetoothGauge.send(currentGaugeValue); bluetoothTable.sendValueUpdate("Gauge Value", String(currentGaugeValue, 1) + "%"); } delay(10); }
  • Important : Allez à Tools > Partition Scheme et sélectionnez "Huge APP (3MB No OTA/1MB SPIFFS)". Ceci est requis car l'exemple d'applications multiples utilise significativement plus d'espace flash.
  • Cliquez sur le bouton Upload dans Arduino IDE pour télécharger le code vers l'ESP32
  • Ouvrez le Serial Monitor
  • Vérifiez le résultat dans le Serial Monitor. Cela ressemble à ceci :
COM6
Send
DIYables Bluetooth - ESP32 BLE Multiple Apps Example Waiting for Bluetooth connection...
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Application Mobile

  • Installez l'application DIYables Bluetooth sur votre smartphone : Android | iOS
  • Si vous utilisez le code ESP32 Classic Bluetooth, vous devez appairer l'ESP32 avec votre téléphone Android avant d'ouvrir l'application :
    • Allez dans les Paramètres > Bluetooth de votre téléphone
    • Assurez-vous que le Bluetooth est activé
    • Votre téléphone recherchera les appareils disponibles
    • Trouvez et appuyez sur "ESP32 Multi-App" dans la liste des appareils disponibles
    • Confirmez la demande d'appairage (aucun PIN requis)
    • Attendez jusqu'à ce que cela affiche "Paired" sous le nom de l'appareil
  • Si vous utilisez le code ESP32 BLE, aucun appairage n'est nécessaire. Passez simplement à l'étape suivante.
  • Ouvrez l'application DIYables Bluetooth
  • Lors de la première ouverture de l'application, elle demandera des autorisations. Veuillez accorder les autorisations suivantes :
    • Autorisation Appareils à proximité (Android 12+) / autorisation Bluetooth (iOS) - requis pour scanner et se connecter aux appareils Bluetooth
    • Autorisation de localisation (Android 11 et antérieurs uniquement) - requis par les anciennes versions Android pour scanner les appareils BLE
  • Assurez-vous que le Bluetooth est activé sur votre téléphone
  • Sur l'écran d'accueil, appuyez sur le bouton Connect. L'application recherchera les appareils BLE et Classic Bluetooth.
Application DIYables Bluetooth - Écran d'accueil avec bouton de scan
  • Trouvez et appuyez sur votre appareil dans les résultats de scan pour vous connecter :
    • Pour Classic Bluetooth : appuyez sur "ESP32 Multi-App"
    • Pour BLE : appuyez sur "ESP32BLE Multi-App"
  • Une fois connecté, l'application revient automatiquement à l'écran d'accueil. L'écran d'accueil montre toutes les applications disponibles. Les 9 applications initialisées dans le code Arduino répondront et fonctionneront — les autres applications sur l'écran d'accueil apparaîtront mais ne fonctionneront pas avec ce sketch.
Application DIYables Bluetooth - Écran d'accueil avec applications multiples

Note : Vous pouvez appuyer sur l'icône des paramètres sur l'écran d'accueil pour masquer/afficher les applications sur l'écran d'accueil. Pour plus de détails, consultez le Manuel d'utilisation de l'application DIYables Bluetooth.

  • Appuyez sur certaines des applications suivantes pour les ouvrir et interagir avec l'ESP32 : Monitor, Chat, Slider, Joystick, Temperature, Plotter, Table, Analog Gauge, Rotator
  • Basculez librement entre les applications — elles partagent toutes la même connexion Bluetooth

Maintenant regardez le Serial Monitor dans Arduino IDE. Vous verrez :

COM6
Send
Bluetooth connected! Monitor: Uptime: 5s | Free heap: 245780 bytes Temperature: 25.3°C Plotter values sent Table values updated Gauge value: 50.0
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Personnalisation Créative - Adaptez le Code à Votre Projet

Comment Fonctionnent les Applications Multiples

Chaque application est créée comme un objet séparé et enregistrée avec le même serveur Bluetooth. Elles partagent la connexion Bluetooth unique mais fonctionnent indépendamment :

// Include all app headers #include <DIYables_BluetoothMonitor.h> #include <DIYables_BluetoothChat.h> #include <DIYables_BluetoothSlider.h> #include <DIYables_BluetoothJoystick.h> #include <DIYables_BluetoothTemperature.h> #include <DIYables_BluetoothPlotter.h> #include <DIYables_BluetoothTable.h> #include <DIYables_BluetoothAnalogGauge.h> #include <DIYables_BluetoothRotator.h> // Create app instances DIYables_BluetoothMonitor bluetoothMonitor; DIYables_BluetoothChat bluetoothChat; DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); DIYables_BluetoothJoystick bluetoothJoystick; DIYables_BluetoothTemperature bluetoothTemperature(-10.0, 50.0, "°C"); DIYables_BluetoothPlotter bluetoothPlotter; DIYables_BluetoothTable bluetoothTable; DIYables_BluetoothAnalogGauge bluetoothGauge(0.0, 100.0, "km/h"); DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_LIMITED, 0, 180); // Register all apps with the Bluetooth server bluetoothServer.addApp(bluetoothMonitor); bluetoothServer.addApp(bluetoothChat); bluetoothServer.addApp(bluetoothSlider); bluetoothServer.addApp(bluetoothJoystick); bluetoothServer.addApp(bluetoothTemperature); bluetoothServer.addApp(bluetoothPlotter); bluetoothServer.addApp(bluetoothTable); bluetoothServer.addApp(bluetoothGauge); bluetoothServer.addApp(bluetoothRotator);

Configuration des Callbacks pour Chaque Application

Chaque application a ses propres gestionnaires d'événements :

void setup() { // Monitor - receives text commands bluetoothMonitor.onMonitorMessage([](String message) { Serial.println("Monitor received: " + message); }); // Chat - two-way messaging bluetoothChat.onChatMessage([](String message) { Serial.println("Chat: " + message); bluetoothChat.send("Echo: " + message); }); // Slider - value changes bluetoothSlider.onSliderValue([](int slider1, int slider2) { Serial.println("Slider: " + String(slider1)); }); // Joystick - directional input bluetoothJoystick.onJoystickValue([](int x, int y) { Serial.println("Joystick: X=" + String(x) + " Y=" + String(y)); }); // Rotator - angle changes bluetoothRotator.onRotatorAngle([](float angle) { Serial.println("Rotator: " + String(angle) + "°"); }); }

Intervalles de Mise à Jour Indépendants

Chaque application peut avoir son propre timing de mise à jour :

void loop() { bluetoothServer.loop(); unsigned long now = millis(); // Monitor: every 5 seconds static unsigned long lastMonitor = 0; if (now - lastMonitor >= 5000) { lastMonitor = now; bluetoothMonitor.send("Uptime: " + String(now / 1000) + "s"); } // Temperature: every 2 seconds static unsigned long lastTemp = 0; if (now - lastTemp >= 2000) { lastTemp = now; bluetoothTemperature.send(readTemperature()); } // Plotter: every 100ms (fast updates for smooth graph) static unsigned long lastPlotter = 0; if (now - lastPlotter >= 100) { lastPlotter = now; bluetoothPlotter.send(readSensorValue()); } // Table: every 5 seconds static unsigned long lastTable = 0; if (now - lastTable >= 5000) { lastTable = now; updateTableValues(); } // Gauge: every 3 seconds static unsigned long lastGauge = 0; if (now - lastGauge >= 3000) { lastGauge = now; bluetoothGauge.send(readGaugeValue()); } delay(10); }

Choisir les Applications à Inclure

Vous n'êtes pas obligé d'inclure les 9 applications. Choisissez seulement celles dont vous avez besoin :

// Example: Only Monitor + Slider + Temperature #include <DIYables_BluetoothMonitor.h> #include <DIYables_BluetoothSlider.h> #include <DIYables_BluetoothTemperature.h> DIYables_BluetoothMonitor bluetoothMonitor; DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); DIYables_BluetoothTemperature bluetoothTemperature(-10.0, 50.0, "°C"); void setup() { // ... Bluetooth server setup ... bluetoothServer.addApp(bluetoothMonitor); bluetoothServer.addApp(bluetoothSlider); bluetoothServer.addApp(bluetoothTemperature); // Only these 3 apps will appear in the mobile app }

Gérer les Événements de Connexion

bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send initial values for all apps bluetoothTemperature.send(currentTemperature); bluetoothGauge.send(currentGaugeValue); bluetoothRotator.send(currentAngle); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); });

Comment Utiliser les Applications Multiples

Commutation d'Applications

Dans l'application DIYables Bluetooth :

  • L'écran d'accueil montre toutes les applications enregistrées sous forme de boutons
  • Appuyez sur n'importe quelle application pour l'ouvrir
  • Utilisez le bouton retour ou le bouton home pour revenir et basculer vers une autre application
  • Toutes les applications continuent de fonctionner sur l'ESP32 peu importe quelle application est affichée

Flux de Données

  • Applications d'Entrée (Slider, Joystick, Rotator, Chat) : Envoient des données du téléphone vers l'ESP32
  • Applications de Sortie (Monitor, Temperature, Plotter, Table, Gauge) : Envoient des données de l'ESP32 vers le téléphone
  • Applications Bidirectionnelles (Chat, Monitor) : Peuvent envoyer et recevoir des données

Exemples de Programmation

Tableau de Bord Station Météo

// Temperature gauge for main reading DIYables_BluetoothTemperature bluetoothTemperature(-10.0, 50.0, "°C"); // Table for all sensor data DIYables_BluetoothTable bluetoothTable; // Plotter for trend visualization DIYables_BluetoothPlotter bluetoothPlotter; // Monitor for log messages DIYables_BluetoothMonitor bluetoothMonitor; void setup() { // ... Bluetooth setup ... bluetoothTable.addRow("Temperature"); bluetoothTable.addRow("Humidity"); bluetoothTable.addRow("Pressure"); bluetoothTable.addRow("Wind Speed"); bluetoothTable.addRow("Rain"); bluetoothPlotter.setPlotTitle("Weather Trends"); bluetoothPlotter.setLegendLabels("Temp", "Humidity", "Pressure"); } void loop() { bluetoothServer.loop(); static unsigned long lastUpdate = 0; if (millis() - lastUpdate >= 2000) { lastUpdate = millis(); float temp = readTemperature(); float hum = readHumidity(); float press = readPressure(); // Temperature gauge bluetoothTemperature.send(temp); // Table update bluetoothTable.sendValueUpdate("Temperature", String(temp, 1) + " °C"); bluetoothTable.sendValueUpdate("Humidity", String(hum, 0) + "%"); bluetoothTable.sendValueUpdate("Pressure", String(press, 0) + " hPa"); // Plotter bluetoothPlotter.send(temp, hum, press / 10.0); // Monitor log bluetoothMonitor.send("Weather update: " + String(temp, 1) + "°C, " + String(hum, 0) + "%, " + String(press, 0) + "hPa"); } delay(10); }

Contrôleur de Robot

// Joystick for movement DIYables_BluetoothJoystick bluetoothJoystick; // Slider for speed limit DIYables_BluetoothSlider bluetoothSlider(0, 100, 5); // Rotator for arm/turret angle DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_LIMITED, 0, 180); // Monitor for status feedback DIYables_BluetoothMonitor bluetoothMonitor; // Gauge for battery level DIYables_BluetoothAnalogGauge bluetoothGauge(0.0, 100.0, "%"); int maxSpeed = 50; void setup() { // ... Bluetooth setup ... bluetoothSlider.onSliderValue([](int slider1, int slider2) { maxSpeed = slider1; bluetoothMonitor.send("Max speed set to: " + String(maxSpeed) + "%"); }); bluetoothJoystick.onJoystickValue([](int x, int y) { int leftMotor = constrain(y + x, -maxSpeed, maxSpeed); int rightMotor = constrain(y - x, -maxSpeed, maxSpeed); setMotors(leftMotor, rightMotor); bluetoothMonitor.send("Motors: L=" + String(leftMotor) + " R=" + String(rightMotor)); }); bluetoothRotator.onRotatorAngle([](float angle) { setArmAngle((int)angle); bluetoothMonitor.send("Arm angle: " + String((int)angle) + "°"); }); } void loop() { bluetoothServer.loop(); // Update battery level every 10 seconds static unsigned long lastBattery = 0; if (millis() - lastBattery >= 10000) { lastBattery = millis(); float battery = readBatteryLevel(); bluetoothGauge.send(battery); } delay(10); }

Hub Domotique

// Chat for voice/text commands DIYables_BluetoothChat bluetoothChat; // Slider for dimmer/thermostat DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); // Table for device status DIYables_BluetoothTable bluetoothTable; // Temperature for room temp DIYables_BluetoothTemperature bluetoothTemperature(10.0, 40.0, "°C"); // Monitor for activity log DIYables_BluetoothMonitor bluetoothMonitor; void setup() { // ... Bluetooth setup ... bluetoothTable.addRow("Living Room Light"); bluetoothTable.addRow("Bedroom Light"); bluetoothTable.addRow("AC Status"); bluetoothTable.addRow("Door Lock"); bluetoothTable.addRow("Security"); bluetoothChat.onChatMessage([](String message) { message.toLowerCase(); if (message == "lights on") { setLights(true); bluetoothChat.send("Lights turned ON"); bluetoothTable.sendValueUpdate("Living Room Light", "ON ?"); } else if (message == "lights off") { setLights(false); bluetoothChat.send("Lights turned OFF"); bluetoothTable.sendValueUpdate("Living Room Light", "OFF ?"); } else if (message == "status") { bluetoothChat.send("Temp: " + String(readTemperature(), 1) + "°C"); bluetoothChat.send("All systems normal"); } bluetoothMonitor.send("[CMD] " + message); }); bluetoothSlider.onSliderValue([](int slider1, int slider2) { setDimmer(slider1); bluetoothMonitor.send("[DIMMER] Set to " + String(slider1) + "%"); }); }

Techniques de Programmation Avancées

Communication Inter-Applications

Utilisez les données d'une application pour mettre à jour une autre :

// Joystick controls movement, plotter shows trajectory float posX = 0, posY = 0; bluetoothJoystick.onJoystickValue([](int x, int y) { posX += x * 0.1; posY += y * 0.1; // Plot position on plotter bluetoothPlotter.send(posX, posY); // Show on table bluetoothTable.sendValueUpdate("Position X", String(posX, 1)); bluetoothTable.sendValueUpdate("Position Y", String(posY, 1)); // Log in monitor bluetoothMonitor.send("Pos: (" + String(posX, 1) + ", " + String(posY, 1) + ")"); });

Multi-Applications Optimisées en Mémoire

Lorsque la mémoire est limitée, partagez les variables entre les applications :

// Shared sensor data struct SensorData { float temperature; float humidity; float pressure; unsigned long lastUpdate; } sensorData; void readAllSensors() { sensorData.temperature = readTemperature(); sensorData.humidity = readHumidity(); sensorData.pressure = readPressure(); sensorData.lastUpdate = millis(); } void updateAllApps() { readAllSensors(); // Temperature gauge bluetoothTemperature.send(sensorData.temperature); // Table bluetoothTable.sendValueUpdate("Temperature", String(sensorData.temperature, 1) + " °C"); bluetoothTable.sendValueUpdate("Humidity", String(sensorData.humidity, 0) + "%"); // Plotter bluetoothPlotter.send(sensorData.temperature, sensorData.humidity); // Gauge (pressure) bluetoothGauge.send(sensorData.pressure); // Monitor bluetoothMonitor.send("Sensors updated at " + String(sensorData.lastUpdate / 1000) + "s"); }

BLE vs Classic Bluetooth - Lequel Choisir ?

FonctionnalitéBLE (Esp32BLE_MultipleApps)Classic Bluetooth (Esp32Bluetooth_MultipleApps)
Support iOS✅ Oui❌ Non
Support Android✅ Oui✅ Oui
ConsommationFaiblePlus élevée
Portée~30-100m~10-100m
Débit de DonnéesPlus faiblePlus élevé
Appairage RequisNon (auto-connexion)Oui (appairage manuel)
Idéal PourAlimenté par batterie, multi-plateformeHaut débit, Android uniquement

> Note pour les Applications Multiples : Puisque les applications multiples envoient des données simultanément, le débit plus élevé de Classic Bluetooth peut être bénéfique si vous avez de nombreuses applications à mise à jour rapide (par ex. plotter à 100ms). Pour les projets alimentés par batterie, BLE est toujours recommandé.

Dépannage

Problèmes Courants

1. Impossible de trouver l'appareil dans l'application

  • Assurez-vous que l'ESP32 est alimenté et le sketch téléchargé
  • Pour BLE : Assurez-vous que le Bluetooth et la Localisation de votre téléphone sont activés
  • Pour Classic Bluetooth : Appairez d'abord l'appareil dans les paramètres Bluetooth du téléphone
  • Vérifiez que le schéma de partition correct est sélectionné (Huge APP) — c'est critique pour les exemples multi-applications

2. Sketch trop volumineux / pas assez d'espace

  • Dans Arduino IDE, allez à Tools > Partition Scheme et sélectionnez "Huge APP (3MB No OTA/1MB SPIFFS)" ou "No OTA (Large APP)"
  • Le schéma de partition par défaut fournit seulement ~1,2MB pour le code de l'application, ce qui n'est pas suffisant pour l'exemple multi-applications
  • Ce paramètre donne ~3MB en sacrifiant la partition OTA (mise à jour par liaison radio)
  • Si c'est encore trop volumineux, supprimez les applications dont vous n'avez pas besoin

3. Certaines applications n'apparaissent pas dans l'application mobile

  • Assurez-vous que chaque application est enregistrée avec bluetoothServer.addApp()
  • Vérifiez que les en-têtes include correspondent aux objets d'applications créés
  • Vérifiez que toutes les applications sont enregistrées avant bluetoothServer.begin()

4. Les mises à jour de données sont lentes ou retardées

  • Réduisez le nombre d'applications envoyant des données simultanément
  • Augmentez les intervalles de mise à jour pour les applications moins critiques
  • BLE a une bande passante limitée — échelonnez les mises à jour dans le temps

5. L'ESP32 plante ou redémarre

  • Vérifiez la mémoire heap disponible avec ESP.getFreeHeap()
  • Réduisez le nombre de lignes de tableau ou d'échantillons de traceur
  • Assurez-vous que l'alimentation est adéquate (USB 3.0 ou alimentation externe)

6. La connexion se coupe fréquemment

  • Rapprochez-vous de l'ESP32 (réduisez la distance)
  • Réduisez la quantité totale de données envoyées
  • Échelonnez les intervalles de mise à jour pour que les applications n'envoient pas toutes en même temps

Conseils de débogage

Surveillez la mémoire et les performances :

void debugMultiApp() { Serial.println("=== Multi-App Debug ==="); Serial.println("Free Heap: " + String(ESP.getFreeHeap()) + " bytes"); Serial.println("Min Free Heap: " + String(ESP.getMinFreeHeap()) + " bytes"); Serial.println("Uptime: " + String(millis() / 1000) + "s"); Serial.println("======================="); } // Call periodically in loop static unsigned long lastDebug = 0; if (millis() - lastDebug >= 30000) { lastDebug = millis(); debugMultiApp(); }

Idées de projets

Tableaux de bord complets

  • Station météo (Température + Tableau + Traceur + Moniteur)
  • Tableau de bord de véhicule (Jauge + Rotateur + Traceur + Moniteur)
  • Hub domotique (Chat + Curseur + Tableau + Moniteur)
  • Panneau d'instruments de laboratoire (Température + Jauge + Traceur + Tableau)

Systèmes de contrôle à distance

  • Contrôleur de robot (Joystick + Curseur + Rotateur + Moniteur + Jauge)
  • Station au sol de drone (Joystick + Tableau + Traceur + Jauge)
  • Interface de machine CNC (Curseur + Rotateur + Moniteur + Tableau)
  • Contrôle de cardan de caméra (Joystick + Rotateur + Moniteur)

Projets éducatifs

  • Laboratoire de physique (Traceur + Tableau + Température + Jauge + Moniteur)
  • Établi d'électronique (Jauge + Traceur + Tableau + Moniteur)
  • Sciences de l'environnement (Température + Traceur + Tableau + Moniteur)
  • Club de robotique (Joystick + Curseur + Rotateur + Moniteur + Chat)

Applications IoT

  • Serre intelligente (Température + Curseur + Tableau + Traceur + Moniteur)
  • Contrôleur d'aquarium (Température + Curseur + Tableau + Moniteur)
  • Suiveur solaire (Rotateur + Jauge + Traceur + Tableau)
  • Moniteur d'énergie (Jauge + Traceur + Tableau + Moniteur)

Prochaines étapes

Maintenant que vous maîtrisez la combinaison de plusieurs applications Bluetooth, vous avez tous les outils pour construire des projets ESP32 complexes avec des interfaces mobiles riches. Explorez chaque tutoriel d'application individuelle pour une connaissance approfondie de l'API :

  1. Moniteur Bluetooth - Moniteur série basé sur texte
  2. Chat Bluetooth - Messagerie bidirectionnelle
  3. Curseur Bluetooth - Contrôle des valeurs avec curseurs
  4. Joystick Bluetooth - Entrée directionnelle 2D
  5. Température Bluetooth - Affichage de jauge de température
  6. Traceur Bluetooth - Tracé de données en temps réel
  7. Tableau Bluetooth - Affichage de données structurées
  8. Jauge analogique Bluetooth - Affichage de compteur analogique
  9. Rotateur Bluetooth - Contrôle de bouton rotatif

Support

Pour une aide supplémentaire :

  • Consultez la documentation de référence API
  • Forums de la communauté Arduino

※ NOS MESSAGES

  • N'hésitez pas à partager le lien de ce tutoriel. Cependant, veuillez ne pas utiliser notre contenu sur d'autres sites web. Nous avons investi beaucoup d'efforts et de temps pour créer ce contenu, veuillez respecter notre travail !