Here is the relevant part of my code:
Code: Select all
void reader(void *pvParameters) {
uint64_t read_sum;
String for_send;
// The 4 high bits are the channel, and the data is inverted
uint16_t offset = (int)ADC_INPUT * 0x1000 + 0xFFF;
size_t bytes_read;
while (1) {
uint16_t buffer[2] = {0};
i2s_read(I2S_NUM_0, &buffer, sizeof(buffer), &bytes_read, 15);
//Serial.printf("%d %d %d\n", offset - buffer[0], offset - buffer[1],offset - buffer[2]);
if (bytes_read == sizeof(buffer)) {
read_sum = offset - buffer[0];
if (is_client == 1) {
for_send = int64String(read_sum);
webSocket.sendTXT(0, for_send);
}
} else {
Serial.println("buffer empty");
}
}
}
void setup() {
Serial.begin(115200);
// Initialize the I2S peripheral
i2sInit();
// Create a task that will read the data
xTaskCreatePinnedToCore(reader, "ADC_reader", 2048, NULL, 1, NULL, 0);
// Print our IP address
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Start WebSocket server and assign callback
webSocket.begin();
webSocket.onEvent(onWebSocketEvent);
}
void loop() {
// Look for and handle WebSocket data
webSocket.loop();
}
Is websocket the right protocol to use to send data very fast via wifi? The audio data is generating at 44100 samples * 12 bits per sample / 8 = 66150 bytes per second, that means the uploading speed must be higher than 66.150kb/s. I can accept some missing packages and latency if buffer is necessary, but what approach should I use on this sending data to computer part? Thanks