mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
use smaller json key names, increase buffer size. fixes #157
This commit is contained in:
@@ -82,10 +82,10 @@ const CustomTooltip = withStyles((theme: Theme) => ({
|
|||||||
}))(Tooltip);
|
}))(Tooltip);
|
||||||
|
|
||||||
function compareDevices(a: Device, b: Device) {
|
function compareDevices(a: Device, b: Device) {
|
||||||
if (a.type < b.type) {
|
if (a.t < b.t) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (a.type > b.type) {
|
if (a.t > b.t) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -244,10 +244,10 @@ class EMSESPDataForm extends Component<
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
// because input field with type=number doens't like negative values, force it here
|
// because input field with type=number doens't like negative values, force it here
|
||||||
sensor: {
|
sensor: {
|
||||||
no: edit_Sensor?.no,
|
no: edit_Sensor?.n, // no
|
||||||
id: edit_Sensor?.id,
|
id: edit_Sensor?.i, // id
|
||||||
temp: edit_Sensor?.temp,
|
temp: edit_Sensor?.t, // temp
|
||||||
offset: Number(edit_Sensor?.offset)
|
offset: Number(edit_Sensor?.o) // offset
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -316,20 +316,18 @@ class EMSESPDataForm extends Component<
|
|||||||
{data.devices.sort(compareDevices).map((device) => (
|
{data.devices.sort(compareDevices).map((device) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
hover
|
hover
|
||||||
key={device.id}
|
key={device.i}
|
||||||
onClick={() => this.handleRowClick(device.id)}
|
onClick={() => this.handleRowClick(device.i)}
|
||||||
>
|
>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<CustomTooltip
|
<CustomTooltip
|
||||||
title={
|
title={
|
||||||
'DeviceID:0x' +
|
'DeviceID:0x' +
|
||||||
(
|
('00' + device.d.toString(16).toUpperCase()).slice(-2) +
|
||||||
'00' + device.deviceid.toString(16).toUpperCase()
|
|
||||||
).slice(-2) +
|
|
||||||
' ProductID:' +
|
' ProductID:' +
|
||||||
device.productid +
|
device.p +
|
||||||
' Version:' +
|
' Version:' +
|
||||||
device.version
|
device.v
|
||||||
}
|
}
|
||||||
placement="right-end"
|
placement="right-end"
|
||||||
>
|
>
|
||||||
@@ -338,12 +336,12 @@ class EMSESPDataForm extends Component<
|
|||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
>
|
>
|
||||||
{device.type}
|
{device.t}
|
||||||
</Button>
|
</Button>
|
||||||
</CustomTooltip>
|
</CustomTooltip>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="right">
|
<TableCell align="right">
|
||||||
{device.brand + ' ' + device.name}{' '}
|
{device.b + ' ' + device.n}{' '}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
@@ -392,7 +390,7 @@ class EMSESPDataForm extends Component<
|
|||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.sensors.map((sensorData) => (
|
{data.sensors.map((sensorData) => (
|
||||||
<TableRow key={sensorData.no} hover>
|
<TableRow key={sensorData.n} hover>
|
||||||
<TableCell padding="checkbox" style={{ width: 18 }}>
|
<TableCell padding="checkbox" style={{ width: 18 }}>
|
||||||
{me.admin && (
|
{me.admin && (
|
||||||
<CustomTooltip title="edit" placement="left-end">
|
<CustomTooltip title="edit" placement="left-end">
|
||||||
@@ -408,11 +406,11 @@ class EMSESPDataForm extends Component<
|
|||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell component="th" scope="row">
|
<TableCell component="th" scope="row">
|
||||||
{sensorData.no}
|
{sensorData.n}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="left">{sensorData.id}</TableCell>
|
<TableCell align="left">{sensorData.i}</TableCell>
|
||||||
<TableCell align="right">
|
<TableCell align="right">
|
||||||
{formatValue(sensorData.temp, DeviceValueUOM.DEGREES, 1)}
|
{formatValue(sensorData.t, DeviceValueUOM.DEGREES, 1)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -41,20 +41,20 @@ export interface EMSESPStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Device {
|
export interface Device {
|
||||||
id: number;
|
i: number; // id
|
||||||
type: string;
|
t: string; // type
|
||||||
brand: string;
|
b: string; // brand
|
||||||
name: string;
|
n: string; // name
|
||||||
deviceid: number;
|
d: number; // deviceid
|
||||||
productid: number;
|
p: number; // productid
|
||||||
version: string;
|
v: string; // version
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Sensor {
|
export interface Sensor {
|
||||||
no: number;
|
n: number; // np
|
||||||
id: string;
|
i: string; // id
|
||||||
temp: number;
|
t: number; // temp
|
||||||
offset: number;
|
o: number; // offset
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EMSESPData {
|
export interface EMSESPData {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class SensorForm extends React.Component<SensorFormProps> {
|
|||||||
open
|
open
|
||||||
>
|
>
|
||||||
<DialogTitle id="user-form-dialog-title">
|
<DialogTitle id="user-form-dialog-title">
|
||||||
Editing Sensor #{sensor.no}
|
Editing Sensor #{sensor.n}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<TextValidator
|
<TextValidator
|
||||||
@@ -51,8 +51,8 @@ class SensorForm extends React.Component<SensorFormProps> {
|
|||||||
errorMessages={['Not a valid name']}
|
errorMessages={['Not a valid name']}
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={sensor.id}
|
value={sensor.i}
|
||||||
onChange={handleSensorChange('id')}
|
onChange={handleSensorChange('i')}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
label="Name"
|
label="Name"
|
||||||
name="id"
|
name="id"
|
||||||
@@ -67,12 +67,12 @@ class SensorForm extends React.Component<SensorFormProps> {
|
|||||||
label="Custom Offset (°C)"
|
label="Custom Offset (°C)"
|
||||||
name="offset"
|
name="offset"
|
||||||
type="number"
|
type="number"
|
||||||
value={sensor.offset}
|
value={sensor.o}
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
InputProps={{ inputProps: { min: '-5', max: '5', step: '0.1' } }}
|
InputProps={{ inputProps: { min: '-5', max: '5', step: '0.1' } }}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
onChange={handleSensorChange('offset')}
|
onChange={handleSensorChange('o')}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|||||||
@@ -55,20 +55,20 @@ void WebDataService::scan_devices(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebDataService::all_devices(AsyncWebServerRequest * request) {
|
void WebDataService::all_devices(AsyncWebServerRequest * request) {
|
||||||
AsyncJsonResponse * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_LARGE_DYN);
|
AsyncJsonResponse * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_XLARGE_DYN);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
JsonArray devices = root.createNestedArray("devices");
|
JsonArray devices = root.createNestedArray("devices");
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice) {
|
if (emsdevice) {
|
||||||
JsonObject obj = devices.createNestedObject();
|
JsonObject obj = devices.createNestedObject();
|
||||||
obj["id"] = emsdevice->unique_id();
|
obj["i"] = emsdevice->unique_id(); // id
|
||||||
obj["type"] = emsdevice->device_type_name();
|
obj["t"] = emsdevice->device_type_name(); // type
|
||||||
obj["brand"] = emsdevice->brand_to_string();
|
obj["b"] = emsdevice->brand_to_string(); // brand
|
||||||
obj["name"] = emsdevice->name();
|
obj["n"] = emsdevice->name(); // name
|
||||||
obj["deviceid"] = emsdevice->device_id();
|
obj["d"] = emsdevice->device_id(); // deviceid
|
||||||
obj["productid"] = emsdevice->product_id();
|
obj["p"] = emsdevice->product_id(); // productid
|
||||||
obj["version"] = emsdevice->version();
|
obj["v"] = emsdevice->version(); // version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,10 +77,10 @@ void WebDataService::all_devices(AsyncWebServerRequest * request) {
|
|||||||
uint8_t i = 1;
|
uint8_t i = 1;
|
||||||
for (const auto & sensor : EMSESP::sensor_devices()) {
|
for (const auto & sensor : EMSESP::sensor_devices()) {
|
||||||
JsonObject obj = sensors.createNestedObject();
|
JsonObject obj = sensors.createNestedObject();
|
||||||
obj["no"] = i++;
|
obj["n"] = i++; // no
|
||||||
obj["id"] = sensor.to_string(true);
|
obj["i"] = sensor.to_string(true); // id
|
||||||
obj["temp"] = (float)(sensor.temperature_c) / 10;
|
obj["t"] = (float)(sensor.temperature_c) / 10; // temp
|
||||||
obj["offset"] = (float)(sensor.offset()) / 10;
|
obj["o"] = (float)(sensor.offset()) / 10; // offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user