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