diff --git a/interface/src/AppRouting.js b/interface/src/AppRouting.js index 3217c1c..10670f1 100644 --- a/interface/src/AppRouting.js +++ b/interface/src/AppRouting.js @@ -29,8 +29,8 @@ class AppRouting extends Component { - + diff --git a/interface/src/components/MenuAppBar.js b/interface/src/components/MenuAppBar.js index 1d36edb..674e804 100644 --- a/interface/src/components/MenuAppBar.js +++ b/interface/src/components/MenuAppBar.js @@ -127,18 +127,18 @@ class MenuAppBar extends React.Component { - - - - - - + + + + + + ); diff --git a/interface/src/constants/Endpoints.js b/interface/src/constants/Endpoints.js index c9874b6..b3efbfa 100644 --- a/interface/src/constants/Endpoints.js +++ b/interface/src/constants/Endpoints.js @@ -9,6 +9,7 @@ export const LIST_NETWORKS_ENDPOINT = ENDPOINT_ROOT + "listNetworks"; export const WIFI_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "wifiSettings"; export const WIFI_STATUS_ENDPOINT = ENDPOINT_ROOT + "wifiStatus"; export const OTA_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "otaSettings"; +export const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus"; export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn"; export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization"; export const USERS_ENDPOINT = ENDPOINT_ROOT + "users"; diff --git a/interface/src/containers/SystemStatus.js b/interface/src/containers/SystemStatus.js new file mode 100644 index 0000000..ae287df --- /dev/null +++ b/interface/src/containers/SystemStatus.js @@ -0,0 +1,141 @@ +import React, { Component, Fragment } from 'react'; + +import { withStyles } from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import LinearProgress from '@material-ui/core/LinearProgress'; +import Typography from '@material-ui/core/Typography'; +import List from '@material-ui/core/List'; +import ListItem from '@material-ui/core/ListItem'; +import ListItemAvatar from '@material-ui/core/ListItemAvatar'; +import ListItemText from '@material-ui/core/ListItemText'; +import Avatar from '@material-ui/core/Avatar'; +import Divider from '@material-ui/core/Divider'; +import DevicesIcon from '@material-ui/icons/Devices'; +import MemoryIcon from '@material-ui/icons/Memory'; +import ShowChartIcon from '@material-ui/icons/ShowChart'; +import SdStorageIcon from '@material-ui/icons/SdStorage'; +import DataUsageIcon from '@material-ui/icons/DataUsage'; + + +import { SYSTEM_STATUS_ENDPOINT } from '../constants/Endpoints'; +import { restComponent } from '../components/RestComponent'; +import SectionContent from '../components/SectionContent'; + +const styles = theme => ({ + fetching: { + margin: theme.spacing.unit * 4, + textAlign: "center" + }, + button: { + marginRight: theme.spacing.unit * 2, + marginTop: theme.spacing.unit * 2, + } +}); + +class SystemStatus extends Component { + + componentDidMount() { + this.props.loadData(); + } + /* + { + "sdk_version": "v3.2-18-g977854975", + "flash_chip_size": 4194304, + "flash_chip_speed": 40000000 + } +*/ + createListItems(data, classes) { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); + } + + renderNTPStatus(data, classes) { + return ( +
+ + {this.createListItems(data, classes)} + + +
+ ); + } + + render() { + const { data, fetched, errorMessage, classes } = this.props; + return ( + + { + !fetched ? +
+ + + Loading... + +
+ : + data ? this.renderNTPStatus(data, classes) + : +
+ + {errorMessage} + + +
+ } +
+ ) + } +} + +export default restComponent(SYSTEM_STATUS_ENDPOINT, withStyles(styles)(SystemStatus)); diff --git a/interface/src/sections/System.js b/interface/src/sections/System.js index ed9f120..f34c9b6 100644 --- a/interface/src/sections/System.js +++ b/interface/src/sections/System.js @@ -7,6 +7,7 @@ import Tab from '@material-ui/core/Tab'; import AuthenticatedRoute from '../authentication/AuthenticatedRoute'; import MenuAppBar from '../components/MenuAppBar'; import OTASettings from '../containers/OTASettings'; +import SystemStatus from '../containers/SystemStatus'; class System extends Component { @@ -22,7 +23,7 @@ class System extends Component { - + diff --git a/src/SystemStatus.cpp b/src/SystemStatus.cpp new file mode 100644 index 0000000..de99a3d --- /dev/null +++ b/src/SystemStatus.cpp @@ -0,0 +1,24 @@ +#include + + SystemStatus::SystemStatus(AsyncWebServer *server) : _server(server) { + _server->on(SYSTEM_STATUS_SERVICE_PATH, HTTP_GET, std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1)); +} + + void SystemStatus::systemStatus(AsyncWebServerRequest *request) { + AsyncJsonResponse * response = new AsyncJsonResponse(MAX_ESP_STATUS_SIZE); + JsonObject root = response->getRoot(); +#if defined(ESP8266) + root["esp_platform"] = "esp8266"; +#elif defined(ESP_PLATFORM) + root["esp_platform"] = "esp32"; +#endif + root["cpu_freq_mhz"] = ESP.getCpuFreqMHz(); + root["free_heap"] = ESP.getFreeHeap(); + root["sketch_size"] = ESP.getSketchSize(); + root["free_sketch_space"] = ESP.getFreeSketchSpace(); + root["sdk_version"] = ESP.getSdkVersion(); + root["flash_chip_size"] = ESP.getFlashChipSize(); + root["flash_chip_speed"] = ESP.getFlashChipSpeed(); + response->setLength(); + request->send(response); +} diff --git a/src/SystemStatus.h b/src/SystemStatus.h new file mode 100644 index 0000000..2ae4f90 --- /dev/null +++ b/src/SystemStatus.h @@ -0,0 +1,33 @@ +#ifndef SystemStatus_h +#define SystemStatus_h + +#if defined(ESP8266) + #include + #include +#elif defined(ESP_PLATFORM) + #include + #include +#endif + +#include +#include +#include + +#define MAX_ESP_STATUS_SIZE 1024 +#define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus" + +class SystemStatus { + + public: + + SystemStatus(AsyncWebServer *server); + + private: + + AsyncWebServer* _server; + + void systemStatus(AsyncWebServerRequest *request); + +}; + +#endif // end SystemStatus_h \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ea0a4c5..694fde9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ #include #include #include - +#include #define SERIAL_BAUD_RATE 115200 @@ -39,6 +39,7 @@ WiFiScanner wifiScanner = WiFiScanner(&server); WiFiStatus wifiStatus = WiFiStatus(&server); NTPStatus ntpStatus = NTPStatus(&server); APStatus apStatus = APStatus(&server); +SystemStatus systemStatus = SystemStatus(&server); void setup() { // Disable wifi config persistance