From f83465d78d4878b7baaddc3e98aa3f9d6caee038 Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Wed, 8 Nov 2023 13:59:31 +0100 Subject: [PATCH] ftp example --- .../ftp/ftp-client/ftp-client.ino | 53 +++++++++++++++++++ src/AudioTools/AudioStreams.h | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 examples/examples-communication/ftp/ftp-client/ftp-client.ino diff --git a/examples/examples-communication/ftp/ftp-client/ftp-client.ino b/examples/examples-communication/ftp/ftp-client/ftp-client.ino new file mode 100644 index 0000000000..81a07d58cf --- /dev/null +++ b/examples/examples-communication/ftp/ftp-client/ftp-client.ino @@ -0,0 +1,53 @@ +/** + * @file ftp-client.ino + * @author Phil Schatzmann + * @brief Receiving audio via FTP and writing to I2S of the AudioKit. + * Replace the userids, passwords and ip adresses with your own! + * @version 0.1 + * @date 2023-11-09 + * + * @copyright Copyright (c) 2023 + */ + +#include "WiFi.h" +#include "ArduinoFTPClient.h" // install https://github.com/pschatzmann/TinyFTPClient +#include "AudioTools.h" +#include "AudioCodecs/CodecMP3Helix.h" +#include "AudioLibs/AudioKit.h" + +WiFiClient cmd; +WiFiClient data; +FTPClient client(cmd, data); +FTPFile file; +AudioKitStream kit; // or replace with e.g. I2SStream +MP3DecoderHelix mp3; +EncodedAudioStream decoder(&kit, &mp3); +StreamCopy copier(decoder, file); + +void setup() { + Serial.begin(115200); + + // connect to WIFI + WiFi.begin("network name", "password"); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + // optional logging + FTPLogger::setOutput(Serial); + // FTPLogger::setLogLevel(LOG_DEBUG); + + // open connection + client.begin(IPAddress(192, 168, 1, 10), "user", "password"); + + // copy data from file + file = client.open("/data/music/Neil Young/After the Gold Rush/08 Birds.mp3"); + + // open output device + kit.begin(); + decoder.begin(); + +} + +void loop() { copier.copy(); } \ No newline at end of file diff --git a/src/AudioTools/AudioStreams.h b/src/AudioTools/AudioStreams.h index a143399c4b..a2566c674a 100644 --- a/src/AudioTools/AudioStreams.h +++ b/src/AudioTools/AudioStreams.h @@ -1374,7 +1374,7 @@ class Throttle : public AudioStream { uint64_t durationUsEff = micros() - start_time; uint64_t durationUsToBe = getDelayUs(sum_frames); int64_t waitUs = durationUsToBe - durationUsEff + cfg.correction_us; - LOGI("wait us: %ld", waitUs); + LOGI("wait us: %ld", (long) waitUs); if (waitUs > 0) { int64_t waitMs = waitUs / 1000; if (waitMs > 0) delay(waitMs);