Deploy script, wifi reconnect

This commit is contained in:
Martin Bauer
2020-08-08 22:18:35 +02:00
parent 314f57b2b7
commit ae341f91b3
3 changed files with 155 additions and 17 deletions

View File

@@ -72,7 +72,7 @@ void httpSetup(SessionManager<SessionT> *sessionManager)
Serial.println("Tare");
sessionManager->tare();
};
auto cbFirmwareUpdate = [](httpd_req_t * req) {
auto cbFirmwareUpdate = [](httpd_req_t *req) {
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, "OK", -1);
firmwareUpdate();
@@ -116,7 +116,22 @@ void httpSetup(SessionManager<SessionT> *sessionManager)
{
const String freeBytes(ESP.getFreePsram());
const String usedBytes(ESP.getPsramSize() - ESP.getFreePsram());
result += "\"psram\": { \"used\": " + usedBytes + ", \"free\":" + freeBytes + "}\n";
result += "\"psram\": { \"used\": " + usedBytes + ", \"free\":" + freeBytes + "},\n";
}
// firmware
{
auto descr = esp_ota_get_app_description();
const String projectName(descr->project_name);
const String versionStr(descr->version);
const String idfVersion(descr->idf_ver);
const String compileDate(descr->date);
const String compileTime(descr->time);
result += "\"firmware\": { \"name\" : \"" +
projectName + "\", \"version\": \"" +
versionStr + "\", \"idfVersion\": \"" +
idfVersion + "\", \"compile_date\": \"" +
compileDate + +"\", \"compile_time\": \"" +
compileTime + "\" }\n";
}
result += "}";
httpd_resp_send(req, result.c_str(), result.length());
@@ -178,11 +193,8 @@ void checkWifi()
while (WiFi.status() != WL_CONNECTED)
{
Serial.println("WiFi disconnected. Try to reconnect");
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
delay(200);
WiFi.reconnect();
delay(2000);
}
}
@@ -202,7 +214,7 @@ void setup()
while (!Serial)
{
}
Serial.println("Starting SwimTracker Firmware");
Serial.printf("Starting SwimTracker Firmware - connecting to %s\n", CONFIG_WIFI_SSID);
// File system
bool spiffsResult = SPIFFS.begin(true);
@@ -212,6 +224,7 @@ void setup()
ESP_ERROR_CHECK(esp_event_loop_create_default());
// WiFi
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
String fullHostname = String(CONFIG_HOSTNAME) + getIdSuffix();
@@ -230,14 +243,18 @@ void setup()
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
Serial.println("Running version 1"); // todo
Serial.println("Running version new24!"); // todo
// Session
sessionManager.begin();
// HTTP & Websocket server
httpSetup(&sessionManager);
Serial.printf("Offset %d\n", sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t));
Serial.printf("Size %d\n", sizeof(esp_app_desc_t));
webSocketServer.begin();
}