The code below is using basic Webserver library and WiFiClient objects.
I need to convert it with AsyncTCP because ESPAsyncWebServer doesn't use WiFiClient objects.
how to convert the client.write in my case?
// In WiFiClient
public: size_t write(const uint8_t *buf, size_t size)
client->write can't be use
// Get access to the client object
WiFiClient client = server.client();
// Send the 200 OK response with the headers
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: audio/wav");
client.println("Access-Control-Allow-Origin: *");
client.println();
// Send the initial part of the WAV header
client.write(reinterpret_cast<const uint8_t*>(&wavHeader), sizeof(wavHeader));
uint8_t buffer[bufferSize];
uint32_t totalDataSize = 0; // Total size of audio data sent
while (client.connected()) { // Keep streaming as long as the client is connected
// Read audio data from I2S DMA
size_t bytesRead;
i2s_read(static_cast(i2sPortNumber), buffer, bufferSize, &bytesRead, portMAX_DELAY);
// Send audio data
if (bytesRead > 0) {
client.write(buffer, bytesRead);
totalDataSize += bytesRead;
}
The code below is using basic Webserver library and WiFiClient objects. I need to convert it with AsyncTCP because ESPAsyncWebServer doesn't use WiFiClient objects. how to convert the client.write in my case?
// In WiFiClient public: size_t write(const uint8_t *buf, size_t size)
client->write can't be use
// Get access to the client object WiFiClient client = server.client();
// Send the 200 OK response with the headers client.println("HTTP/1.1 200 OK"); client.println("Content-Type: audio/wav"); client.println("Access-Control-Allow-Origin: *"); client.println();
// Send the initial part of the WAV header client.write(reinterpret_cast<const uint8_t*>(&wavHeader), sizeof(wavHeader));
uint8_t buffer[bufferSize]; uint32_t totalDataSize = 0; // Total size of audio data sent
while (client.connected()) { // Keep streaming as long as the client is connected // Read audio data from I2S DMA size_t bytesRead; i2s_read(static_cast(i2sPortNumber), buffer, bufferSize, &bytesRead, portMAX_DELAY);
}
If anyone could help me that would be great.