Repository navigation
Communication SMB
SMB is the file sharing protocol of Windows, also provided by macOS, Samba on Linux and most NAS systems. With TinySMB (install it) your microcontroller can play the audio files of a shared folder directly - your music collection on the NAS, for example. See Communication for the general considerations, and FTP for FTP servers.
AudioSourceSMB (AudioTools/Disk/AudioSourceSMB.h) is an AudioSource for the AudioPlayer: it scans a directory of the share recursively and plays the files that match the extension, in the order in which the server lists them. From player-smb-audiokit.ino:
#include "WiFi.h"
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Disk/AudioSourceSMB.h"
WiFiClient wifi;
SMBClient smbClient(wifi);
AudioSourceSMB source(smbClient, "/Music", "mp3");
AudioBoardStream i2s(AudioKitEs8388V1);
MP3DecoderHelix decoder;
AudioPlayer player(source, i2s, decoder);
void setup() {
// ... connect WiFi
WiFi.setSleep(false);
// connect to \\192.168.1.39\share
if (!smbClient.begin("192.168.1.39", "share", "user", "password")) stop();
auto cfg = i2s.defaultConfig(TX_MODE);
i2s.begin(cfg);
player.begin();
}
void loop() { player.copy(); }Call smbClient.begin(host, share, user, password) before the player accesses the files. The file names are not kept in memory: the share is listed each time a new file is selected.
- The share must allow access with the user and password you provide (on Windows: a local user with read rights on the folder).
- See the TinySMB documentation for the supported SMB versions and for reading or writing single files.