From c029cf79f76bb909546c1b7abbef4dd7891c333c Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 14 Oct 2021 10:09:28 +0200 Subject: [PATCH] use smaller json key names, increase buffer size. fixes #157 --- interface/src/project/EMSESPDataForm.tsx | 36 +++++++++++------------- interface/src/project/EMSESPtypes.ts | 22 +++++++-------- interface/src/project/SensorForm.tsx | 10 +++---- src/web/WebDataService.cpp | 26 ++++++++--------- 4 files changed, 46 insertions(+), 48 deletions(-) diff --git a/interface/src/project/EMSESPDataForm.tsx b/interface/src/project/EMSESPDataForm.tsx index 6accf8e98..a62e12eef 100644 --- a/interface/src/project/EMSESPDataForm.tsx +++ b/interface/src/project/EMSESPDataForm.tsx @@ -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) => ( this.handleRowClick(device.id)} + key={device.i} + onClick={() => this.handleRowClick(device.i)} > @@ -338,12 +336,12 @@ class EMSESPDataForm extends Component< size="small" variant="outlined" > - {device.type} + {device.t} - {device.brand + ' ' + device.name}{' '} + {device.b + ' ' + device.n}{' '} ))} @@ -392,7 +390,7 @@ class EMSESPDataForm extends Component< {data.sensors.map((sensorData) => ( - + {me.admin && ( @@ -408,11 +406,11 @@ class EMSESPDataForm extends Component< )} - {sensorData.no} + {sensorData.n} - {sensorData.id} + {sensorData.i} - {formatValue(sensorData.temp, DeviceValueUOM.DEGREES, 1)} + {formatValue(sensorData.t, DeviceValueUOM.DEGREES, 1)} ))} diff --git a/interface/src/project/EMSESPtypes.ts b/interface/src/project/EMSESPtypes.ts index a65bc89a6..b0c25f39f 100644 --- a/interface/src/project/EMSESPtypes.ts +++ b/interface/src/project/EMSESPtypes.ts @@ -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 { diff --git a/interface/src/project/SensorForm.tsx b/interface/src/project/SensorForm.tsx index e981007ef..ea77f516e 100644 --- a/interface/src/project/SensorForm.tsx +++ b/interface/src/project/SensorForm.tsx @@ -43,7 +43,7 @@ class SensorForm extends React.Component { open > - Editing Sensor #{sensor.no} + Editing Sensor #{sensor.n} { 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 { 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')} /> diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index 631bc8984..32a582258 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -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 } }