mirror of
https://github.com/lumapu/ahoy.git
synced 2025-07-16 16:05:15 +02:00
fix #338, needs verifcation from homeassistant users
added download link for settings on setup.html and update.html
This commit is contained in:
parent
38bb3fd7e2
commit
a595950d7d
6 changed files with 77 additions and 29 deletions
|
@ -26,6 +26,8 @@ void webApi::setup(void) {
|
|||
mSrv->on("/api", HTTP_GET, std::bind(&webApi::onApi, this, std::placeholders::_1));
|
||||
mSrv->on("/api", HTTP_POST, std::bind(&webApi::onApiPost, this, std::placeholders::_1)).onBody(
|
||||
std::bind(&webApi::onApiPostBody, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
|
||||
|
||||
mSrv->on("/get_setup", HTTP_GET, std::bind(&webApi::onDwnldSetup, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,6 +119,21 @@ void webApi::getNotFound(JsonObject obj, String url) {
|
|||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void webApi::onDwnldSetup(AsyncWebServerRequest *request) {
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 8192);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
getSetup(root);
|
||||
|
||||
response->setLength();
|
||||
response->addHeader("Content-Type", "application/octet-stream");
|
||||
response->addHeader("Content-Description", "File Transfer");
|
||||
response->addHeader("Content-Disposition", "attachment; filename=ahoy_setup.json");
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void webApi::getSystem(JsonObject obj) {
|
||||
obj[F("ssid")] = mSysCfg->stationSsid;
|
||||
|
@ -396,6 +413,8 @@ bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
|
|||
mApp->setTimestamp(jsonIn[F("ts")]);
|
||||
else if(F("sync_ntp") == jsonIn[F("cmd")])
|
||||
mApp->setTimestamp(0); // 0: update ntp flag
|
||||
else if(F("discovery_cfg") == jsonIn[F("cmd")])
|
||||
mApp->mFlagSendDiscoveryConfig = true; // for homeassistant
|
||||
else {
|
||||
jsonOut[F("error")] = F("unknown cmd");
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue