Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
f9f8f17803 | |||
58ddb4fb74 | |||
c940a2afec | |||
0c42b53902 | |||
566ee35935 |
36
API_DOC.txt
36
API_DOC.txt
@@ -1,36 +0,0 @@
|
||||
API Location Method Returns Redirects to Description
|
||||
---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
/api/ API root
|
||||
----------------
|
||||
|
||||
|
||||
/api/v1/playback/ Playback functions
|
||||
----------------
|
||||
/api/v1/playback/toggle GET JSON object Toggle Playback
|
||||
/api/v1/playback/play GET JSON object Start playback
|
||||
/api/v1/playback/pause GET JSON object Pause playback
|
||||
/api/v1/playback/next GET JSON object Play next audio
|
||||
/api/v1/playback/previous GET JSON object Play previous audio
|
||||
/api/v1/playback/info GET JSON object Get the title, artist, album, path, type, ... of the current played resource
|
||||
|
||||
/api/v1/playlist/
|
||||
----------------
|
||||
/api/v1/playlist/get GET JSON object Returns the whole current playlist
|
||||
/api/v1/playlist/create POST JSON object Creates a playlist of the given directory
|
||||
/api/v1/playlist/play POST JSON object Plays a playlist from the SD card
|
||||
|
||||
/api/v1/volume/
|
||||
----------------
|
||||
/api/v1/volume/up GET JSON object Higher the volume (max. 20)
|
||||
/api/v1/volume/down GET JSON object Lower the volume (min. 0)
|
||||
/api/v1/volume/mute GET JSON object Mute (does not affect volume)
|
||||
/api/v1/volume/unmute GET JSON object Unmute (set volume to current volume)
|
||||
/api/v1/volume/get GET JSON object Do nothing, just get the volume
|
||||
/api/v1/volume/<0-20> GET JSON object Set volume to a specific value between 0 and 20
|
||||
|
||||
/api/v1/settings/
|
||||
----------------
|
||||
/api/v1/settings/restart GET JSON object Performs a reboot of the microcontroller (after waiting 5000ms)
|
||||
|
@@ -53,12 +53,11 @@ Features, already implemented, or still in progress for the v1.0.0 release!
|
||||
- [X] /api/v1/eq/mid/<0-46>
|
||||
- [X] /api/v1/eq/high/get
|
||||
- [X] /api/v1/eq/high/<0-46>
|
||||
- [X] /api/v1/settings/restart/
|
||||
- [X] /api/v1/system/restart/
|
||||
- [ ] /api/v1/system/name
|
||||
- [ ] /api/v1/system/info
|
||||
- [ ] /api/v1/system/name
|
||||
- [ ] /api/v1/system/wifi/change
|
||||
- [ ] /api/v1/system/wifi/get_ssid
|
||||
- [X] /api/v1/system/wifi/change
|
||||
- [X] /api/v1/system/wifi/get_ssid
|
||||
- [ ] /api/v1/files/get
|
||||
- [ ] /api/v1/files/upload
|
||||
- [X] Automatic WiFi connection
|
||||
|
@@ -21,7 +21,7 @@ For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
|
||||
// define all constants
|
||||
const String version = "NetSpeaker v0.2.2-dev"; // version string used e.g. for access point ssid when wifi couldn't connect
|
||||
const String version = "NetSpeaker v0.2.5-dev"; // version string used e.g. for access point ssid when wifi couldn't connect
|
||||
const int operation_mode = 0; // 0: interconnected (no buttons, but api and wifi); 1: standalone (no wifi; no api)
|
||||
const int SD_CS = 5; // BOARD SPECIFIC
|
||||
const int SPI_MISO = 19; // BOARD SPECIFIC
|
||||
|
@@ -188,10 +188,9 @@ void audio_lasthost(const char *info) { // stream URL played
|
||||
}
|
||||
|
||||
// *********************************************************************************** //
|
||||
// *************** Code heavily inspired by schreibfaul1's wiki entry ************** //
|
||||
// ******** Following function heavily inspired by schreibfaul1's wiki entry ******** //
|
||||
// * https://github.com/schreibfaul1/ESP32-audioI2S/wiki#what-audio-events-are-there * //
|
||||
// *********************************************************************************** //
|
||||
|
||||
void audio_id3image(File &file, const size_t pos, const size_t size) { // cover image
|
||||
Serial.printf("[Audio.h] ID3Image Found at position: %u | Length: %u\n", pos, size);
|
||||
uint8_t buf[1024];
|
||||
|
@@ -20,6 +20,21 @@ int setupSD(int SD_CS, int SPI_MISO, int SPI_MOSI, int SPI_SCK) {
|
||||
return ret; // returns 1 if everything is OK, 0 if an error occured (eg. wiring not correct)
|
||||
}
|
||||
|
||||
bool writeWiFiSecrets(String confPath, String ssid, String psk) {
|
||||
File wifiSecrets = SD.open(confPath, FILE_WRITE);
|
||||
|
||||
wifiSecrets.printf("%s\n", ssid.c_str());
|
||||
wifiSecrets.printf("%s", psk.c_str());
|
||||
|
||||
wifiSecrets.flush();
|
||||
wifiSecrets.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
bool writeWiFiSecrets(String ssid, String psk) {
|
||||
return writeWiFiSecrets(wifiConfigPath, ssid, psk);
|
||||
}
|
||||
|
||||
String getWiFiSSID(String confPath) {
|
||||
String ssid;
|
||||
char new_char;
|
||||
@@ -28,7 +43,7 @@ String getWiFiSSID(String confPath) {
|
||||
File confFile = SD.open(confPath);
|
||||
|
||||
ssid = (char)confFile.read();
|
||||
while (ssid[ssid.length() - 1] != '\n' && confFile.available()) {
|
||||
while (ssid[ssid.length() - 1] != '\n' || ssid[ssid.length() - 1] != '\r' && confFile.available()) {
|
||||
new_char = (char)confFile.read();
|
||||
if (new_char == '\n') break;
|
||||
ssid += new_char;
|
||||
@@ -55,7 +70,7 @@ String getWiFiPSK(String confPath) {
|
||||
psk = (char)confFile.read();
|
||||
while (confFile.available()) {
|
||||
new_char = (char)confFile.read();
|
||||
if (new_char == '\n') break;
|
||||
if (new_char == '\n' || new_char == '\r') break;
|
||||
psk += new_char;
|
||||
}
|
||||
|
||||
|
@@ -401,15 +401,58 @@ void api_v1_playlist_play() {
|
||||
}
|
||||
}
|
||||
|
||||
void api_v1_settings_restart() {
|
||||
void api_v1_system_restart() {
|
||||
Serial.println("[HTTP] [API] 200 - GET '/api/v1/system/restart'");
|
||||
|
||||
SD.end(); // delete SD object and sync its cache to flash
|
||||
WiFi.disconnect(); // disconnect wifi
|
||||
Serial.printf("[INFO] Restarting after 5000ms.\n", waitOnSDCardEject, retrySDMountTreshold);
|
||||
delay(5000);
|
||||
api_server.send(200, "application/json", "{\"restart\": true, \"wait_time\": 5000}");
|
||||
delay(5000);
|
||||
ESP.restart(); // reset everything and restart the program
|
||||
}
|
||||
|
||||
void api_v1_system_wifi_getssid() {
|
||||
Serial.println("[HTTP] [API] 200 - GET '/api/v1/system/wifi/get_ssid'");
|
||||
|
||||
api_server.send(200, "application/json", generate_api_json(true, "\"wifi_ssid\": \"" + getWiFiSSID() + "\""));
|
||||
}
|
||||
|
||||
void api_v1_system_wifi_change() {
|
||||
Serial.println("[HTTP] [API] 200 - POST '/api/v1/system/wifi/change'");
|
||||
|
||||
// get the right POST params
|
||||
String ssid = "";
|
||||
String psk = "";
|
||||
for (int i = 0; i < api_server.args(); i++) {
|
||||
if (api_server.argName(i) == "ssid") {
|
||||
ssid = api_server.arg(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < api_server.args(); i++) {
|
||||
if (api_server.argName(i) == "psk") {
|
||||
psk = api_server.arg(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ssid != "" && psk != "") { // both ssid and psk are given
|
||||
writeWiFiSecrets(ssid, psk);
|
||||
} else if (ssid != "" && psk == "") { // just the ssid is given
|
||||
writeWiFiSecrets(ssid, getWiFiPSK());
|
||||
} else if (ssid == "" && psk != "") { // just the psk is given
|
||||
writeWiFiSecrets(getWiFiSSID(), psk);
|
||||
} else { // none of ssid or psk is given
|
||||
api_server.send(200, "application/json", generate_api_json(false));
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.printf("[INFO] Changed wifi credentials (SSID: '%s' | PSK: '%s')\n", ssid.c_str(), psk.c_str());
|
||||
api_server.send(200, "application/json", generate_api_json(true, "\"ssid\": \"" + ssid + "\", \"psk\": \"" + psk + "\""));
|
||||
}
|
||||
|
||||
|
||||
void setupConfigWeb() {
|
||||
if (runConfServer) {
|
||||
conf_server.onNotFound([]() {
|
||||
@@ -442,12 +485,14 @@ void setupApiWeb() {
|
||||
api_server.on("/api/v1/playlist/play", HTTP_POST, api_v1_playlist_play);
|
||||
api_server.on(UriBraces("/api/v1/volume/{}"), HTTP_GET, api_v1_volume);
|
||||
api_server.on(UriBraces("/api/v1/balance/{}"), HTTP_GET, api_v1_balance);
|
||||
api_server.on(UriBraces("/api/v1/eq/get"), HTTP_GET, api_v1_eq_get);
|
||||
api_server.on("/api/v1/eq/get", HTTP_GET, api_v1_eq_get);
|
||||
api_server.on(UriBraces("/api/v1/eq/reset"), HTTP_GET, api_v1_eq_reset);
|
||||
api_server.on(UriBraces("/api/v1/eq/low/{}"), HTTP_GET, api_v1_eq_low);
|
||||
api_server.on(UriBraces("/api/v1/eq/mid/{}"), HTTP_GET, api_v1_eq_mid);
|
||||
api_server.on(UriBraces("/api/v1/eq/high/{}"), HTTP_GET, api_v1_eq_high);
|
||||
api_server.on("/api/v1/settings/restart", HTTP_GET, api_v1_settings_restart);
|
||||
api_server.on("/api/v1/system/restart", HTTP_GET, api_v1_system_restart);
|
||||
api_server.on("/api/v1/system/wifi/change", HTTP_POST, api_v1_system_wifi_change);
|
||||
api_server.on("/api/v1/system/wifi/get_ssid", HTTP_GET, api_v1_system_wifi_getssid);
|
||||
|
||||
Serial.println("[HTTP] [API] Starting API server (http) on port " + String(webport_api));
|
||||
api_server.begin();
|
||||
|
@@ -32,11 +32,13 @@ void setupWiFi() {
|
||||
for(int i = 0; i<33; i++) { if(WiFiSSIDstr.length() >= i) {WiFiSSID[i] = WiFiSSIDstr[i];} else break; }
|
||||
for(int i = 0; i<64; i++) { if(WiFiPSKstr.length() >= i) {WiFiPSK[i] = WiFiPSKstr[i];} else break; }
|
||||
|
||||
//Serial.printf("[WiFi] Credentials: SSID '%s' | PSK '%s'\n", WiFiSSID, WiFiPSK); // kept here fordebugging wifi problems
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
WiFi.begin(WiFiSSID, WiFiPSK);
|
||||
// wait for 10 seconds for wifi to connect
|
||||
int start_timer = millis(); while(WiFi.status() != WL_CONNECTED) { if((millis()-start_timer) > 20000) break; }
|
||||
int start_timer = millis(); while(WiFi.status() != WL_CONNECTED) { if((millis()-start_timer) > 20000) break; delay(10); }
|
||||
if(WiFi.status() != WL_CONNECTED) {
|
||||
currentWiFiMode = 1;
|
||||
Serial.printf("[WiFi] Unable to connect to %s\n", WiFiSSID);
|
||||
|
Reference in New Issue
Block a user