From 001e2751316e7fb23a062a3e85dbd776579cb660 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 29 Nov 2019 05:46:26 +0100 Subject: [PATCH] Include information about versions and WiFi connection to controller's json. --- include/main.h | 4 ++++ src/controller.cpp | 17 +++++++++++++++++ src/main.cpp | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 include/main.h diff --git a/include/main.h b/include/main.h new file mode 100644 index 0000000..b1c6ac1 --- /dev/null +++ b/include/main.h @@ -0,0 +1,4 @@ +#pragma once + +extern uint16_t spiffs_version; +void wifi_connect(); diff --git a/src/controller.cpp b/src/controller.cpp index f2c37df..6189e53 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -377,6 +377,23 @@ String Controller::json() { rfid["data"] = _last_rfid_data; json["uptime"] = millis() / 1000; 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(); } diff --git a/src/main.cpp b/src/main.cpp index 5233578..6a50dfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,8 @@ HTTPServer* http_server; uint8_t SPIMaster::state = 0; +uint16_t spiffs_version = 0; + bool connect_to_wifi(String ssid, String pass) { TRACE("Connecting to wifi \"%s\"...\n", ssid.c_str()); WiFi.mode(WIFI_AP_STA); @@ -100,7 +102,6 @@ void setup() { spi->select_sd(false); DEBUG("Starting SPIFFS...\n"); - uint16_t spiffs_version = 0; SPIFFS.begin(true); if (SPIFFS.exists("/_version.txt")) { File f = SPIFFS.open("/_version.txt", "r");