Skip to content

Commit 2a56dd3

Browse files
committed
copyAll example
1 parent f5b5f7c commit 2a56dd3

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @file streams-url-file.ino
3+
* @author Phil Schatzmann
4+
* @brief Demo how to download a file from the internet and store it to a file. The test was done with an AudioKit which requires
5+
* some specific pin settings
6+
* @version 0.1
7+
* @date 2022-09-09
8+
*
9+
* @copyright Copyright (c) 2022
10+
*
11+
*/
12+
#include "SD.h"
13+
#include "AudioTools.h"
14+
15+
#define PIN_AUDIO_KIT_SD_CARD_CS 13
16+
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
17+
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
18+
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
19+
20+
21+
const char *ssid = "SSID";
22+
const char *password = "password";
23+
URLStream url(ssid, password); // Music Stream
24+
StreamCopy copier; //(i2s, music, 1024); // copy music to i2s
25+
File file; // final output stream
26+
int retryCount = 5;
27+
28+
// Arduino Setup
29+
void setup(void) {
30+
Serial.begin(115200);
31+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
32+
33+
// define custom SPI pins
34+
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
35+
36+
// intialize SD
37+
if(!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)){
38+
LOGE("SD failed");
39+
return;
40+
}
41+
42+
// open music stream
43+
url.begin("https://pschatzmann.github.io/arduino-audio-tools/resources/audio-8000.raw");
44+
45+
// copy file
46+
file = SD.open("/audio-8000.raw", FILE_WRITE);
47+
copier.begin(file, url);
48+
copier.copyAll(retryCount);
49+
file.close();
50+
51+
file = SD.open("/audio-8000.raw");
52+
LOGI("file size: %d", file.size());
53+
}
54+
55+
void loop() {
56+
}

0 commit comments

Comments
 (0)