Include information about versions and WiFi connection to controller's json.

This commit is contained in:
Fabian Schlenz 2019-11-29 05:46:26 +01:00
parent 196021bef5
commit 001e275131
3 changed files with 23 additions and 1 deletions

4
include/main.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
extern uint16_t spiffs_version;
void wifi_connect();

View File

@ -377,6 +377,23 @@ String Controller::json() {
rfid["data"] = _last_rfid_data; rfid["data"] = _last_rfid_data;
json["uptime"] = millis() / 1000; json["uptime"] = millis() / 1000;
json["free_heap"] = ESP.getFreeHeap(); json["free_heap"] = ESP.getFreeHeap();
JsonObject versions = json.createNestedObject("versions");
versions["spiffs"] = spiffs_version;
versions["ota"] = OTA_VERSION;
#ifdef VERSION
versions["release"] = VERSION;
#else
versions["release"] = "unknown";
#endif
JsonObject wifi = json.createNestedObject("wifi");
if (WiFi.isConnected()) {
wifi["connected"] = true;
wifi["ssid"] = WiFi.SSID();
wifi["rssi"] = WiFi.RSSI();
} else {
wifi["connected"] = false;
}
return json.as<String>(); return json.as<String>();
} }

View File

@ -20,6 +20,8 @@ HTTPServer* http_server;
uint8_t SPIMaster::state = 0; uint8_t SPIMaster::state = 0;
uint16_t spiffs_version = 0;
bool connect_to_wifi(String ssid, String pass) { bool connect_to_wifi(String ssid, String pass) {
TRACE("Connecting to wifi \"%s\"...\n", ssid.c_str()); TRACE("Connecting to wifi \"%s\"...\n", ssid.c_str());
WiFi.mode(WIFI_AP_STA); WiFi.mode(WIFI_AP_STA);
@ -100,7 +102,6 @@ void setup() {
spi->select_sd(false); spi->select_sd(false);
DEBUG("Starting SPIFFS...\n"); DEBUG("Starting SPIFFS...\n");
uint16_t spiffs_version = 0;
SPIFFS.begin(true); SPIFFS.begin(true);
if (SPIFFS.exists("/_version.txt")) { if (SPIFFS.exists("/_version.txt")) {
File f = SPIFFS.open("/_version.txt", "r"); File f = SPIFFS.open("/_version.txt", "r");