You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
2 years ago
|
#include <HTTPClient.h>
|
||
|
#include <FirebaseJson.h>
|
||
|
|
||
|
#define PLAYER_UPDATE_INTERVAL_MS (500)
|
||
|
|
||
|
static unsigned long playerLastUpdateTime = 0;
|
||
|
|
||
|
String httpURL(String path) {
|
||
|
return String(OWNTONE_SERVER_ADDRESS) + "/api/" + path;
|
||
|
}
|
||
|
|
||
|
String httpGET(String path) {
|
||
|
HTTPClient http;
|
||
|
|
||
|
Serial.println(httpURL(path));
|
||
|
|
||
|
http.begin(httpURL(path));
|
||
|
http.GET();
|
||
|
String out = http.getString();
|
||
|
http.end();
|
||
|
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
void apiDebug(AppState *state) {
|
||
|
|
||
|
}
|
||
|
|
||
|
void apiLoop(AppState *state) {
|
||
|
bool playerNeedsUpdate = (state->sinceBoot - playerLastUpdateTime) > PLAYER_UPDATE_INTERVAL_MS;
|
||
|
playerNeedsUpdate = playerNeedsUpdate || (playerLastUpdateTime > state->sinceBoot);
|
||
|
if (playerNeedsUpdate) {
|
||
|
String playerText = httpGET(String("player"));
|
||
|
FirebaseJson json;
|
||
|
json.setJsonData(playerText);
|
||
|
FirebaseJsonData result;
|
||
|
json.get(result, "volume");
|
||
|
Serial.println(result.type);
|
||
|
Serial.println(result.to<int>());
|
||
|
|
||
|
state->volume = result.to<int>();
|
||
|
|
||
|
playerLastUpdateTime = state->sinceBoot;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void apiSetup(AppState *state) {
|
||
|
|
||
|
}
|