Skip to content

Commit

Permalink
use smaller json key names, increase buffer size. fixes #157
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 14, 2021
1 parent 0b796a8 commit c029cf7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 48 deletions.
36 changes: 17 additions & 19 deletions interface/src/project/EMSESPDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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"
>
Expand All @@ -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>
))}
Expand Down Expand Up @@ -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">
Expand All @@ -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>
))}
Expand Down
22 changes: 11 additions & 11 deletions interface/src/project/EMSESPtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions interface/src/project/SensorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ 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
validators={['matchRegexp:^([a-zA-Z0-9_.-]{0,19})$']}
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"
Expand All @@ -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>
Expand Down
26 changes: 13 additions & 13 deletions src/web/WebDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down

0 comments on commit c029cf7

Please sign in to comment.