logging
This commit is contained in:
parent
2c343d98c7
commit
8d4d888957
@ -40,7 +40,7 @@ bool running = false;
|
|||||||
void audioStop() {
|
void audioStop() {
|
||||||
if (running) {
|
if (running) {
|
||||||
running = false;
|
running = false;
|
||||||
Serial.println("[STOP]");
|
Serial.println("[AUDIO ] STOP");
|
||||||
}
|
}
|
||||||
copyErrors = 0;
|
copyErrors = 0;
|
||||||
copier.end();
|
copier.end();
|
||||||
@ -55,12 +55,12 @@ void audioStop() {
|
|||||||
bool audioPlayInit(const Entry &entry) {
|
bool audioPlayInit(const Entry &entry) {
|
||||||
audioStop();
|
audioStop();
|
||||||
|
|
||||||
Serial.printf("[%s] %s\n", entry.type.c_str(), entry.url.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Start: %s\n", entry.type.c_str(), entry.url.c_str());
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
if (entry.type == "ICY" || entry.type == "SNAP") {
|
if (entry.type == "ICY" || entry.type == "SNAP") {
|
||||||
if (!isWifiConnected()) {
|
if (!isWifiConnected()) {
|
||||||
Serial.printf("[%s] WiFi not connected.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] WiFi not connected.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ bool audioPlayInit(const Entry &entry) {
|
|||||||
|
|
||||||
if (entry.type == "SD") {
|
if (entry.type == "SD") {
|
||||||
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
|
if (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
|
||||||
Serial.printf("[%s] Failed to mount SD-card.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to mount SD-card.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -79,13 +79,13 @@ bool audioPlayInit(const Entry &entry) {
|
|||||||
|
|
||||||
bool audioBeginMP3Stream(const Entry &entry, Stream &source) {
|
bool audioBeginMP3Stream(const Entry &entry, Stream &source) {
|
||||||
if (!mp3Decoder.begin()) {
|
if (!mp3Decoder.begin()) {
|
||||||
Serial.printf("[%s] Failed to start MP3DecoderHelix.", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to start MP3DecoderHelix.", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mp3Stream.begin()) {
|
if (!mp3Stream.begin()) {
|
||||||
Serial.printf("[%s] Failed to start EncodedAudioStream.", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to start EncodedAudioStream.", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ bool audioBeginMP3Stream(const Entry &entry, Stream &source) {
|
|||||||
copier.begin(mp3Stream, source);
|
copier.begin(mp3Stream, source);
|
||||||
|
|
||||||
if (copier.copy() == 0) {
|
if (copier.copy() == 0) {
|
||||||
Serial.printf("[%s] Failed to copy initial data.", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to copy initial data.", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ bool audioPlayICY(const Entry &entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!icy.begin(entry.url.c_str())) {
|
if (!icy.begin(entry.url.c_str())) {
|
||||||
Serial.printf("[%s] Failed to start ICYStream.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to start ICYStream.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -122,26 +122,26 @@ bool audioPlaySNAP(const Entry &entry) {
|
|||||||
|
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
if (!WiFiClass::hostByName(entry.url.c_str(), ip)) {
|
if (!WiFiClass::hostByName(entry.url.c_str(), ip)) {
|
||||||
Serial.printf("[%s] Failed to resolve host.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to resolve host.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
snap.setServerIP(ip);
|
snap.setServerIP(ip);
|
||||||
if (!snap.begin()) {
|
if (!snap.begin()) {
|
||||||
Serial.printf("[%s] Failed to connect.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to connect.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opusDecoder.begin()) {
|
if (!opusDecoder.begin()) {
|
||||||
Serial.printf("[%s] Failed to start OpusAudioDecoder.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to start OpusAudioDecoder.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!snap.doLoop()) {
|
if (!snap.doLoop()) {
|
||||||
Serial.printf("[%s] Failed to copy initial data.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to copy initial data.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -155,14 +155,14 @@ bool audioPlaySD(const Entry &entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!SD.exists(entry.url.c_str())) {
|
if (!SD.exists(entry.url.c_str())) {
|
||||||
Serial.printf("[%s] File not found.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] File not found.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
file = SD.open(entry.url.c_str(), FILE_READ);
|
file = SD.open(entry.url.c_str(), FILE_READ);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.printf("[%s] Failed to open file.\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] [%-4s] Failed to open file.\n", entry.type.c_str());
|
||||||
audioStop();
|
audioStop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -184,20 +184,20 @@ bool audioPlay(const Entry &entry) {
|
|||||||
if (entry.type == "SNAP") {
|
if (entry.type == "SNAP") {
|
||||||
return audioPlaySNAP(entry);
|
return audioPlaySNAP(entry);
|
||||||
}
|
}
|
||||||
Serial.printf("[ERROR] unknown type: %s\n", entry.type.c_str());
|
Serial.printf("[AUDIO ] Unknown type: %s\n", entry.type.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audioSetup() {
|
void audioSetup() {
|
||||||
AudioToolsLogger.setLogLevel(AudioToolsLogLevel::Error);
|
AudioToolsLogger.setLogLevel(AudioToolsLogLevel::Error);
|
||||||
Serial.println("Initializing board...");
|
Serial.println("[AUDIO ] Initializing board...");
|
||||||
board.begin();
|
board.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool audioLoop() {
|
bool audioLoop() {
|
||||||
audioVolume = max(0.0f, min(audioVolume, 1.0f));
|
audioVolume = max(0.0f, min(audioVolume, 1.0f));
|
||||||
if (abs(board.volume() - audioVolume) >= 0.01f) {
|
if (abs(board.volume() - audioVolume) >= 0.01f) {
|
||||||
Serial.println("writing new volume...");
|
Serial.printf("[AUDIO ] writing volume = %.2f\n", audioVolume);
|
||||||
board.setVolume(audioVolume);
|
board.setVolume(audioVolume);
|
||||||
}
|
}
|
||||||
board.setMute(audioMute);
|
board.setMute(audioMute);
|
||||||
@ -210,7 +210,7 @@ bool audioLoop() {
|
|||||||
if (copyErrors < 100) {
|
if (copyErrors < 100) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Serial.println("Stream ended!");
|
Serial.println("[AUDIO ] Stream ended!");
|
||||||
audioStop();
|
audioStop();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
16
src/http.cpp
16
src/http.cpp
@ -12,15 +12,15 @@ AsyncWebSocket ws("/ws");
|
|||||||
|
|
||||||
void onWebSocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, const AwsEventType type, void *arg, const uint8_t *data, const size_t len) {
|
void onWebSocketEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, const AwsEventType type, void *arg, const uint8_t *data, const size_t len) {
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
Serial.printf("[WEBSOCKET] Connected: %s\n", client->remoteIP().toString().c_str());
|
Serial.printf("[%-8s] Connected: %s\n", "WEBSOCKET", client->remoteIP().toString().c_str());
|
||||||
client->text(stateBuffer);
|
client->text(stateBuffer);
|
||||||
} else if (type == WS_EVT_DISCONNECT) {
|
} else if (type == WS_EVT_DISCONNECT) {
|
||||||
Serial.printf("[WEBSOCKET] Disconnected: %s\n", client->remoteIP().toString().c_str());
|
Serial.printf("[%-8s] Disconnected: %s\n", "WEBSOCKET", client->remoteIP().toString().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void httpSetup() {
|
void httpSetup() {
|
||||||
Serial.println("Starting HTTP server");
|
Serial.println("[HTTP ] Starting HTTP server");
|
||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) {
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
const auto path = request->url();
|
const auto path = request->url();
|
||||||
@ -31,41 +31,51 @@ void httpSetup() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
server.on("/state", [](AsyncWebServerRequest *request) {
|
server.on("/state", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
request->send(200, "application/json", stateBuffer);
|
request->send(200, "application/json", stateBuffer);
|
||||||
});
|
});
|
||||||
server.on("/stop", [](AsyncWebServerRequest *request) {
|
server.on("/stop", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
playerState = PLAYER_STOP;
|
playerState = PLAYER_STOP;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/play", [](AsyncWebServerRequest *request) {
|
server.on("/play", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
playerState = PLAYER_PLAY;
|
playerState = PLAYER_PLAY;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/pause", [](AsyncWebServerRequest *request) {
|
server.on("/pause", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
playerState = PLAYER_PAUSE;
|
playerState = PLAYER_PAUSE;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/mute", [](AsyncWebServerRequest *request) {
|
server.on("/mute", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
audioMute = true;
|
audioMute = true;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/unmute", [](AsyncWebServerRequest *request) {
|
server.on("/unmute", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
audioMute = false;
|
audioMute = false;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/up", [](AsyncWebServerRequest *request) {
|
server.on("/up", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
audioVolume = max(0.0f, min(audioVolume + 0.05f, 1.0f));
|
audioVolume = max(0.0f, min(audioVolume + 0.05f, 1.0f));
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/down", [](AsyncWebServerRequest *request) {
|
server.on("/down", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
audioVolume = max(0.0f, min(audioVolume - 0.05f, 1.0f));
|
audioVolume = max(0.0f, min(audioVolume - 0.05f, 1.0f));
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/next", [](AsyncWebServerRequest *request) {
|
server.on("/next", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
playerSkip += 1;
|
playerSkip += 1;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
server.on("/back", [](AsyncWebServerRequest *request) {
|
server.on("/back", [](AsyncWebServerRequest *request) {
|
||||||
|
Serial.println("[HTTP ] " + request->url());
|
||||||
playerSkip -= 1;
|
playerSkip -= 1;
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -29,7 +29,7 @@ void playlistClear() {
|
|||||||
|
|
||||||
void playlistAdd(String entry) {
|
void playlistAdd(String entry) {
|
||||||
entry.trim();
|
entry.trim();
|
||||||
Serial.println("[PLAYLIST] add: " + entry);
|
Serial.println("[PLAYLIST] [ADD] " + entry);
|
||||||
|
|
||||||
const auto index_type_url = entry.indexOf('|');
|
const auto index_type_url = entry.indexOf('|');
|
||||||
if (index_type_url < 0) {
|
if (index_type_url < 0) {
|
||||||
|
|||||||
@ -12,21 +12,21 @@ void wifiLoop() {
|
|||||||
if (connected) {
|
if (connected) {
|
||||||
// still connected
|
// still connected
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("WIFI disconnected!\n");
|
Serial.printf("[WIFI ] Disconnected!\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
wifiLastMillis = 0;
|
wifiLastMillis = 0;
|
||||||
Serial.printf("WIFI connected: %s\n", WiFi.localIP().toString().c_str());
|
Serial.printf("[WIFI ] Connected: %s\n", WiFi.localIP().toString().c_str());
|
||||||
} else if (wifiLastMillis == 0 || millis() - wifiLastMillis > 10000) {
|
} else if (wifiLastMillis == 0 || millis() - wifiLastMillis > 10000) {
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
yield();
|
yield();
|
||||||
if (wifiLastMillis != 0) {
|
if (wifiLastMillis != 0) {
|
||||||
Serial.printf("WIFI connect timeout!\n");
|
Serial.printf("[WIFI ] Connect timeout!\n");
|
||||||
}
|
}
|
||||||
wifiLastMillis = max(1UL, millis());
|
wifiLastMillis = max(1UL, millis());
|
||||||
const auto ssid = "HappyNet";
|
const auto ssid = "HappyNet";
|
||||||
Serial.printf("WIFI connecting: %s\n", ssid);
|
Serial.printf("[WIFI ] Connecting: %s\n", ssid);
|
||||||
WiFi.begin(ssid, "1Grausame!Sackratte7");
|
WiFi.begin(ssid, "1Grausame!Sackratte7");
|
||||||
yield();
|
yield();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user