mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
show external dallas temp sensors in web UI
This commit is contained in:
@@ -22,7 +22,7 @@ class EMSESP extends Component<RouteComponentProps> {
|
|||||||
<MenuAppBar sectionTitle="Dashboard">
|
<MenuAppBar sectionTitle="Dashboard">
|
||||||
<Tabs value={this.props.match.url} onChange={this.handleTabChange} variant="fullWidth">
|
<Tabs value={this.props.match.url} onChange={this.handleTabChange} variant="fullWidth">
|
||||||
<Tab value={`/${PROJECT_PATH}/status`} label="EMS Status" />
|
<Tab value={`/${PROJECT_PATH}/status`} label="EMS Status" />
|
||||||
<Tab value={`/${PROJECT_PATH}/devices`} label="EMS Devices" />
|
<Tab value={`/${PROJECT_PATH}/devices`} label="Devices & Sensors" />
|
||||||
<Tab value={`/${PROJECT_PATH}/help`} label="EMS-ESP Help" />
|
<Tab value={`/${PROJECT_PATH}/help`} label="EMS-ESP Help" />
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class EMSESPDevicesController extends Component<EMSESPDevicesControllerProps> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<SectionContent title="EMS Devices">
|
<SectionContent title="Devices & Sensors">
|
||||||
<RestFormLoader
|
<RestFormLoader
|
||||||
{...this.props}
|
{...this.props}
|
||||||
render={formProps => <EMSESPDevicesForm {...formProps} />}
|
render={formProps => <EMSESPDevicesForm {...formProps} />}
|
||||||
|
|||||||
@@ -71,14 +71,21 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
|
|||||||
return (this.props.data.devices.length === 0);
|
return (this.props.data.devices.length === 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
noSensors = () => {
|
||||||
|
return (this.props.data.sensors.length === 0);
|
||||||
|
};
|
||||||
|
|
||||||
noDeviceData = () => {
|
noDeviceData = () => {
|
||||||
return (this.state.deviceData?.deviceData.length === 0);
|
return (this.state.deviceData?.deviceData.length === 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
createTableItems() {
|
createDeviceItems() {
|
||||||
const { width, data } = this.props;
|
const { width, data } = this.props;
|
||||||
return (
|
return (
|
||||||
<TableContainer>
|
<TableContainer>
|
||||||
|
<Typography variant="h6" color="primary" paragraph>
|
||||||
|
Devices:
|
||||||
|
</Typography>
|
||||||
{!this.noDevices() && (
|
{!this.noDevices() && (
|
||||||
<Table size="small" padding={isWidthDown('xs', width!) ? "none" : "default"}>
|
<Table size="small" padding={isWidthDown('xs', width!) ? "none" : "default"}>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
@@ -132,6 +139,49 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createSensorItems() {
|
||||||
|
const { data } = this.props;
|
||||||
|
return (
|
||||||
|
<TableContainer>
|
||||||
|
<p></p>
|
||||||
|
<Typography variant="h6" color="primary" paragraph>
|
||||||
|
Sensors:
|
||||||
|
</Typography>
|
||||||
|
{!this.noSensors() && (
|
||||||
|
<Table size="small" padding="default">
|
||||||
|
<TableHead>
|
||||||
|
<TableRow>
|
||||||
|
<StyledTableCell>ID</StyledTableCell>
|
||||||
|
<StyledTableCell align="left">Temperature</StyledTableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableHead>
|
||||||
|
<TableBody>
|
||||||
|
{data.sensors.map(sensorData => (
|
||||||
|
<TableRow key={sensorData.id}>
|
||||||
|
<TableCell component="th" scope="row">
|
||||||
|
{sensorData.id}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell align="left">
|
||||||
|
{sensorData.temp}°C
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)}
|
||||||
|
{this.noSensors() &&
|
||||||
|
(
|
||||||
|
<Box color="warning.main" p={0} mt={0} mb={0}>
|
||||||
|
<Typography variant="body1">
|
||||||
|
No external temperature sensors detected.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</TableContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderScanDevicesDialog() {
|
renderScanDevicesDialog() {
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
@@ -252,8 +302,9 @@ class EMSESPDevicesForm extends Component<EMSESPDevicesFormProps, EMSESPDevicesF
|
|||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<br></br>
|
<br></br>
|
||||||
{this.createTableItems()}
|
{this.createDeviceItems()}
|
||||||
{this.renderDeviceData()}
|
{this.renderDeviceData()}
|
||||||
|
{this.createSensorItems()}
|
||||||
<br></br>
|
<br></br>
|
||||||
<Box display="flex" flexWrap="wrap">
|
<Box display="flex" flexWrap="wrap">
|
||||||
<Box flexGrow={1} padding={1}>
|
<Box flexGrow={1} padding={1}>
|
||||||
|
|||||||
@@ -33,8 +33,14 @@ export interface Device {
|
|||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Sensor {
|
||||||
|
id: string;
|
||||||
|
temp: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EMSESPDevices {
|
export interface EMSESPDevices {
|
||||||
devices: Device[];
|
devices: Device[];
|
||||||
|
sensors: Sensor[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeviceData {
|
export interface DeviceData {
|
||||||
|
|||||||
@@ -50,14 +50,23 @@ void EMSESPDevicesService::all_devices(AsyncWebServerRequest * request) {
|
|||||||
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 deviceRoot = devices.createNestedObject();
|
JsonObject obj = devices.createNestedObject();
|
||||||
deviceRoot["id"] = emsdevice->unique_id();
|
obj["id"] = emsdevice->unique_id();
|
||||||
deviceRoot["type"] = emsdevice->device_type_name();
|
obj["type"] = emsdevice->device_type_name();
|
||||||
deviceRoot["brand"] = emsdevice->brand_to_string();
|
obj["brand"] = emsdevice->brand_to_string();
|
||||||
deviceRoot["name"] = emsdevice->name();
|
obj["name"] = emsdevice->name();
|
||||||
deviceRoot["deviceid"] = emsdevice->device_id();
|
obj["deviceid"] = emsdevice->device_id();
|
||||||
deviceRoot["productid"] = emsdevice->product_id();
|
obj["productid"] = emsdevice->product_id();
|
||||||
deviceRoot["version"] = emsdevice->version();
|
obj["version"] = emsdevice->version();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray sensors = root.createNestedArray("sensors");
|
||||||
|
if (!EMSESP::sensor_devices().empty()) {
|
||||||
|
for (const auto & sensor : EMSESP::sensor_devices()) {
|
||||||
|
JsonObject obj = sensors.createNestedObject();
|
||||||
|
obj["id"] = sensor.to_string();
|
||||||
|
obj["temp"] = sensor.temperature_c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// show Dallas sensors
|
// show Dallas temperature sensors
|
||||||
void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||||
if (sensor_devices().empty()) {
|
if (sensor_devices().empty()) {
|
||||||
return;
|
return;
|
||||||
@@ -257,7 +257,7 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
|||||||
char valuestr[8] = {0}; // for formatting temp
|
char valuestr[8] = {0}; // for formatting temp
|
||||||
shell.printfln(F("External temperature sensors:"));
|
shell.printfln(F("External temperature sensors:"));
|
||||||
for (const auto & device : sensor_devices()) {
|
for (const auto & device : sensor_devices()) {
|
||||||
shell.printfln(F(" Sensor ID %s: %s°C"), device.to_string().c_str(), Helpers::render_value(valuestr, device.temperature_c_, 2));
|
shell.printfln(F(" ID: %s, Temperature: %s°C"), device.to_string().c_str(), Helpers::render_value(valuestr, device.temperature_c, 2));
|
||||||
}
|
}
|
||||||
shell.println();
|
shell.println();
|
||||||
}
|
}
|
||||||
@@ -778,7 +778,7 @@ void EMSESP::loop() {
|
|||||||
// if we're doing an OTA upload, skip MQTT and EMS
|
// if we're doing an OTA upload, skip MQTT and EMS
|
||||||
if (system_.upload_status()) {
|
if (system_.upload_status()) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
delay(1); // slow down OTA update to avoid getting killed by task watchdog (task_wdt)
|
delay(10); // slow down OTA update to avoid getting killed by task watchdog (task_wdt)
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ void Sensors::loop() {
|
|||||||
case TYPE_DS1822:
|
case TYPE_DS1822:
|
||||||
case TYPE_DS1825:
|
case TYPE_DS1825:
|
||||||
found_.emplace_back(addr);
|
found_.emplace_back(addr);
|
||||||
found_.back().temperature_c_ = get_temperature_c(addr);
|
found_.back().temperature_c = get_temperature_c(addr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// comment out for debugging
|
// comment out for debugging
|
||||||
@@ -253,7 +253,7 @@ void Sensors::publish_values() {
|
|||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
for (const auto & device : devices_) {
|
for (const auto & device : devices_) {
|
||||||
char s[5];
|
char s[5];
|
||||||
doc["temp"] = Helpers::render_value(s, device.temperature_c_, 2);
|
doc["temp"] = Helpers::render_value(s, device.temperature_c, 2);
|
||||||
char topic[60]; // sensors{1-n}
|
char topic[60]; // sensors{1-n}
|
||||||
strlcpy(topic, "sensor_", 50); // create topic, e.g. home/ems-esp/sensor_28-EA41-9497-0E03-5F
|
strlcpy(topic, "sensor_", 50); // create topic, e.g. home/ems-esp/sensor_28-EA41-9497-0E03-5F
|
||||||
strlcat(topic, device.to_string().c_str(), 60);
|
strlcat(topic, device.to_string().c_str(), 60);
|
||||||
@@ -279,7 +279,7 @@ void Sensors::publish_values() {
|
|||||||
for (const auto & device : devices_) {
|
for (const auto & device : devices_) {
|
||||||
if (mqtt_format_ == MQTT_format::CUSTOM) {
|
if (mqtt_format_ == MQTT_format::CUSTOM) {
|
||||||
char s[5];
|
char s[5];
|
||||||
doc[device.to_string()] = Helpers::render_value(s, device.temperature_c_, 2);
|
doc[device.to_string()] = Helpers::render_value(s, device.temperature_c, 2);
|
||||||
} else {
|
} else {
|
||||||
char sensorID[10]; // sensor{1-n}
|
char sensorID[10]; // sensor{1-n}
|
||||||
strlcpy(sensorID, "sensor", 10);
|
strlcpy(sensorID, "sensor", 10);
|
||||||
@@ -287,7 +287,7 @@ void Sensors::publish_values() {
|
|||||||
strlcat(sensorID, Helpers::itoa(s, i++), 10);
|
strlcat(sensorID, Helpers::itoa(s, i++), 10);
|
||||||
JsonObject dataSensor = doc.createNestedObject(sensorID);
|
JsonObject dataSensor = doc.createNestedObject(sensorID);
|
||||||
dataSensor["id"] = device.to_string();
|
dataSensor["id"] = device.to_string();
|
||||||
dataSensor["temp"] = Helpers::render_value(s, device.temperature_c_, 2);
|
dataSensor["temp"] = Helpers::render_value(s, device.temperature_c, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Sensors {
|
|||||||
uint64_t id() const;
|
uint64_t id() const;
|
||||||
std::string to_string() const;
|
std::string to_string() const;
|
||||||
|
|
||||||
float temperature_c_ = NAN;
|
float temperature_c = NAN;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint64_t id_;
|
const uint64_t id_;
|
||||||
|
|||||||
Reference in New Issue
Block a user