Add support for UDP broadcast and multicast for ESP32-S2 and ESP32-C3 #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mdev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1723,10 +1723,23 @@ class AudioReactive : public Usermod { | |
| transmitData.FFT_Magnitude = my_magnitude; | ||
| transmitData.FFT_MajorPeak = FFT_MajorPeak; | ||
|
|
||
| #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) | ||
| // ESP32-S2 and ESP32-C3: Use broadcast like the working Python script | ||
| //DEBUGSR_PRINTLN("ESP32-S2/C3: Sending UDP broadcast packet (like Python script)"); | ||
| if (fftUdp.beginPacket(IPAddress(255, 255, 255, 255), audioSyncPort) != 0) { | ||
| fftUdp.write(reinterpret_cast<uint8_t *>(&transmitData), sizeof(transmitData)); | ||
| int result = fftUdp.endPacket(); | ||
| //DEBUGSR_PRINTF("UDP broadcast packet sent, result: %d\n", result); | ||
| } | ||
| #else | ||
| // Original ESP32 and other variants | ||
| //DEBUGSR_PRINTLN("ESP32: Sending multicast packet"); | ||
| if (fftUdp.beginMulticastPacket() != 0) { // beginMulticastPacket returns 0 in case of error | ||
| fftUdp.write(reinterpret_cast<uint8_t *>(&transmitData), sizeof(transmitData)); | ||
| fftUdp.endPacket(); | ||
| int result = fftUdp.endPacket(); | ||
| //DEBUGSR_PRINTF("Multicast packet sent, result: %d\n", result); | ||
| } | ||
| #endif | ||
|
|
||
| frameCounter++; | ||
| } // transmitAudioData() | ||
|
|
@@ -2165,11 +2178,19 @@ class AudioReactive : public Usermod { | |
| } | ||
|
|
||
| if ((audioSyncPort > 0) && (audioSyncEnabled > AUDIOSYNC_NONE)) { | ||
| #ifdef ARDUINO_ARCH_ESP32 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not necessary to remove this (see my other comment) |
||
| //DEBUGSR_PRINTF("Connecting UDP: port=%d, audioSyncEnabled=%d\n", audioSyncPort, audioSyncEnabled); | ||
| #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) | ||
| // ESP32-S2 and ESP32-C3 may have issues with beginMulticast() | ||
| // Use regular UDP connection instead | ||
| //DEBUGSR_PRINTLN("ESP32-S2/C3: Using regular UDP begin"); | ||
| udpSyncConnected = fftUdp.begin(audioSyncPort); | ||
| #elif defined(ARDUINO_ARCH_ESP32) | ||
| //DEBUGSR_PRINTLN("ESP32: Using multicast begin"); | ||
| udpSyncConnected = fftUdp.beginMulticast(IPAddress(239, 0, 0, 1), audioSyncPort); | ||
| #else | ||
| udpSyncConnected = fftUdp.beginMulticast(WiFi.localIP(), IPAddress(239, 0, 0, 1), audioSyncPort); | ||
| #endif | ||
| //DEBUGSR_PRINTF("UDP connection result: %s\n", udpSyncConnected ? "SUCCESS" : "FAILED"); | ||
| receivedFormat = 0; | ||
| if (udpSyncConnected) last_UDPTime = millis(); | ||
| if (apActive && !(WLED_CONNECTED)) { | ||
|
|
@@ -2395,13 +2416,14 @@ class AudioReactive : public Usermod { | |
| } | ||
| #endif | ||
|
|
||
| #ifdef ARDUINO_ARCH_ESP32 | ||
| #if defined(ARDUINO_ARCH_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is not necessary, because ARDUINO_ARCH_ESP32 is defined on all esp32 boads (not just on the classic esp32) |
||
| //UDP Microphone Sync - transmit mode | ||
| #if defined(WLEDMM_FASTPATH) | ||
| if ((audioSyncEnabled & AUDIOSYNC_SEND) && (haveNewFFTResult || (millis() - lastTime > 24))) { // fastpath: send data once results are ready, or each 25ms as fallback (max sampling time is 23ms) | ||
| #else | ||
| if ((audioSyncEnabled & AUDIOSYNC_SEND) && (millis() - lastTime > 20)) { // standard: send data each 20ms | ||
| #endif | ||
| //DEBUGSR_PRINTF("Calling transmitAudioData: audioSyncEnabled=%d, AUDIOSYNC_SEND=%d\n", audioSyncEnabled, AUDIOSYNC_SEND); | ||
| haveNewFFTResult = false; // reset notification | ||
| // Only run the transmit code IF we're in Transmit mode | ||
| transmitAudioData(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is "the working python script" ?