Rick Watson
5 years ago
8 changed files with 210 additions and 9 deletions
-
2interface/src/AppRouting.js
-
12interface/src/components/MenuAppBar.js
-
1interface/src/constants/Endpoints.js
-
141interface/src/containers/SystemStatus.js
-
3interface/src/sections/System.js
-
24src/SystemStatus.cpp
-
33src/SystemStatus.h
-
3src/main.cpp
@ -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 ( |
|||
<Fragment> |
|||
<ListItem > |
|||
<ListItemAvatar> |
|||
<Avatar> |
|||
<DevicesIcon /> |
|||
</Avatar> |
|||
</ListItemAvatar> |
|||
<ListItemText primary="Platform" secondary={data.esp_platform} /> |
|||
</ListItem> |
|||
<Divider variant="inset" component="li" /> |
|||
<ListItem > |
|||
<ListItemAvatar> |
|||
<Avatar> |
|||
<ShowChartIcon /> |
|||
</Avatar> |
|||
</ListItemAvatar> |
|||
<ListItemText primary="CPU Frequency" secondary={data.cpu_freq_mhz + ' MHz'} /> |
|||
</ListItem> |
|||
<Divider variant="inset" component="li" /> |
|||
<ListItem > |
|||
<ListItemAvatar> |
|||
<Avatar> |
|||
<MemoryIcon /> |
|||
</Avatar> |
|||
</ListItemAvatar> |
|||
<ListItemText primary="Free Heap" secondary={data.free_heap + ' bytes'} /> |
|||
</ListItem> |
|||
<Divider variant="inset" component="li" /> |
|||
<ListItem > |
|||
<ListItemAvatar> |
|||
<Avatar> |
|||
<DataUsageIcon /> |
|||
</Avatar> |
|||
</ListItemAvatar> |
|||
<ListItemText primary="Sketch Size (used/max)" secondary={data.sketch_size + ' / ' + data.free_sketch_space + ' bytes'} /> |
|||
</ListItem> |
|||
<Divider variant="inset" component="li" /> |
|||
<ListItem > |
|||
<ListItemAvatar> |
|||
<Avatar> |
|||
<SdStorageIcon /> |
|||
</Avatar> |
|||
</ListItemAvatar> |
|||
<ListItemText primary="Flash Chip Size" secondary={data.flash_chip_size + ' bytes'} /> |
|||
</ListItem> |
|||
<Divider variant="inset" component="li" /> |
|||
</Fragment> |
|||
); |
|||
} |
|||
|
|||
renderNTPStatus(data, classes) { |
|||
return ( |
|||
<div> |
|||
<List> |
|||
{this.createListItems(data, classes)} |
|||
</List> |
|||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}> |
|||
Refresh |
|||
</Button> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
render() { |
|||
const { data, fetched, errorMessage, classes } = this.props; |
|||
return ( |
|||
<SectionContent title="System Status"> |
|||
{ |
|||
!fetched ? |
|||
<div> |
|||
<LinearProgress className={classes.fetching} /> |
|||
<Typography variant="h4" className={classes.fetching}> |
|||
Loading... |
|||
</Typography> |
|||
</div> |
|||
: |
|||
data ? this.renderNTPStatus(data, classes) |
|||
: |
|||
<div> |
|||
<Typography variant="h4" className={classes.fetching}> |
|||
{errorMessage} |
|||
</Typography> |
|||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}> |
|||
Refresh |
|||
</Button> |
|||
</div> |
|||
} |
|||
</SectionContent> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default restComponent(SYSTEM_STATUS_ENDPOINT, withStyles(styles)(SystemStatus)); |
@ -0,0 +1,24 @@ |
|||
#include <SystemStatus.h>
|
|||
|
|||
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); |
|||
} |
@ -0,0 +1,33 @@ |
|||
#ifndef SystemStatus_h |
|||
#define SystemStatus_h |
|||
|
|||
#if defined(ESP8266) |
|||
#include <ESP8266WiFi.h> |
|||
#include <ESPAsyncTCP.h> |
|||
#elif defined(ESP_PLATFORM) |
|||
#include <WiFi.h> |
|||
#include <AsyncTCP.h> |
|||
#endif |
|||
|
|||
#include <ESPAsyncWebServer.h> |
|||
#include <ArduinoJson.h> |
|||
#include <AsyncArduinoJson6.h> |
|||
|
|||
#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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue