Hi everyone, I am working on a project where I have to save the mp3 file from custom API to sd card and after that play it using esp32 where I am using VS1053B Codec.
I have seen plenty of examples of internet radio which are playing audio through differrent web stations.
If anyone has solution for my problem, please let me know
Regards
Rajbir
#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>
const char* ssid = "MYACCESSPOINT";
const char* password = "MYPASSWORD";
//Your Domain name with URL path or IP address with path
String serverName = "MYAPI";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
String AUDIO_STRING ;
String AUDIO_STRING Arr[100];
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
AUDIO_STRING = httpGETRequest(serverName);
Serial.println(AUDIO_STRING );
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
String httpGETRequest(String serverName) {
WiFiClient client;
HTTPClient http;
String serverPath = serverName + "?MYAPIPATH";
// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
Basically I want to get the audio from My custom API and want to play on speaker using esp32.
but i am getting this string data but don't know how to convert it in playable audio.
1.zip (17.0 KB)
This is the audio file I want to convert.