mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Merge pull request #475 from proddy/dev
Changes to Table (sorting, format, search)
This commit is contained in:
1742
interface/package-lock.json
generated
1742
interface/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,27 +7,28 @@
|
|||||||
"@emotion/react": "^11.9.0",
|
"@emotion/react": "^11.9.0",
|
||||||
"@emotion/styled": "^11.8.1",
|
"@emotion/styled": "^11.8.1",
|
||||||
"@msgpack/msgpack": "^2.7.2",
|
"@msgpack/msgpack": "^2.7.2",
|
||||||
"@mui/icons-material": "^5.6.0",
|
"@mui/icons-material": "^5.6.2",
|
||||||
"@mui/material": "^5.6.0",
|
"@mui/material": "^5.6.2",
|
||||||
"@types/lodash": "^4.14.181",
|
"@table-library/react-table-library": "^3.1.0",
|
||||||
"@types/node": "^17.0.23",
|
"@types/lodash": "^4.14.182",
|
||||||
|
"@types/node": "^17.0.26",
|
||||||
"@types/react": "^17.0.43",
|
"@types/react": "^17.0.43",
|
||||||
"@types/react-dom": "^17.0.14",
|
"@types/react-dom": "^17.0.14",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"async-validator": "^4.0.7",
|
"async-validator": "^4.0.8",
|
||||||
"axios": "^0.26.1",
|
"axios": "^0.26.1",
|
||||||
"http-proxy-middleware": "^2.0.4",
|
"http-proxy-middleware": "^2.0.6",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"notistack": "^2.0.3",
|
"notistack": "^2.0.4",
|
||||||
"parse-ms": "^3.0.0",
|
"parse-ms": "^3.0.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
|
||||||
"react-app-rewired": "^2.2.1",
|
"react-app-rewired": "^2.2.1",
|
||||||
"react-dropzone": "^12.0.4",
|
"react-dom": "^17.0.2",
|
||||||
|
"react-dropzone": "^12.0.5",
|
||||||
"react-icons": "^4.3.1",
|
"react-icons": "^4.3.1",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"react-scripts": "5.0.0",
|
"react-scripts": "5.0.1",
|
||||||
"sockette": "^2.0.6",
|
"sockette": "^2.0.6",
|
||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
ValidatedPasswordField,
|
ValidatedPasswordField,
|
||||||
ValidatedTextField
|
ValidatedTextField
|
||||||
} from '../../components';
|
} from '../../components';
|
||||||
|
|
||||||
import { APProvisionMode, APSettings } from '../../types';
|
import { APProvisionMode, APSettings } from '../../types';
|
||||||
import { numberValue, updateValue, useRest } from '../../utils';
|
import { numberValue, updateValue, useRest } from '../../utils';
|
||||||
import * as APApi from '../../api/ap';
|
import * as APApi from '../../api/ap';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC, useContext, useState } from 'react';
|
import { FC, useContext, useState } from 'react';
|
||||||
|
|
||||||
import { Button, IconButton, Table, TableBody, TableCell, TableFooter, TableHead, TableRow } from '@mui/material';
|
import { Button, IconButton, Box } from '@mui/material';
|
||||||
import SaveIcon from '@mui/icons-material/Save';
|
import SaveIcon from '@mui/icons-material/Save';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import PersonAddIcon from '@mui/icons-material/PersonAdd';
|
import PersonAddIcon from '@mui/icons-material/PersonAdd';
|
||||||
@@ -9,6 +9,10 @@ import CheckIcon from '@mui/icons-material/Check';
|
|||||||
import CloseIcon from '@mui/icons-material/Close';
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
import VpnKeyIcon from '@mui/icons-material/VpnKey';
|
import VpnKeyIcon from '@mui/icons-material/VpnKey';
|
||||||
|
|
||||||
|
import { Table } from '@table-library/react-table-library/table';
|
||||||
|
import { useTheme } from '@table-library/react-table-library/theme';
|
||||||
|
import { Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table';
|
||||||
|
|
||||||
import * as SecurityApi from '../../api/security';
|
import * as SecurityApi from '../../api/security';
|
||||||
import { SecuritySettings, User } from '../../types';
|
import { SecuritySettings, User } from '../../types';
|
||||||
import { ButtonRow, FormLoader, MessageBox, SectionContent } from '../../components';
|
import { ButtonRow, FormLoader, MessageBox, SectionContent } from '../../components';
|
||||||
@@ -19,16 +23,6 @@ import { AuthenticatedContext } from '../../contexts/authentication';
|
|||||||
import GenerateToken from './GenerateToken';
|
import GenerateToken from './GenerateToken';
|
||||||
import UserForm from './UserForm';
|
import UserForm from './UserForm';
|
||||||
|
|
||||||
function compareUsers(a: User, b: User) {
|
|
||||||
if (a.username < b.username) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.username > b.username) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ManageUsersForm: FC = () => {
|
const ManageUsersForm: FC = () => {
|
||||||
const { loadData, saving, data, setData, saveData, errorMessage } = useRest<SecuritySettings>({
|
const { loadData, saving, data, setData, saveData, errorMessage } = useRest<SecuritySettings>({
|
||||||
read: SecurityApi.readSecuritySettings,
|
read: SecurityApi.readSecuritySettings,
|
||||||
@@ -40,6 +34,45 @@ const ManageUsersForm: FC = () => {
|
|||||||
const [generatingToken, setGeneratingToken] = useState<string>();
|
const [generatingToken, setGeneratingToken] = useState<string>();
|
||||||
const authenticatedContext = useContext(AuthenticatedContext);
|
const authenticatedContext = useContext(AuthenticatedContext);
|
||||||
|
|
||||||
|
const table_theme = useTheme({
|
||||||
|
BaseRow: `
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
`,
|
||||||
|
HeaderRow: `
|
||||||
|
text-transform: uppercase;
|
||||||
|
background-color: black;
|
||||||
|
color: #90CAF9;
|
||||||
|
border-bottom: 1px solid #e0e0e0;
|
||||||
|
`,
|
||||||
|
Row: `
|
||||||
|
&:nth-of-type(odd) {
|
||||||
|
background-color: #303030;
|
||||||
|
}
|
||||||
|
&:nth-of-type(even) {
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
}
|
||||||
|
border-top: 1px solid #565656;
|
||||||
|
border-bottom: 1px solid #565656;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
&:not(:last-of-type) {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
}
|
||||||
|
&:not(:first-of-type) {
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
BaseCell: `
|
||||||
|
border-top: 1px solid transparent;
|
||||||
|
border-right: 1px solid transparent;
|
||||||
|
border-bottom: 1px solid transparent;
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
const content = () => {
|
const content = () => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return <FormLoader onRetry={loadData} errorMessage={errorMessage} />;
|
return <FormLoader onRetry={loadData} errorMessage={errorMessage} />;
|
||||||
@@ -48,13 +81,14 @@ const ManageUsersForm: FC = () => {
|
|||||||
const noAdminConfigured = () => !data.users.find((u) => u.admin);
|
const noAdminConfigured = () => !data.users.find((u) => u.admin);
|
||||||
|
|
||||||
const removeUser = (toRemove: User) => {
|
const removeUser = (toRemove: User) => {
|
||||||
const users = data.users.filter((u) => u.username !== toRemove.username);
|
const users = data.users.filter((u) => u.id !== toRemove.id);
|
||||||
setData({ ...data, users });
|
setData({ ...data, users });
|
||||||
};
|
};
|
||||||
|
|
||||||
const createUser = () => {
|
const createUser = () => {
|
||||||
setCreating(true);
|
setCreating(true);
|
||||||
setUser({
|
setUser({
|
||||||
|
id: '',
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
admin: true
|
admin: true
|
||||||
@@ -72,7 +106,7 @@ const ManageUsersForm: FC = () => {
|
|||||||
|
|
||||||
const doneEditingUser = () => {
|
const doneEditingUser = () => {
|
||||||
if (user) {
|
if (user) {
|
||||||
const users = [...data.users.filter((u) => u.username !== user.username), user];
|
const users = [...data.users.filter((u) => u.id !== user.id), user];
|
||||||
setData({ ...data, users });
|
setData({ ...data, users });
|
||||||
setUser(undefined);
|
setUser(undefined);
|
||||||
}
|
}
|
||||||
@@ -82,8 +116,8 @@ const ManageUsersForm: FC = () => {
|
|||||||
setGeneratingToken(undefined);
|
setGeneratingToken(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateToken = (username: string) => {
|
const generateToken = (id: string) => {
|
||||||
setGeneratingToken(username);
|
setGeneratingToken(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
@@ -93,66 +127,71 @@ const ManageUsersForm: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Table size="small">
|
<Table data={{ nodes: data.users }} theme={table_theme}>
|
||||||
<TableHead>
|
{(tableList: any) => (
|
||||||
<TableRow>
|
<>
|
||||||
<TableCell>Username</TableCell>
|
<Header>
|
||||||
<TableCell align="center">is Admin?</TableCell>
|
<HeaderRow>
|
||||||
<TableCell />
|
<HeaderCell>USERNAME</HeaderCell>
|
||||||
</TableRow>
|
<HeaderCell>IS ADMIN</HeaderCell>
|
||||||
</TableHead>
|
<HeaderCell />
|
||||||
<TableBody>
|
</HeaderRow>
|
||||||
{data.users.sort(compareUsers).map((u) => (
|
</Header>
|
||||||
<TableRow key={u.username}>
|
<Body>
|
||||||
<TableCell component="th" scope="row">
|
{tableList.map((u: User, index: number) => (
|
||||||
{u.username}
|
<Row key={u.id} item={u}>
|
||||||
</TableCell>
|
<Cell>{u.id}</Cell>
|
||||||
<TableCell align="center">{u.admin ? <CheckIcon /> : <CloseIcon />}</TableCell>
|
<Cell>{u.admin ? <CheckIcon /> : <CloseIcon />}</Cell>
|
||||||
<TableCell align="center">
|
<Cell>
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
disabled={!authenticatedContext.me.admin}
|
disabled={!authenticatedContext.me.admin}
|
||||||
aria-label="Generate Token"
|
aria-label="Generate Token"
|
||||||
onClick={() => generateToken(u.username)}
|
onClick={() => generateToken(u.id)}
|
||||||
>
|
>
|
||||||
<VpnKeyIcon />
|
<VpnKeyIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton size="small" aria-label="Delete" onClick={() => removeUser(u)}>
|
<IconButton size="small" aria-label="Delete" onClick={() => removeUser(u)}>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton size="small" aria-label="Edit" onClick={() => editUser(u)}>
|
<IconButton size="small" aria-label="Edit" onClick={() => editUser(u)}>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</TableCell>
|
</Cell>
|
||||||
</TableRow>
|
</Row>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</Body>
|
||||||
<TableFooter>
|
</>
|
||||||
<TableRow>
|
)}
|
||||||
<TableCell colSpan={2} />
|
|
||||||
<TableCell align="center">
|
|
||||||
<Button startIcon={<PersonAddIcon />} variant="outlined" color="secondary" onClick={createUser}>
|
|
||||||
Add
|
|
||||||
</Button>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
</TableFooter>
|
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
{noAdminConfigured() && (
|
{noAdminConfigured() && (
|
||||||
<MessageBox level="warning" message="You must have at least one admin user configured" my={2} />
|
<MessageBox level="warning" message="You must have at least one admin user configured" my={2} />
|
||||||
)}
|
)}
|
||||||
<ButtonRow>
|
|
||||||
<Button
|
<Box display="flex" flexWrap="wrap">
|
||||||
startIcon={<SaveIcon />}
|
<Box flexGrow={1} sx={{ '& button': { mt: 2 } }}>
|
||||||
disabled={saving || noAdminConfigured()}
|
<Button
|
||||||
variant="outlined"
|
startIcon={<SaveIcon />}
|
||||||
color="primary"
|
disabled={saving || noAdminConfigured()}
|
||||||
type="submit"
|
variant="outlined"
|
||||||
onClick={onSubmit}
|
color="primary"
|
||||||
>
|
type="submit"
|
||||||
Save
|
onClick={onSubmit}
|
||||||
</Button>
|
>
|
||||||
</ButtonRow>
|
Save
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box flexWrap="nowrap" whiteSpace="nowrap">
|
||||||
|
<ButtonRow>
|
||||||
|
<Button startIcon={<PersonAddIcon />} variant="outlined" color="secondary" onClick={createUser}>
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
</ButtonRow>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
<GenerateToken username={generatingToken} onClose={closeGenerateToken} />
|
<GenerateToken username={generatingToken} onClose={closeGenerateToken} />
|
||||||
<UserForm
|
<UserForm
|
||||||
user={user}
|
user={user}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,25 +3,23 @@ import { useSnackbar } from 'notistack';
|
|||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Button,
|
Button,
|
||||||
Table,
|
|
||||||
TableContainer,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableRow,
|
|
||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
ListItemAvatar,
|
ListItemAvatar,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
Theme,
|
|
||||||
useTheme,
|
|
||||||
Box,
|
Box,
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
|
Theme,
|
||||||
|
useTheme
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
|
import { Table } from '@table-library/react-table-library/table';
|
||||||
|
import { useTheme as tableTheme } from '@table-library/react-table-library/theme';
|
||||||
|
import { Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table';
|
||||||
|
|
||||||
import DeviceHubIcon from '@mui/icons-material/DeviceHub';
|
import DeviceHubIcon from '@mui/icons-material/DeviceHub';
|
||||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||||
import PermScanWifiIcon from '@mui/icons-material/PermScanWifi';
|
import PermScanWifiIcon from '@mui/icons-material/PermScanWifi';
|
||||||
@@ -32,14 +30,12 @@ import { AuthenticatedContext } from '../contexts/authentication';
|
|||||||
|
|
||||||
import { ButtonRow, FormLoader, SectionContent } from '../components';
|
import { ButtonRow, FormLoader, SectionContent } from '../components';
|
||||||
|
|
||||||
import { Status, busConnectionStatus } from './types';
|
import { Status, busConnectionStatus, Stat } from './types';
|
||||||
|
|
||||||
import { formatDurationSec, pluralize } from '../utils';
|
import { formatDurationSec, pluralize, extractErrorMessage, useRest } from '../utils';
|
||||||
|
|
||||||
import * as EMSESP from './api';
|
import * as EMSESP from './api';
|
||||||
|
|
||||||
import { extractErrorMessage, useRest } from '../utils';
|
|
||||||
|
|
||||||
export const isConnected = ({ status }: Status) => status !== busConnectionStatus.BUS_STATUS_OFFLINE;
|
export const isConnected = ({ status }: Status) => status !== busConnectionStatus.BUS_STATUS_OFFLINE;
|
||||||
|
|
||||||
const busStatusHighlight = ({ status }: Status, theme: Theme) => {
|
const busStatusHighlight = ({ status }: Status, theme: Theme) => {
|
||||||
@@ -60,7 +56,7 @@ const busStatus = ({ status }: Status) => {
|
|||||||
case busConnectionStatus.BUS_STATUS_CONNECTED:
|
case busConnectionStatus.BUS_STATUS_CONNECTED:
|
||||||
return 'Connected';
|
return 'Connected';
|
||||||
case busConnectionStatus.BUS_STATUS_TX_ERRORS:
|
case busConnectionStatus.BUS_STATUS_TX_ERRORS:
|
||||||
return 'Tx issues - try a different Tx-Mode';
|
return 'Tx issues - try a different Tx Mode';
|
||||||
case busConnectionStatus.BUS_STATUS_OFFLINE:
|
case busConnectionStatus.BUS_STATUS_OFFLINE:
|
||||||
return 'Disconnected';
|
return 'Disconnected';
|
||||||
default:
|
default:
|
||||||
@@ -68,41 +64,17 @@ const busStatus = ({ status }: Status) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatRow = (name: string, success: number, fail: number, quality: number) => {
|
const showQuality = (stat: Stat) => {
|
||||||
if (success === 0 && fail === 0) {
|
if (stat.q === 0 || stat.s + stat.f === 0) {
|
||||||
return (
|
return;
|
||||||
<TableRow>
|
|
||||||
<TableCell sx={{ color: 'gray' }}>{name}</TableCell>
|
|
||||||
<TableCell />
|
|
||||||
<TableCell />
|
|
||||||
<TableCell />
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
if (stat.q === 100) {
|
||||||
return (
|
return <div style={{ color: '#00FF7F' }}>{stat.q}%</div>;
|
||||||
<TableRow>
|
|
||||||
<TableCell>{name}</TableCell>
|
|
||||||
<TableCell>{Intl.NumberFormat().format(success)}</TableCell>
|
|
||||||
<TableCell>{Intl.NumberFormat().format(fail)}</TableCell>
|
|
||||||
{showQuality(quality)}
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const showQuality = (quality: number) => {
|
|
||||||
if (quality === 0) {
|
|
||||||
return <TableCell />;
|
|
||||||
}
|
}
|
||||||
|
if (stat.q >= 95) {
|
||||||
if (quality === 100) {
|
return <div style={{ color: 'orange' }}>{stat.q}%</div>;
|
||||||
return <TableCell sx={{ color: '#00FF7F' }}>{quality}%</TableCell>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quality >= 95) {
|
|
||||||
return <TableCell sx={{ color: 'orange' }}>{quality}%</TableCell>;
|
|
||||||
} else {
|
} else {
|
||||||
return <TableCell sx={{ color: 'red' }}>{quality}%</TableCell>;
|
return <div style={{ color: 'red' }}>{stat.q}%</div>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,6 +87,48 @@ const DashboardStatus: FC = () => {
|
|||||||
|
|
||||||
const { me } = useContext(AuthenticatedContext);
|
const { me } = useContext(AuthenticatedContext);
|
||||||
|
|
||||||
|
const stats_theme = tableTheme({
|
||||||
|
BaseRow: `
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
`,
|
||||||
|
HeaderRow: `
|
||||||
|
text-transform: uppercase;
|
||||||
|
background-color: black;
|
||||||
|
color: #90CAF9;
|
||||||
|
border-bottom: 1px solid #e0e0e0;
|
||||||
|
`,
|
||||||
|
Row: `
|
||||||
|
&:nth-of-type(odd) {
|
||||||
|
background-color: #303030;
|
||||||
|
}
|
||||||
|
&:nth-of-type(even) {
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
}
|
||||||
|
border-top: 1px solid #565656;
|
||||||
|
border-bottom: 1px solid #565656;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
&:not(:last-of-type) {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
}
|
||||||
|
&:not(:first-of-type) {
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
BaseCell: `
|
||||||
|
border-top: 1px solid transparent;
|
||||||
|
border-right: 1px solid transparent;
|
||||||
|
border-bottom: 1px solid transparent;
|
||||||
|
&:nth-of-type(1) {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => loadData(), 30000);
|
const timer = setInterval(() => loadData(), 30000);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -183,27 +197,30 @@ const DashboardStatus: FC = () => {
|
|||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Box m={3}></Box>
|
<Box m={3}></Box>
|
||||||
<TableContainer>
|
<Table data={{ nodes: data.stats }} theme={stats_theme} layout={{ custom: true }}>
|
||||||
<Table size="small">
|
{(tableList: any) => (
|
||||||
<TableHead>
|
<>
|
||||||
<TableRow>
|
<Header>
|
||||||
<TableCell></TableCell>
|
<HeaderRow>
|
||||||
<TableCell>SUCCESS</TableCell>
|
<HeaderCell></HeaderCell>
|
||||||
<TableCell>FAIL</TableCell>
|
<HeaderCell>SUCCESS</HeaderCell>
|
||||||
<TableCell>QUALITY</TableCell>
|
<HeaderCell>FAIL</HeaderCell>
|
||||||
</TableRow>
|
<HeaderCell>QUALITY</HeaderCell>
|
||||||
</TableHead>
|
</HeaderRow>
|
||||||
<TableBody>
|
</Header>
|
||||||
{formatRow('EMS Telegrams Received (Rx)', data.rx_received, data.rx_fails, data.rx_quality)}
|
<Body>
|
||||||
{formatRow('EMS Reads (Tx)', data.tx_reads, data.tx_read_fails, data.tx_read_quality)}
|
{tableList.map((stat: Stat) => (
|
||||||
{formatRow('EMS Writes (Tx)', data.tx_writes, data.tx_write_fails, data.tx_write_quality)}
|
<Row key={stat.id} item={stat}>
|
||||||
{formatRow('Temperature Sensor Reads', data.sensor_reads, data.sensor_fails, data.sensor_quality)}
|
<Cell>{stat.id}</Cell>
|
||||||
{formatRow('Analog Sensor Reads', data.analog_reads, data.analog_fails, data.analog_quality)}
|
<Cell>{Intl.NumberFormat().format(stat.s)}</Cell>
|
||||||
{formatRow('MQTT Publishes', data.mqtt_count, data.mqtt_fails, data.mqtt_quality)}
|
<Cell>{Intl.NumberFormat().format(stat.f)}</Cell>
|
||||||
{formatRow('API Calls', data.api_calls, data.api_fails, data.api_quality)}
|
<Cell>{showQuality(stat)}</Cell>
|
||||||
</TableBody>
|
</Row>
|
||||||
</Table>
|
))}
|
||||||
</TableContainer>
|
</Body>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Table>
|
||||||
</List>
|
</List>
|
||||||
{renderScanDialog()}
|
{renderScanDialog()}
|
||||||
<Box display="flex" flexWrap="wrap">
|
<Box display="flex" flexWrap="wrap">
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import { FC, useState, useEffect, useCallback } from 'react';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableHead,
|
|
||||||
TableRow,
|
|
||||||
Typography,
|
Typography,
|
||||||
Box,
|
Box,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
@@ -14,22 +10,31 @@ import {
|
|||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
ToggleButton,
|
ToggleButton,
|
||||||
ToggleButtonGroup
|
ToggleButtonGroup,
|
||||||
|
Tooltip,
|
||||||
|
Grid,
|
||||||
|
TextField
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
|
import { Table } from '@table-library/react-table-library/table';
|
||||||
|
import { useTheme } from '@table-library/react-table-library/theme';
|
||||||
import { styled } from '@mui/material/styles';
|
import { useSort, SortToggleType } from '@table-library/react-table-library/sort';
|
||||||
|
import { Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table';
|
||||||
|
|
||||||
import { useSnackbar } from 'notistack';
|
import { useSnackbar } from 'notistack';
|
||||||
|
|
||||||
import SaveIcon from '@mui/icons-material/Save';
|
import SaveIcon from '@mui/icons-material/Save';
|
||||||
import CancelIcon from '@mui/icons-material/Cancel';
|
import CancelIcon from '@mui/icons-material/Cancel';
|
||||||
import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined';
|
import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined';
|
||||||
import FavoriteBorderOutlinedIcon from '@mui/icons-material/FavoriteBorderOutlined';
|
import StarIcon from '@mui/icons-material/Star';
|
||||||
import VisibilityOffOutlinedIcon from '@mui/icons-material/VisibilityOffOutlined';
|
import VisibilityOffOutlinedIcon from '@mui/icons-material/VisibilityOffOutlined';
|
||||||
import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined';
|
import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined';
|
||||||
import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore';
|
import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore';
|
||||||
|
import KeyboardArrowUpOutlinedIcon from '@mui/icons-material/KeyboardArrowUpOutlined';
|
||||||
|
import KeyboardArrowDownOutlinedIcon from '@mui/icons-material/KeyboardArrowDownOutlined';
|
||||||
|
import UnfoldMoreOutlinedIcon from '@mui/icons-material/UnfoldMoreOutlined';
|
||||||
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
||||||
|
|
||||||
import { ButtonRow, FormLoader, ValidatedTextField, SectionContent } from '../components';
|
import { ButtonRow, FormLoader, ValidatedTextField, SectionContent } from '../components';
|
||||||
|
|
||||||
@@ -37,26 +42,116 @@ import * as EMSESP from './api';
|
|||||||
|
|
||||||
import { extractErrorMessage } from '../utils';
|
import { extractErrorMessage } from '../utils';
|
||||||
|
|
||||||
import { DeviceShort, Devices, DeviceEntity } from './types';
|
import { DeviceShort, Devices, DeviceEntity, DeviceEntityMask } from './types';
|
||||||
|
|
||||||
const StyledTableCell = styled(TableCell)(({ theme }) => ({
|
|
||||||
[`&.${tableCellClasses.head}`]: {
|
|
||||||
backgroundColor: '#607d8b'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
const SettingsCustomization: FC = () => {
|
const SettingsCustomization: FC = () => {
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const [deviceEntities, setDeviceEntities] = useState<DeviceEntity[]>();
|
const [deviceEntities, setDeviceEntities] = useState<DeviceEntity[]>([{ id: '', v: 0, s: '', m: 0, w: false }]);
|
||||||
const [devices, setDevices] = useState<Devices>();
|
const [devices, setDevices] = useState<Devices>();
|
||||||
const [errorMessage, setErrorMessage] = useState<string>();
|
const [errorMessage, setErrorMessage] = useState<string>();
|
||||||
const [selectedDevice, setSelectedDevice] = useState<number>(0);
|
const [selectedDevice, setSelectedDevice] = useState<number>(0);
|
||||||
const [confirmReset, setConfirmReset] = useState<boolean>(false);
|
const [confirmReset, setConfirmReset] = useState<boolean>(false);
|
||||||
|
const [selectedFilters, setSelectedFilters] = useState<number>(0);
|
||||||
|
const [search, setSearch] = useState('');
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const [masks, setMasks] = useState(() => ['']);
|
const [masks, setMasks] = useState(() => ['']);
|
||||||
|
|
||||||
|
const entities_theme = useTheme({
|
||||||
|
BaseRow: `
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
height: 32px;
|
||||||
|
`,
|
||||||
|
HeaderRow: `
|
||||||
|
text-transform: uppercase;
|
||||||
|
background-color: black;
|
||||||
|
border-bottom: 1px solid #e0e0e0;
|
||||||
|
color: #90CAF9;
|
||||||
|
font-weight: 500;
|
||||||
|
`,
|
||||||
|
Row: `
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
border-top: 1px solid #565656;
|
||||||
|
border-bottom: 1px solid #565656;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
&:not(:last-of-type) {
|
||||||
|
margin-bottom: -1px;
|
||||||
|
}
|
||||||
|
&:not(:first-of-type) {
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
z-index: 2;
|
||||||
|
color: white;
|
||||||
|
border-top: 1px solid #177ac9;
|
||||||
|
border-bottom: 1px solid #177ac9;
|
||||||
|
},
|
||||||
|
&.tr.tr-body.row-select.row-select-single-selected, &.tr.tr-body.row-select.row-select-selected {
|
||||||
|
background-color: #3d4752;
|
||||||
|
color: white;
|
||||||
|
font-weight: normal;
|
||||||
|
z-index: 2;
|
||||||
|
border-top: 1px solid #177ac9;
|
||||||
|
border-bottom: 1px solid #177ac9;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
BaseCell: `
|
||||||
|
padding-left: 8px;
|
||||||
|
border-top: 1px solid transparent;
|
||||||
|
border-right: 1px solid transparent;
|
||||||
|
border-bottom: 1px solid transparent;
|
||||||
|
&:nth-of-type(1) {
|
||||||
|
left: 0px;
|
||||||
|
min-width: 124px;
|
||||||
|
width: 124px;
|
||||||
|
padding-left: 0px;
|
||||||
|
|
||||||
|
}
|
||||||
|
&:nth-of-type(2) {
|
||||||
|
min-width: 70%;
|
||||||
|
width: 70%;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
HeaderCell: `
|
||||||
|
padding-left: 0px;
|
||||||
|
&:nth-of-type(1) {
|
||||||
|
padding-left: 24px;
|
||||||
|
}
|
||||||
|
&:nth-of-type(3) {
|
||||||
|
border-left: 1px solid #565656;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSortIcon = (state: any, sortKey: any) => {
|
||||||
|
if (state.sortKey === sortKey && state.reverse) {
|
||||||
|
return <KeyboardArrowDownOutlinedIcon />;
|
||||||
|
}
|
||||||
|
if (state.sortKey === sortKey && !state.reverse) {
|
||||||
|
return <KeyboardArrowUpOutlinedIcon />;
|
||||||
|
}
|
||||||
|
return <UnfoldMoreOutlinedIcon />;
|
||||||
|
};
|
||||||
|
|
||||||
|
const entity_sort = useSort(
|
||||||
|
{ nodes: deviceEntities },
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
sortIcon: {
|
||||||
|
iconDefault: <UnfoldMoreOutlinedIcon />,
|
||||||
|
iconUp: <KeyboardArrowUpOutlinedIcon />,
|
||||||
|
iconDown: <KeyboardArrowDownOutlinedIcon />
|
||||||
|
},
|
||||||
|
sortToggleType: SortToggleType.AlternateWithReset,
|
||||||
|
sortFns: {
|
||||||
|
NAME: (array) => array.sort((a, b) => a.id.localeCompare(b.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const fetchDevices = useCallback(async () => {
|
const fetchDevices = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setDevices((await EMSESP.readDevices()).data);
|
setDevices((await EMSESP.readDevices()).data);
|
||||||
@@ -93,47 +188,112 @@ const SettingsCustomization: FC = () => {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getMaskNumber = (newMask: string[]) => {
|
||||||
|
var new_mask = 0;
|
||||||
|
for (let entry of newMask) {
|
||||||
|
new_mask |= Number(entry);
|
||||||
|
}
|
||||||
|
return new_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMaskString = (m: number) => {
|
||||||
|
var new_masks = [];
|
||||||
|
if ((m & 1) === 1) {
|
||||||
|
new_masks.push('1');
|
||||||
|
}
|
||||||
|
if ((m & 2) === 2) {
|
||||||
|
new_masks.push('2');
|
||||||
|
}
|
||||||
|
if ((m & 4) === 4) {
|
||||||
|
new_masks.push('4');
|
||||||
|
}
|
||||||
|
if ((m & 8) === 8) {
|
||||||
|
new_masks.push('8');
|
||||||
|
}
|
||||||
|
return new_masks;
|
||||||
|
};
|
||||||
|
|
||||||
|
const maskDisabled = (set: boolean) => {
|
||||||
|
setDeviceEntities(
|
||||||
|
deviceEntities.map(function (de) {
|
||||||
|
if ((de.m & selectedFilters || !selectedFilters) && de.id.toLowerCase().includes(search.toLowerCase())) {
|
||||||
|
return {
|
||||||
|
...de,
|
||||||
|
m: set
|
||||||
|
? de.m | (DeviceEntityMask.DV_API_MQTT_EXCLUDE | DeviceEntityMask.DV_WEB_EXCLUDE)
|
||||||
|
: de.m & ~(DeviceEntityMask.DV_API_MQTT_EXCLUDE | DeviceEntityMask.DV_WEB_EXCLUDE)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return de;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function compareDevices(a: DeviceShort, b: DeviceShort) {
|
||||||
|
if (a.s < b.s) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (a.s > b.s) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const changeSelectedDevice = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const selected_device = parseInt(event.target.value, 10);
|
||||||
|
setSelectedDevice(selected_device);
|
||||||
|
fetchDeviceEntities(selected_device);
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetCustomization = async () => {
|
||||||
|
try {
|
||||||
|
await EMSESP.resetCustomizations();
|
||||||
|
enqueueSnackbar('All customizations have been removed. Restarting...', { variant: 'info' });
|
||||||
|
} catch (error: any) {
|
||||||
|
enqueueSnackbar(extractErrorMessage(error, 'Problem resetting customizations'), { variant: 'error' });
|
||||||
|
} finally {
|
||||||
|
setConfirmReset(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveCustomization = async () => {
|
||||||
|
if (deviceEntities && selectedDevice) {
|
||||||
|
const masked_entities = deviceEntities
|
||||||
|
.filter((de) => de.m !== de.om)
|
||||||
|
.map((new_de) => new_de.m.toString(16).padStart(2, '0') + new_de.s);
|
||||||
|
|
||||||
|
if (masked_entities.length > 60) {
|
||||||
|
enqueueSnackbar('Selected entities exceeded limit of 60. Please Save in batches', { variant: 'warning' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await EMSESP.writeMaskedEntities({
|
||||||
|
id: selectedDevice,
|
||||||
|
entity_ids: masked_entities
|
||||||
|
});
|
||||||
|
if (response.status === 200) {
|
||||||
|
enqueueSnackbar('Customization saved', { variant: 'success' });
|
||||||
|
} else {
|
||||||
|
enqueueSnackbar('Customization save failed', { variant: 'error' });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
enqueueSnackbar(extractErrorMessage(error, 'Problem sending entity list'), { variant: 'error' });
|
||||||
|
}
|
||||||
|
setInitialMask(deviceEntities);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const renderDeviceList = () => {
|
const renderDeviceList = () => {
|
||||||
if (!devices) {
|
if (!devices) {
|
||||||
return <FormLoader errorMessage={errorMessage} />;
|
return <FormLoader errorMessage={errorMessage} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareDevices(a: DeviceShort, b: DeviceShort) {
|
|
||||||
if (a.s < b.s) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.s > b.s) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const changeSelectedDevice = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const selected_device = parseInt(event.target.value, 10);
|
|
||||||
setSelectedDevice(selected_device);
|
|
||||||
fetchDeviceEntities(selected_device);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box color="warning.main">
|
<Box color="warning.main">
|
||||||
<Typography variant="body2">Select a device and customize each of its entities using the options:</Typography>
|
<Typography variant="body2">Select a device and customize each of its entities using the options.</Typography>
|
||||||
<Typography mt={1} ml={2} display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
|
|
||||||
<FavoriteBorderOutlinedIcon color="success" sx={{ fontSize: 13 }} />
|
|
||||||
mark it as favorite to be listed at the top of the Dashboard
|
|
||||||
</Typography>
|
|
||||||
<Typography ml={2} display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
|
|
||||||
<EditOffOutlinedIcon color="secondary" sx={{ fontSize: 13 }} />
|
|
||||||
make it read-only, only if it has write operation available
|
|
||||||
</Typography>
|
|
||||||
<Typography ml={2} display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
|
|
||||||
<CommentsDisabledOutlinedIcon color="secondary" sx={{ fontSize: 13 }} />
|
|
||||||
excluded it from MQTT and API outputs
|
|
||||||
</Typography>
|
|
||||||
<Typography ml={2} mb={1} display="block" variant="body2" sx={{ alignItems: 'center', display: 'flex' }}>
|
|
||||||
<VisibilityOffOutlinedIcon color="secondary" sx={{ fontSize: 13 }} />
|
|
||||||
hide it from the Dashboard
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
</Box>
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
name="device"
|
name="device"
|
||||||
@@ -158,131 +318,177 @@ const SettingsCustomization: FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveCustomization = async () => {
|
|
||||||
if (deviceEntities && selectedDevice) {
|
|
||||||
const masked_entities = deviceEntities
|
|
||||||
.filter((de) => de.m !== de.om)
|
|
||||||
.map((new_de) => new_de.m.toString(16).padStart(2, '0') + new_de.s);
|
|
||||||
|
|
||||||
if (masked_entities.length > 50) {
|
|
||||||
enqueueSnackbar(
|
|
||||||
'Too many selected entities (' + masked_entities.length + '). Limit is 50. Please Save in batches',
|
|
||||||
{ variant: 'warning' }
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await EMSESP.writeMaskedEntities({
|
|
||||||
id: selectedDevice,
|
|
||||||
entity_ids: masked_entities
|
|
||||||
});
|
|
||||||
if (response.status === 200) {
|
|
||||||
enqueueSnackbar('Customization saved', { variant: 'success' });
|
|
||||||
} else {
|
|
||||||
enqueueSnackbar('Customization save failed', { variant: 'error' });
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
enqueueSnackbar(extractErrorMessage(error, 'Problem sending entity list'), { variant: 'error' });
|
|
||||||
}
|
|
||||||
setInitialMask(deviceEntities);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderDeviceData = () => {
|
const renderDeviceData = () => {
|
||||||
if (devices?.devices.length === 0 || !deviceEntities) {
|
if (devices?.devices.length === 0 || deviceEntities[0].id === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const setMask = (de: DeviceEntity, newMask: string[]) => {
|
const shown_data = deviceEntities.filter(
|
||||||
var new_mask = 0;
|
(de) => (de.m & selectedFilters || !selectedFilters) && de.id.toLowerCase().includes(search.toLowerCase())
|
||||||
for (let entry of newMask) {
|
);
|
||||||
new_mask |= Number(entry);
|
|
||||||
}
|
|
||||||
de.m = new_mask;
|
|
||||||
setMasks(newMask);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMask = (de: DeviceEntity) => {
|
|
||||||
var new_masks = [];
|
|
||||||
if ((de.m & 1) === 1 || de.n === '') {
|
|
||||||
new_masks.push('1');
|
|
||||||
}
|
|
||||||
if ((de.m & 2) === 2) {
|
|
||||||
new_masks.push('2');
|
|
||||||
}
|
|
||||||
if ((de.m & 4) === 4 && de.w) {
|
|
||||||
new_masks.push('4');
|
|
||||||
}
|
|
||||||
if ((de.m & 8) === 8) {
|
|
||||||
new_masks.push('8');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_masks;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table size="small" padding="normal">
|
<>
|
||||||
<TableHead>
|
<Grid container mb={1} mt={0} spacing={1} direction="row" justifyContent="flex-start" alignItems="center">
|
||||||
<TableRow>
|
<Grid item>
|
||||||
<StyledTableCell align="center">OPTIONS</StyledTableCell>
|
<Typography variant="subtitle2" color="primary">
|
||||||
<StyledTableCell align="left">ENTITY NAME (CODE)</StyledTableCell>
|
#:
|
||||||
<StyledTableCell align="right">VALUE</StyledTableCell>
|
</Typography>
|
||||||
</TableRow>
|
</Grid>
|
||||||
</TableHead>
|
<Grid item>
|
||||||
<TableBody>
|
<Typography variant="subtitle2">
|
||||||
{deviceEntities.map((de) => (
|
{shown_data.length}/{deviceEntities.length}
|
||||||
<TableRow key={de.s} hover>
|
</Typography>
|
||||||
<StyledTableCell padding="none">
|
</Grid>
|
||||||
<ToggleButtonGroup
|
<Grid item>
|
||||||
size="small"
|
<SearchIcon color="primary" sx={{ fontSize: 16, verticalAlign: 'middle' }} />:
|
||||||
color="secondary"
|
</Grid>
|
||||||
value={getMask(de)}
|
<Grid item xs={2}>
|
||||||
onChange={(event, mask) => {
|
<TextField
|
||||||
setMask(de, mask);
|
size="small"
|
||||||
}}
|
variant="outlined"
|
||||||
>
|
onChange={(event) => {
|
||||||
<ToggleButton value="8" color="success" disabled={(de.m & 1) !== 0 || de.n === ''}>
|
setSearch(event.target.value);
|
||||||
<FavoriteBorderOutlinedIcon sx={{ fontSize: 14 }} />
|
}}
|
||||||
</ToggleButton>
|
/>
|
||||||
<ToggleButton value="4" disabled={!de.w}>
|
</Grid>
|
||||||
<EditOffOutlinedIcon sx={{ fontSize: 14 }} />
|
<Grid item>
|
||||||
</ToggleButton>
|
<FilterListIcon color="primary" sx={{ fontSize: 14, verticalAlign: 'middle' }} />:
|
||||||
<ToggleButton value="2">
|
</Grid>
|
||||||
<CommentsDisabledOutlinedIcon sx={{ fontSize: 14 }} />
|
<Grid item>
|
||||||
</ToggleButton>
|
<ToggleButtonGroup
|
||||||
<ToggleButton value="1">
|
size="small"
|
||||||
<VisibilityOffOutlinedIcon sx={{ fontSize: 14 }} />
|
color="secondary"
|
||||||
</ToggleButton>
|
value={getMaskString(selectedFilters)}
|
||||||
</ToggleButtonGroup>
|
onChange={(event, mask) => {
|
||||||
</StyledTableCell>
|
setSelectedFilters(getMaskNumber(mask));
|
||||||
<StyledTableCell>
|
}}
|
||||||
{de.n} ({de.s})
|
>
|
||||||
</StyledTableCell>
|
<ToggleButton value="8">
|
||||||
<StyledTableCell align="right">{formatValue(de.v)}</StyledTableCell>
|
<Tooltip arrow placement="top" title="mark it as favorite to be listed at the top of the Dashboard">
|
||||||
</TableRow>
|
<StarIcon sx={{ fontSize: 14 }} />
|
||||||
))}
|
</Tooltip>
|
||||||
</TableBody>
|
</ToggleButton>
|
||||||
</Table>
|
<ToggleButton value="4">
|
||||||
);
|
<Tooltip arrow placement="top" title="make it read-only, only if it has write operation available">
|
||||||
};
|
<EditOffOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</Tooltip>
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton value="2">
|
||||||
|
<Tooltip arrow placement="top" title="excluded it from MQTT and API outputs">
|
||||||
|
<CommentsDisabledOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</Tooltip>
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton value="1">
|
||||||
|
<Tooltip arrow placement="top" title="hide it from the Dashboard">
|
||||||
|
<VisibilityOffOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</Tooltip>
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
const resetCustomization = async () => {
|
<Grid item>
|
||||||
try {
|
<CommentsDisabledOutlinedIcon color="primary" sx={{ fontSize: 14, verticalAlign: 'middle' }} />
|
||||||
await EMSESP.resetCustomizations();
|
<VisibilityOffOutlinedIcon color="primary" sx={{ fontSize: 14, verticalAlign: 'middle' }} />:
|
||||||
enqueueSnackbar('All customizations have been removed. Restarting...', { variant: 'info' });
|
</Grid>
|
||||||
} catch (error: any) {
|
<Grid item>
|
||||||
enqueueSnackbar(extractErrorMessage(error, 'Problem resetting customizations'), { variant: 'error' });
|
<Button
|
||||||
} finally {
|
size="small"
|
||||||
setConfirmReset(false);
|
sx={{ fontSize: 10 }}
|
||||||
}
|
variant="outlined"
|
||||||
|
color="inherit"
|
||||||
|
onClick={() => maskDisabled(false)}
|
||||||
|
>
|
||||||
|
enable
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{ fontSize: 10 }}
|
||||||
|
variant="outlined"
|
||||||
|
color="inherit"
|
||||||
|
onClick={() => maskDisabled(true)}
|
||||||
|
>
|
||||||
|
disable
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
<Table
|
||||||
|
data={{ nodes: shown_data }}
|
||||||
|
theme={entities_theme}
|
||||||
|
sort={entity_sort}
|
||||||
|
layout={{ custom: true, horizontalScroll: true }}
|
||||||
|
>
|
||||||
|
{(tableList: any) => (
|
||||||
|
<>
|
||||||
|
<Header>
|
||||||
|
<HeaderRow>
|
||||||
|
<HeaderCell pinLeft>OPTIONS</HeaderCell>
|
||||||
|
<HeaderCell resize>
|
||||||
|
<Button
|
||||||
|
fullWidth
|
||||||
|
style={{ fontSize: '14px', justifyContent: 'flex-start' }}
|
||||||
|
endIcon={getSortIcon(entity_sort.state, 'NAME')}
|
||||||
|
onClick={() => entity_sort.fns.onToggleSort({ sortKey: 'NAME' })}
|
||||||
|
>
|
||||||
|
NAME
|
||||||
|
</Button>
|
||||||
|
</HeaderCell>
|
||||||
|
<HeaderCell>VALUE</HeaderCell>
|
||||||
|
<HeaderCell />
|
||||||
|
</HeaderRow>
|
||||||
|
</Header>
|
||||||
|
<Body>
|
||||||
|
{tableList.map((de: DeviceEntity) => (
|
||||||
|
<Row key={de.id} item={de}>
|
||||||
|
<Cell>
|
||||||
|
<ToggleButtonGroup
|
||||||
|
size="small"
|
||||||
|
color="secondary"
|
||||||
|
value={getMaskString(de.m)}
|
||||||
|
onChange={(event, mask) => {
|
||||||
|
de.m = getMaskNumber(mask);
|
||||||
|
if (de.m & DeviceEntityMask.DV_WEB_EXCLUDE) {
|
||||||
|
de.m = de.m & ~DeviceEntityMask.DV_FAVORITE;
|
||||||
|
}
|
||||||
|
setMasks(['']);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ToggleButton value="8" disabled={(de.m & 1) !== 0 || de.id === ''}>
|
||||||
|
<StarIcon sx={{ fontSize: 14 }} />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton value="4" disabled={!de.w || (de.m & 3) === 3}>
|
||||||
|
<EditOffOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton value="2">
|
||||||
|
<CommentsDisabledOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</ToggleButton>
|
||||||
|
<ToggleButton value="1">
|
||||||
|
<VisibilityOffOutlinedIcon sx={{ fontSize: 14 }} />
|
||||||
|
</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
</Cell>
|
||||||
|
<Cell>
|
||||||
|
{de.id} ({de.s})
|
||||||
|
</Cell>
|
||||||
|
<Cell>{formatValue(de.v)}</Cell>
|
||||||
|
</Row>
|
||||||
|
))}
|
||||||
|
</Body>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Table>
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderResetDialog = () => (
|
const renderResetDialog = () => (
|
||||||
<Dialog open={confirmReset} onClose={() => setConfirmReset(false)}>
|
<Dialog open={confirmReset} onClose={() => setConfirmReset(false)}>
|
||||||
<DialogTitle>Reset</DialogTitle>
|
<DialogTitle>Reset</DialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
Are you sure you want remove all customizations? EMS-ESP will then restart.
|
Are you sure you want remove all customizations including the custom settings of the Temperature and Analog
|
||||||
|
sensors?
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button startIcon={<CancelIcon />} variant="outlined" onClick={() => setConfirmReset(false)} color="secondary">
|
<Button startIcon={<CancelIcon />} variant="outlined" onClick={() => setConfirmReset(false)} color="secondary">
|
||||||
|
|||||||
@@ -38,38 +38,23 @@ export enum busConnectionStatus {
|
|||||||
BUS_STATUS_OFFLINE = 2
|
BUS_STATUS_OFFLINE = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Stat {
|
||||||
|
id: string; // name
|
||||||
|
s: number; // success
|
||||||
|
f: number; // fail
|
||||||
|
q: number; // quality
|
||||||
|
}
|
||||||
export interface Status {
|
export interface Status {
|
||||||
status: busConnectionStatus;
|
status: busConnectionStatus;
|
||||||
tx_mode: number;
|
tx_mode: number;
|
||||||
rx_received: number;
|
uptime: number;
|
||||||
tx_reads: number;
|
|
||||||
tx_writes: number;
|
|
||||||
rx_quality: number;
|
|
||||||
tx_read_quality: number;
|
|
||||||
tx_write_quality: number;
|
|
||||||
tx_read_fails: number;
|
|
||||||
tx_write_fails: number;
|
|
||||||
rx_fails: number;
|
|
||||||
sensor_fails: number;
|
|
||||||
sensor_reads: number;
|
|
||||||
sensor_quality: number;
|
|
||||||
analog_fails: number;
|
|
||||||
analog_reads: number;
|
|
||||||
analog_quality: number;
|
|
||||||
mqtt_count: number;
|
|
||||||
mqtt_fails: number;
|
|
||||||
mqtt_quality: number;
|
|
||||||
api_calls: number;
|
|
||||||
api_fails: number;
|
|
||||||
api_quality: number;
|
|
||||||
num_devices: number;
|
num_devices: number;
|
||||||
num_sensors: number;
|
num_sensors: number;
|
||||||
num_analogs: number;
|
num_analogs: number;
|
||||||
uptime: number;
|
stats: Stat[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Device {
|
export interface Device {
|
||||||
i: number; // id
|
id: string; // id index
|
||||||
t: string; // type
|
t: string; // type
|
||||||
b: string; // brand
|
b: string; // brand
|
||||||
n: string; // name
|
n: string; // name
|
||||||
@@ -80,7 +65,7 @@ export interface Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Sensor {
|
export interface Sensor {
|
||||||
is: string; // id string
|
id: string; // id string
|
||||||
n: string; // name/alias
|
n: string; // name/alias
|
||||||
t?: number; // temp, optional
|
t?: number; // temp, optional
|
||||||
o: number; // offset
|
o: number; // offset
|
||||||
@@ -88,9 +73,10 @@ export interface Sensor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Analog {
|
export interface Analog {
|
||||||
i: number;
|
id: string; // id string
|
||||||
|
g: number; // GPIO
|
||||||
n: string;
|
n: string;
|
||||||
v?: number;
|
v: number; // is optional
|
||||||
u: number;
|
u: number;
|
||||||
o: number;
|
o: number;
|
||||||
f: number;
|
f: number;
|
||||||
@@ -98,7 +84,7 @@ export interface Analog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WriteSensor {
|
export interface WriteSensor {
|
||||||
id_str: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
offset: number;
|
offset: number;
|
||||||
}
|
}
|
||||||
@@ -126,11 +112,11 @@ export interface Devices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DeviceValue {
|
export interface DeviceValue {
|
||||||
v?: any; // value, in any format
|
id: string; // index, contains mask+name
|
||||||
|
v: any; // value, in any format
|
||||||
u: number; // uom
|
u: number; // uom
|
||||||
n: string; // name
|
c?: string; // command, optional
|
||||||
c: string; // command
|
l?: string[]; // list, optional
|
||||||
l: string[]; // list
|
|
||||||
h?: string; // help text, optional
|
h?: string; // help text, optional
|
||||||
s?: string; // steps for up/down, optional
|
s?: string; // steps for up/down, optional
|
||||||
m?: string; // min, optional
|
m?: string; // min, optional
|
||||||
@@ -143,8 +129,8 @@ export interface DeviceData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DeviceEntity {
|
export interface DeviceEntity {
|
||||||
v?: any; // value, in any format
|
id: string; // name
|
||||||
n: string; // name
|
v: any; // value, in any format
|
||||||
s: string; // shortname
|
s: string; // shortname
|
||||||
m: number; // mask
|
m: number; // mask
|
||||||
om?: number; // original mask before edits
|
om?: number; // original mask before edits
|
||||||
@@ -277,7 +263,7 @@ export interface WriteValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface WriteAnalog {
|
export interface WriteAnalog {
|
||||||
id: number;
|
gpio: number;
|
||||||
name: string;
|
name: string;
|
||||||
factor: number;
|
factor: number;
|
||||||
offset: number;
|
offset: number;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export interface User {
|
export interface User {
|
||||||
|
id: string; // needed for Table
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
admin: boolean;
|
admin: boolean;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class SecuritySettings {
|
|||||||
JsonArray users = root.createNestedArray("users");
|
JsonArray users = root.createNestedArray("users");
|
||||||
for (User user : settings.users) {
|
for (User user : settings.users) {
|
||||||
JsonObject userRoot = users.createNestedObject();
|
JsonObject userRoot = users.createNestedObject();
|
||||||
|
userRoot["id"] = user.username; // for React Table
|
||||||
userRoot["username"] = user.username;
|
userRoot["username"] = user.username;
|
||||||
userRoot["password"] = user.password;
|
userRoot["password"] = user.password;
|
||||||
userRoot["admin"] = user.admin;
|
userRoot["admin"] = user.admin;
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ const UPLOAD_FIRMWARE_ENDPOINT = REST_ENDPOINT_ROOT + 'uploadFirmware'
|
|||||||
const SIGN_IN_ENDPOINT = REST_ENDPOINT_ROOT + 'signIn'
|
const SIGN_IN_ENDPOINT = REST_ENDPOINT_ROOT + 'signIn'
|
||||||
const GENERATE_TOKEN_ENDPOINT = REST_ENDPOINT_ROOT + 'generateToken'
|
const GENERATE_TOKEN_ENDPOINT = REST_ENDPOINT_ROOT + 'generateToken'
|
||||||
const system_status = {
|
const system_status = {
|
||||||
emsesp_version: '3.4.0demo',
|
emsesp_version: '3.4demo',
|
||||||
esp_platform: 'ESP32',
|
esp_platform: 'ESP32',
|
||||||
max_alloc_heap: 113792,
|
max_alloc_heap: 113792,
|
||||||
psram_size: 0,
|
psram_size: 0,
|
||||||
@@ -270,8 +270,8 @@ const system_status = {
|
|||||||
security_settings = {
|
security_settings = {
|
||||||
jwt_secret: 'naughty!',
|
jwt_secret: 'naughty!',
|
||||||
users: [
|
users: [
|
||||||
{ username: 'admin', password: 'admin', admin: true },
|
{ id: 'admin', username: 'admin', password: 'admin', admin: true },
|
||||||
{ username: 'guest', password: 'guest', admin: false },
|
{ id: 'guest', username: 'guest', password: 'guest', admin: false },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
const features = {
|
const features = {
|
||||||
@@ -362,11 +362,11 @@ const emsesp_devices = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const emsesp_coredata = {
|
const emsesp_coredata = {
|
||||||
|
// devices: [],
|
||||||
devices: [
|
devices: [
|
||||||
{
|
{
|
||||||
i: 2,
|
id: '2',
|
||||||
t: 'Boiler',
|
t: 'Boiler',
|
||||||
s: 'Boiler',
|
|
||||||
b: 'Nefit',
|
b: 'Nefit',
|
||||||
n: 'GBx72/Trendline/Cerapur/Greenstar Si/27i',
|
n: 'GBx72/Trendline/Cerapur/Greenstar Si/27i',
|
||||||
d: 8,
|
d: 8,
|
||||||
@@ -375,9 +375,8 @@ const emsesp_coredata = {
|
|||||||
e: 68,
|
e: 68,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
i: 1,
|
id: '1',
|
||||||
t: 'Thermostat',
|
t: 'Thermostat',
|
||||||
s: 'Thermostat',
|
|
||||||
b: '',
|
b: '',
|
||||||
n: 'RC20/Moduline 300',
|
n: 'RC20/Moduline 300',
|
||||||
d: 23,
|
d: 23,
|
||||||
@@ -386,9 +385,8 @@ const emsesp_coredata = {
|
|||||||
e: 5,
|
e: 5,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
i: 4,
|
id: '4',
|
||||||
t: 'Thermostat',
|
t: 'Thermostat',
|
||||||
s: 'Thermostat',
|
|
||||||
b: 'Buderus',
|
b: 'Buderus',
|
||||||
n: 'RC100/Moduline 1000/1010',
|
n: 'RC100/Moduline 1000/1010',
|
||||||
d: 16,
|
d: 16,
|
||||||
@@ -403,49 +401,37 @@ const emsesp_coredata = {
|
|||||||
|
|
||||||
const emsesp_sensordata = {
|
const emsesp_sensordata = {
|
||||||
sensors: [
|
sensors: [
|
||||||
{ is: '28-233D-9497-0C03', n: 'Dallas 1', t: 25.7, o: 1.2, u: 1 },
|
{ id: '28-233D-9497-0C03', n: 'Dallas 1', t: 25.7, o: 1.2, u: 1 },
|
||||||
{ is: '28-243D-7437-1E3A', n: 'Dallas 2 outside', t: 26.1, o: 0, u: 1 },
|
{ id: '28-243D-7437-1E3A', n: 'Dallas 2 outside', t: 26.1, o: 0, u: 1 },
|
||||||
{ is: '28-243E-7437-1E3B', n: 'Zolder', t: 27.1, o: 0, u: 16 },
|
{ id: '28-243E-7437-1E3B', n: 'Zolder', t: 27.1, o: 0, u: 16 },
|
||||||
{ is: '28-183D-1892-0C33', n: 'Roof', o: 2, u: 1 },
|
{ id: '28-183D-1892-0C33', n: 'Roof', o: 2, u: 1 },
|
||||||
],
|
],
|
||||||
// sensors: [],
|
// sensors: [],
|
||||||
analogs: [
|
analogs: [
|
||||||
{ i: 36, n: 'motor', u: 0, o: 17, f: 0, t: 0 },
|
{ id: '1', g: 36, n: 'motor', v: 0, u: 0, o: 17, f: 0, t: 0 },
|
||||||
{ i: 37, n: 'External switch', v: 13, u: 0, o: 17, f: 0, t: 1 },
|
{ id: '2', g: 37, n: 'External switch', v: 13, u: 0, o: 17, f: 0, t: 1 },
|
||||||
{ i: 39, n: 'Pulse count', v: 144, u: 0, o: 0, f: 0, t: 2 },
|
{ id: '3', g: 39, n: 'Pulse count', v: 144, u: 0, o: 0, f: 0, t: 2 },
|
||||||
{ i: 40, n: 'Pressure', v: 16, u: 17, o: 0, f: 0, t: 3 },
|
{ id: '4', g: 40, n: 'Pressure', v: 16, u: 17, o: 0, f: 0, t: 3 },
|
||||||
],
|
],
|
||||||
// analogs: [],
|
// analogs: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = {
|
const status = {
|
||||||
analog_fails: 0,
|
|
||||||
analog_quality: 100,
|
|
||||||
analog_reads: 203,
|
|
||||||
api_calls: 4,
|
|
||||||
api_fails: 0,
|
|
||||||
api_quality: 100,
|
|
||||||
mqtt_count: 40243,
|
|
||||||
mqtt_fails: 0,
|
|
||||||
mqtt_quality: 100,
|
|
||||||
num_analogs: 1,
|
|
||||||
num_devices: 2,
|
|
||||||
num_sensors: 1,
|
|
||||||
rx_fails: 11,
|
|
||||||
rx_quality: 100,
|
|
||||||
rx_received: 56506,
|
|
||||||
sensor_fails: 0,
|
|
||||||
sensor_quality: 100,
|
|
||||||
sensor_reads: 15438,
|
|
||||||
status: 0,
|
status: 0,
|
||||||
tx_mode: 1,
|
tx_mode: 1,
|
||||||
tx_read_fails: 0,
|
|
||||||
tx_read_quality: 100,
|
|
||||||
tx_reads: 9026,
|
|
||||||
tx_write_fails: 2,
|
|
||||||
tx_write_quality: 95,
|
|
||||||
tx_writes: 33,
|
|
||||||
uptime: 77186,
|
uptime: 77186,
|
||||||
|
num_devices: 2,
|
||||||
|
num_sensors: 1,
|
||||||
|
num_analogs: 1,
|
||||||
|
stats: [
|
||||||
|
{ id: 'EMS Telegrams Received (Rx)', s: 56506, f: 11, q: 100 },
|
||||||
|
{ id: 'EMS Reads (Tx)', s: 9026, f: 0, q: 100 },
|
||||||
|
{ id: 'EMS Writes (Tx)', s: 33, f: 2, q: 95 },
|
||||||
|
{ id: 'Temperature Sensor Reads', s: 56506, f: 11, q: 100 },
|
||||||
|
{ id: 'Analog Sensor Reads', s: 0, f: 0, q: 100 },
|
||||||
|
{ id: 'MQTT Publishes', s: 12, f: 10, q: 20 },
|
||||||
|
{ id: 'API Calls', s: 0, f: 0, q: 0 },
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dashboard data
|
// Dashboard data
|
||||||
@@ -455,31 +441,28 @@ const emsesp_devicedata_1 = {
|
|||||||
{
|
{
|
||||||
v: '(0)',
|
v: '(0)',
|
||||||
u: 0,
|
u: 0,
|
||||||
n: '00error code',
|
id: '00error code',
|
||||||
c: '',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: '14:54:39 06/06/2021',
|
v: '14:54:39 06/06/2021',
|
||||||
u: 0,
|
u: 0,
|
||||||
n: '00date/time',
|
id: '00date/time',
|
||||||
c: '',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 18,
|
v: 18,
|
||||||
u: 1,
|
u: 1,
|
||||||
n: '00hc1 selected room temperature',
|
id: '00hc1 selected room temperature',
|
||||||
c: 'hc1/seltemp',
|
c: 'hc1/seltemp',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 22.6,
|
v: 22.6,
|
||||||
u: 1,
|
u: 1,
|
||||||
n: '00hc1 current room temperature',
|
id: '00hc1 current room temperature',
|
||||||
c: '',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 'auto',
|
v: 'auto',
|
||||||
u: 0,
|
u: 0,
|
||||||
n: '00hc1 mode',
|
id: '00hc1 mode',
|
||||||
c: 'hc1/mode',
|
c: 'hc1/mode',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -488,81 +471,81 @@ const emsesp_devicedata_1 = {
|
|||||||
const emsesp_devicedata_2 = {
|
const emsesp_devicedata_2 = {
|
||||||
label: 'Boiler: Nefit GBx72/Trendline/Cerapur/Greenstar Si/27i',
|
label: 'Boiler: Nefit GBx72/Trendline/Cerapur/Greenstar Si/27i',
|
||||||
data: [
|
data: [
|
||||||
{ u: 0, n: '08reset', c: 'reset', l: ['-', 'maintenance', 'error'] },
|
{ v: 0, u: 0, id: '08reset', c: 'reset', l: ['-', 'maintenance', 'error'] },
|
||||||
{ v: 'false', u: 0, n: '08heating active' },
|
{ v: 'false', u: 0, id: '08heating active' },
|
||||||
{ v: 'false', u: 0, n: '04tapwater active' },
|
{ v: 'false', u: 0, id: '04tapwater active' },
|
||||||
{ v: 5, u: 1, n: '04selected flow temperature', c: 'selflowtemp' },
|
{ v: 5, u: 1, id: '04selected flow temperature', c: 'selflowtemp' },
|
||||||
{ v: 0, u: 3, n: '0Eburner selected max power', c: 'selburnpow' },
|
{ v: 0, u: 3, id: '0Eburner selected max power', c: 'selburnpow' },
|
||||||
{ v: 0, u: 3, n: '00heating pump modulation' },
|
{ v: 0, u: 3, id: '00heating pump modulation' },
|
||||||
{ v: 53.4, u: 1, n: '00current flow temperature' },
|
{ v: 53.4, u: 1, id: '00current flow temperature' },
|
||||||
{ v: 52.7, u: 1, n: '00return temperature' },
|
{ v: 52.7, u: 1, id: '00return temperature' },
|
||||||
{ v: 1.3, u: 10, n: '00system pressure' },
|
{ v: 1.3, u: 10, id: '00system pressure' },
|
||||||
{ v: 54.9, u: 1, n: '00actual boiler temperature' },
|
{ v: 54.9, u: 1, id: '00actual boiler temperature' },
|
||||||
{ v: 'false', u: 0, n: '00gas' },
|
{ v: 'false', u: 0, id: '00gas' },
|
||||||
{ v: 'false', u: 0, n: '00gas stage 2' },
|
{ v: 'false', u: 0, id: '00gas stage 2' },
|
||||||
{ v: 0, u: 9, n: '00flame current' },
|
{ v: 0, u: 9, id: '00flame current' },
|
||||||
{ v: 'false', u: 0, n: '00heating pump' },
|
{ v: 'false', u: 0, id: '00heating pump' },
|
||||||
{ v: 'false', u: 0, n: '00fan' },
|
{ v: 'false', u: 0, id: '00fan' },
|
||||||
{ v: 'false', u: 0, n: '00ignition' },
|
{ v: 'false', u: 0, id: '00ignition' },
|
||||||
{ v: 'false', u: 0, n: '00oil preheating' },
|
{ v: 'false', u: 0, id: '00oil preheating' },
|
||||||
{ v: 'true', u: 0, n: '00heating activated', c: 'heatingactivated', l: ['off', 'on'] },
|
{ v: 'true', u: 0, id: '00heating activated', c: 'heatingactivated', l: ['off', 'on'] },
|
||||||
{ v: 80, u: 1, n: '00heating temperature', c: 'heatingtemp' },
|
{ v: 80, u: 1, id: '00heating temperature', c: 'heatingtemp' },
|
||||||
{ v: 70, u: 3, n: '00burner pump max power', c: 'pumpmodmax' },
|
{ v: 70, u: 3, id: '00burner pump max power', c: 'pumpmodmax' },
|
||||||
{ v: 30, u: 3, n: '00burner pump min power', c: 'pumpmodmin' },
|
{ v: 30, u: 3, id: '00burner pump min power', c: 'pumpmodmin' },
|
||||||
{ v: 1, u: 8, n: '00pump delay', c: 'pumpdelay' },
|
{ v: 1, u: 8, id: '00pump delay', c: 'pumpdelay' },
|
||||||
{ v: 10, u: 8, n: '00burner min period', c: 'burnminperiod' },
|
{ v: 10, u: 8, id: '00burner min period', c: 'burnminperiod' },
|
||||||
{ v: 0, u: 3, n: '00burner min power', c: 'burnminpower' },
|
{ v: 0, u: 3, id: '00burner min power', c: 'burnminpower' },
|
||||||
{ v: 50, u: 3, n: '00burner max power', c: 'burnmaxpower' },
|
{ v: 50, u: 3, id: '00burner max power', c: 'burnmaxpower' },
|
||||||
{ v: -6, u: 2, n: '00hysteresis on temperature', c: 'boilhyston' },
|
{ v: -6, u: 2, id: '00hysteresis on temperature', c: 'boilhyston' },
|
||||||
{ v: 6, u: 2, n: '00hysteresis off temperature', c: 'boilhystoff' },
|
{ v: 6, u: 2, id: '00hysteresis off temperature', c: 'boilhystoff' },
|
||||||
{ v: 0, u: 1, n: '00set flow temperature' },
|
{ v: 0, u: 1, id: '00set flow temperature' },
|
||||||
{ v: 0, u: 3, n: '00burner set power' },
|
{ v: 0, u: 3, id: '00burner set power' },
|
||||||
{ v: 0, u: 3, n: '00burner current power' },
|
{ v: 0, u: 3, id: '00burner current power' },
|
||||||
{ v: 326323, u: 0, n: '00burner starts' },
|
{ v: 326323, u: 0, id: '00burner starts' },
|
||||||
{ v: 553437, u: 8, n: '00total burner operating time' },
|
{ v: 553437, u: 8, id: '00total burner operating time' },
|
||||||
{ v: 451286, u: 8, n: '00total heat operating time' },
|
{ v: 451286, u: 8, id: '00total heat operating time' },
|
||||||
{ v: 4672173, u: 8, n: '00total UBA operating time' },
|
{ v: 4672173, u: 8, id: '00total UBA operating time' },
|
||||||
{ v: '1C(210) 06.06.2020 12:07 (0 min)', u: 0, n: '00last error code' },
|
{ v: '1C(210) 06.06.2020 12:07 (0 min)', u: 0, id: '00last error code' },
|
||||||
{ v: '0H', u: 0, n: '00service code' },
|
{ v: '0H', u: 0, id: '00service code' },
|
||||||
{ v: 203, u: 0, n: '00service code number' },
|
{ v: 203, u: 0, id: '00service code number' },
|
||||||
{ v: 'H00', u: 0, n: '00maintenance message' },
|
{ v: 'H00', u: 0, id: '00maintenance message' },
|
||||||
{ v: 'manual', u: 0, n: '00maintenance scheduled', c: 'maintenance', l: ['off', 'time', 'date', 'manual'] },
|
{ v: 'manual', u: 0, id: '00maintenance scheduled', c: 'maintenance', l: ['off', 'time', 'date', 'manual'] },
|
||||||
{ v: 6000, u: 7, n: '00time to next maintenance', c: 'maintenancetime' },
|
{ v: 6000, u: 7, id: '00time to next maintenance', c: 'maintenancetime' },
|
||||||
{ v: '01.01.2012', u: 0, n: '00next maintenance date', c: 'maintenancedate', o: 'Format: < dd.mm.yyyy >' },
|
{ v: '01.01.2012', u: 0, id: '00next maintenance date', c: 'maintenancedate', o: 'Format: < dd.mm.yyyy >' },
|
||||||
{ v: 'true', u: 0, n: '00dhw turn on/off', c: 'wwtapactivated', l: ['off', 'on'] },
|
{ v: 'true', u: 0, id: '00dhw turn on/off', c: 'wwtapactivated', l: ['off', 'on'] },
|
||||||
{ v: 62, u: 1, n: '00dhw set temperature' },
|
{ v: 62, u: 1, id: '00dhw set temperature' },
|
||||||
{ v: 60, u: 1, n: '00dhw selected temperature', c: 'wwseltemp' },
|
{ v: 60, u: 1, id: '00dhw selected temperature', c: 'wwseltemp' },
|
||||||
{ v: 'flow', u: 0, n: '00dhw type' },
|
{ v: 'flow', u: 0, id: '00dhw type' },
|
||||||
{ v: 'hot', u: 0, n: '00dhw comfort', c: 'wwcomfort', l: ['hot', 'eco', 'intelligent'] },
|
{ v: 'hot', u: 0, id: '00dhw comfort', c: 'wwcomfort', l: ['hot', 'eco', 'intelligent'] },
|
||||||
{ v: 40, u: 2, n: '00dhw flow temperature offset', c: 'wwflowtempoffset' },
|
{ v: 40, u: 2, id: '00dhw flow temperature offset', c: 'wwflowtempoffset' },
|
||||||
{ v: 100, u: 3, n: '00dhw max power', c: 'wwmaxpower' },
|
{ v: 100, u: 3, id: '00dhw max power', c: 'wwmaxpower' },
|
||||||
{ v: 'false', u: 0, n: '00dhw circulation pump available', c: 'wwcircpump', l: ['off', 'on'] },
|
{ v: 'false', u: 0, id: '00dhw circulation pump available', c: 'wwcircpump', l: ['off', 'on'] },
|
||||||
{ v: '3-way valve', u: 0, n: '00dhw charging type' },
|
{ v: '3-way valve', u: 0, id: '00dhw charging type' },
|
||||||
{ v: -5, u: 2, n: '00dhw hysteresis on temperature', c: 'wwhyston' },
|
{ v: -5, u: 2, id: '00dhw hysteresis on temperature', c: 'wwhyston' },
|
||||||
{ v: 0, u: 2, n: '00dhw hysteresis off temperature', c: 'wwhystoff' },
|
{ v: 0, u: 2, id: '00dhw hysteresis off temperature', c: 'wwhystoff' },
|
||||||
{ v: 70, u: 1, n: '00dhw disinfection temperature', c: 'wwdisinfectiontemp' },
|
{ v: 70, u: 1, id: '00dhw disinfection temperature', c: 'wwdisinfectiontemp' },
|
||||||
{
|
{
|
||||||
v: 'off',
|
v: 'off',
|
||||||
u: 0,
|
u: 0,
|
||||||
n: '00dhw circulation pump mode',
|
id: '00dhw circulation pump mode',
|
||||||
c: 'wwcircmode',
|
c: 'wwcircmode',
|
||||||
l: ['off', '1x3min', '2x3min', '3x3min', '4x3min', '5x3min', '6x3min', 'continuous'],
|
l: ['off', '1x3min', '2x3min', '3x3min', '4x3min', '5x3min', '6x3min', 'continuous'],
|
||||||
},
|
},
|
||||||
{ v: 'false', u: 0, n: '00dhw circulation active', c: 'wwcirc', l: ['off', 'on'] },
|
{ v: 'false', u: 0, id: '00dhw circulation active', c: 'wwcirc', l: ['off', 'on'] },
|
||||||
{ v: 47.3, u: 1, n: '00dhw current intern temperature' },
|
{ v: 47.3, u: 1, id: '00dhw current intern temperature' },
|
||||||
{ v: 0, u: 4, n: '00dhw current tap water flow' },
|
{ v: 0, u: 4, id: '00dhw current tap water flow' },
|
||||||
{ v: 47.3, u: 1, n: '00dhw storage intern temperature' },
|
{ v: 47.3, u: 1, id: '00dhw storage intern temperature' },
|
||||||
{ v: 'true', u: 0, n: '00dhw activated', c: 'wwactivated', l: ['off', 'on'] },
|
{ v: 'true', u: 0, id: '00dhw activated', c: 'wwactivated', l: ['off', 'on'] },
|
||||||
{ v: 'false', u: 0, n: '00dhw one time charging', c: 'wwonetime', l: ['off', 'on'] },
|
{ v: 'false', u: 0, id: '00dhw one time charging', c: 'wwonetime', l: ['off', 'on'] },
|
||||||
{ v: 'false', u: 0, n: '00dhw disinfecting', c: 'wwdisinfecting', l: ['off', 'on'] },
|
{ v: 'false', u: 0, id: '00dhw disinfecting', c: 'wwdisinfecting', l: ['off', 'on'] },
|
||||||
{ v: 'false', u: 0, n: '00dhw charging' },
|
{ v: 'false', u: 0, id: '00dhw charging' },
|
||||||
{ v: 'false', u: 0, n: '00dhw recharging' },
|
{ v: 'false', u: 0, id: '00dhw recharging' },
|
||||||
{ v: 'true', u: 0, n: '00dhw temperature ok' },
|
{ v: 'true', u: 0, id: '00dhw temperature ok' },
|
||||||
{ v: 'false', u: 0, n: '00dhw active' },
|
{ v: 'false', u: 0, id: '00dhw active' },
|
||||||
{ v: 'true', u: 0, n: '00dhw 3way valve active' },
|
{ v: 'true', u: 0, id: '00dhw 3way valve active' },
|
||||||
{ v: 0, u: 3, n: '00dhw set pump power' },
|
{ v: 0, u: 3, id: '00dhw set pump power' },
|
||||||
{ v: 288768, u: 0, n: '00dhw starts' },
|
{ v: 288768, u: 0, id: '00dhw starts' },
|
||||||
{ v: 102151, u: 8, n: '00dhw active time' },
|
{ v: 102151, u: 8, id: '00dhw active time' },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,19 +555,19 @@ const emsesp_devicedata_4 = {
|
|||||||
{
|
{
|
||||||
v: 16,
|
v: 16,
|
||||||
u: 1,
|
u: 1,
|
||||||
n: '00hc2 selected room temperature',
|
id: '08hc2 selected room temperature',
|
||||||
c: 'hc2/seltemp',
|
c: 'hc2/seltemp',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 18.6,
|
v: 18.6,
|
||||||
u: 1,
|
u: 1,
|
||||||
n: '00hc2 current room temperature',
|
id: '02hc2 current room temperature',
|
||||||
c: '',
|
c: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 'off',
|
v: 'off',
|
||||||
u: 0,
|
u: 0,
|
||||||
n: '00hc2 mode',
|
id: '02hc2 mode',
|
||||||
c: 'hc2/mode',
|
c: 'hc2/mode',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -593,35 +576,35 @@ const emsesp_devicedata_4 = {
|
|||||||
const emsesp_deviceentities_1 = [
|
const emsesp_deviceentities_1 = [
|
||||||
{
|
{
|
||||||
v: '(0)',
|
v: '(0)',
|
||||||
n: 'error code',
|
id: 'error code',
|
||||||
s: 'errorcode',
|
s: 'errorcode',
|
||||||
m: 0,
|
m: 0,
|
||||||
w: false,
|
w: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: '14:54:39 06/06/2021',
|
v: '14:54:39 06/06/2021',
|
||||||
n: 'date/time',
|
id: 'date/time',
|
||||||
s: 'datetime',
|
s: 'datetime',
|
||||||
m: 0,
|
m: 0,
|
||||||
w: false,
|
w: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 18.2,
|
v: 18.2,
|
||||||
n: 'hc1 selected room temperature',
|
id: 'hc1 selected room temperature',
|
||||||
s: 'hc1/seltemp',
|
s: 'hc1/seltemp',
|
||||||
m: 0,
|
m: 0,
|
||||||
w: true,
|
w: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 22.6,
|
v: 22.6,
|
||||||
n: 'hc1 current room temperature',
|
id: 'hc1 current room temperature',
|
||||||
s: 'hc1/curtemp',
|
s: 'hc1/curtemp',
|
||||||
m: 0,
|
m: 0,
|
||||||
w: false,
|
w: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 'auto',
|
v: 'auto',
|
||||||
n: 'hc1 mode',
|
id: 'hc1 mode',
|
||||||
s: 'hc1/mode',
|
s: 'hc1/mode',
|
||||||
m: 0,
|
m: 0,
|
||||||
w: true,
|
w: true,
|
||||||
@@ -629,107 +612,107 @@ const emsesp_deviceentities_1 = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const emsesp_deviceentities_2 = [
|
const emsesp_deviceentities_2 = [
|
||||||
{ v: false, n: 'heating active', s: 'heatingactive', m: 0 },
|
{ v: false, id: 'heating active', s: 'heatingactive', m: 0, w: false },
|
||||||
{ v: false, n: 'tapwater active', s: 'tapwateractive', m: 0 },
|
{ v: false, id: 'tapwater active', s: 'tapwateractive', m: 0, w: false },
|
||||||
{ v: 5, n: 'selected flow temperature', s: 'selflowtemp', m: 0 },
|
{ v: 5, id: 'selected flow temperature', s: 'selflowtemp', m: 0, w: true },
|
||||||
{ v: 0, n: 'burner selected max power', s: 'selburnpow', m: 0 },
|
{ v: 0, id: 'burner selected max power', s: 'selburnpow', m: 0, w: true },
|
||||||
{ v: 0, n: 'heating pump modulation', s: 'heatingpumpmod', m: 0 },
|
{ v: 0, id: 'heating pump modulation', s: 'heatingpumpmod', m: 0, w: false },
|
||||||
{ n: 'heating pump 2 modulation', s: 'heatingpump2mod', m: 0 },
|
{ id: 'heating pump 2 modulation', s: 'heatingpump2mod', m: 0, w: false },
|
||||||
{ n: 'outside temperature', s: 'outdoortemp', m: 0 },
|
{ id: 'outside temperature', s: 'outdoortemp', m: 0, w: false },
|
||||||
{ v: 53, n: 'current flow temperature', s: 'curflowtemp', m: 0 },
|
{ v: 53, id: 'current flow temperature', s: 'curflowtemp', m: 0, w: false },
|
||||||
{ v: 51.8, n: 'return temperature', s: 'rettemp', m: 0 },
|
{ v: 51.8, id: 'return temperature', s: 'rettemp', m: 0, w: false },
|
||||||
{ n: 'mixing switch temperature', s: 'switchtemp', m: 0 },
|
{ id: 'mixing switch temperature', s: 'switchtemp', m: 0, w: false },
|
||||||
{ v: 1.3, n: 'system pressure', s: 'syspress', m: 0 },
|
{ v: 1.3, id: 'system pressure', s: 'syspress', m: 0, w: false },
|
||||||
{ v: 54.6, n: 'actual boiler temperature', s: 'boiltemp', m: 0 },
|
{ v: 54.6, id: 'actual boiler temperature', s: 'boiltemp', m: 0, w: false },
|
||||||
{ n: 'exhaust temperature', s: 'exhausttemp', m: 0 },
|
{ id: 'exhaust temperature', s: 'exhausttemp', m: 0, w: false },
|
||||||
{ v: false, n: 'gas', s: 'burngas', m: 0 },
|
{ v: false, id: 'gas', s: 'burngas', m: 0, w: false },
|
||||||
{ v: false, n: 'gas stage 2', s: 'burngas2', m: 0 },
|
{ v: false, id: 'gas stage 2', s: 'burngas2', m: 0, w: false },
|
||||||
{ v: 0, n: 'flame current', s: 'flamecurr', m: 0 },
|
{ v: 0, id: 'flame current', s: 'flamecurr', m: 0, w: false },
|
||||||
{ v: false, n: 'heating pump', s: 'heatingpump', m: 0 },
|
{ v: false, id: 'heating pump', s: 'heatingpump', m: 0, w: false },
|
||||||
{ v: false, n: 'fan', s: 'fanwork', m: 0 },
|
{ v: false, id: 'fan', s: 'fanwork', m: 0, w: false },
|
||||||
{ v: false, n: 'ignition', s: 'ignwork', m: 0 },
|
{ v: false, id: 'ignition', s: 'ignwork', m: 0, w: false },
|
||||||
{ v: false, n: 'oil preheating', s: 'oilpreheat', m: 0 },
|
{ v: false, id: 'oil preheating', s: 'oilpreheat', m: 0, w: false },
|
||||||
{ v: true, n: 'heating activated', s: 'heatingactivated', m: 0 },
|
{ v: true, id: 'heating activated', s: 'heatingactivated', m: 0, w: false },
|
||||||
{ v: 80, n: 'heating temperature', s: 'heatingtemp', m: 0 },
|
{ v: 80, id: 'heating temperature', s: 'heatingtemp', m: 0, w: false },
|
||||||
{ v: 70, n: 'burner pump max power', s: 'pumpmodmax', m: 0 },
|
{ v: 70, id: 'burner pump max power', s: 'pumpmodmax', m: 0, w: false },
|
||||||
{ v: 30, n: 'burner pump min power', s: 'pumpmodmin', m: 0 },
|
{ v: 30, id: 'burner pump min power', s: 'pumpmodmin', m: 0, w: false },
|
||||||
{ v: 1, n: 'pump delay', s: 'pumpdelay', m: 0 },
|
{ v: 1, id: 'pump delay', s: 'pumpdelay', m: 0, w: false },
|
||||||
{ v: 10, n: 'burner min period', s: 'burnminperiod', m: 0 },
|
{ v: 10, id: 'burner min period', s: 'burnminperiod', m: 0, w: false },
|
||||||
{ v: 0, n: 'burner min power', s: 'burnminpower', m: 0 },
|
{ v: 0, id: 'burner min power', s: 'burnminpower', m: 0, w: false },
|
||||||
{ v: 50, n: 'burner max power', s: 'burnmaxpower', m: 0 },
|
{ v: 50, id: 'burner max power', s: 'burnmaxpower', m: 0, w: false },
|
||||||
{ v: -6, n: 'hysteresis on temperature', s: 'boilhyston', m: 0 },
|
{ v: -6, id: 'hysteresis on temperature', s: 'boilhyston', m: 0, w: false },
|
||||||
{ v: 6, n: 'hysteresis off temperature', s: 'boilhystoff', m: 0 },
|
{ v: 6, id: 'hysteresis off temperature', s: 'boilhystoff', m: 0, w: false },
|
||||||
{ v: 0, n: 'set flow temperature', s: 'setflowtemp', m: 0 },
|
{ v: 0, id: 'set flow temperature', s: 'setflowtemp', m: 0, w: true },
|
||||||
{ v: 0, n: 'burner set power', s: 'setburnpow', m: 0 },
|
{ v: 0, id: 'burner set power', s: 'setburnpow', m: 0, w: false },
|
||||||
{ v: 0, n: 'burner current power', s: 'curburnpow', m: 0 },
|
{ v: 0, id: 'burner current power', s: 'curburnpow', m: 0, w: false },
|
||||||
{ v: 326323, n: 'burner starts', s: 'burnstarts', m: 0 },
|
{ v: 326323, id: 'burner starts', s: 'burnstarts', m: 0, w: false },
|
||||||
{ v: 553437, n: 'total burner operating time', s: 'burnworkmin', m: 0 },
|
{ v: 553437, id: 'total burner operating time', s: 'burnworkmin', m: 0, w: false },
|
||||||
{ v: 451286, n: 'total heat operating time', s: 'heatworkmin', m: 0 },
|
{ v: 451286, id: 'total heat operating time', s: 'heatworkmin', m: 0, w: false },
|
||||||
{ v: 4672175, n: 'total UBA operating time', s: 'ubauptime', m: 0 },
|
{ v: 4672175, id: 'total UBA operating time', s: 'ubauptime', m: 0, w: false },
|
||||||
{ v: '1C(210) 06.06.2020 12:07 (0 min)', n: 'last error code', s: 'lastcode', m: 0 },
|
{ v: '1C(210) 06.06.2020 12:07 (0 min)', id: 'last error code', s: 'lastcode', m: 0, w: false },
|
||||||
{ v: '0H', n: 'service code', s: 'servicecode', m: 0 },
|
{ v: '0H', id: 'service code', s: 'servicecode', m: 0, w: false },
|
||||||
{ v: 203, n: 'service code number', s: 'servicecodenumber', m: 0 },
|
{ v: 203, id: 'service code number', s: 'servicecodenumber', m: 0, w: false },
|
||||||
{ v: 'H00', n: 'maintenance message', s: 'maintenancemessage', m: 0 },
|
{ v: 'H00', id: 'maintenance message', s: 'maintenancemessage', m: 0, w: false },
|
||||||
{ v: 'manual', n: 'maintenance scheduled', s: 'maintenance', m: 0 },
|
{ v: 'manual', id: 'maintenance scheduled', s: 'maintenance', m: 0, w: false },
|
||||||
{ v: 6000, n: 'time to next maintenance', s: 'maintenancetime', m: 0 },
|
{ v: 6000, id: 'time to next maintenance', s: 'maintenancetime', m: 0, w: false },
|
||||||
{ v: '01.01.2012', n: 'next maintenance date', s: 'maintenancedate', m: 0 },
|
{ v: '01.01.2012', id: 'next maintenance date', s: 'maintenancedate', m: 0, w: false },
|
||||||
{ v: true, n: 'dhw turn on/off', s: 'wwtapactivated', m: 0 },
|
{ v: true, id: 'dhw turn on/off', s: 'wwtapactivated', m: 0, w: false },
|
||||||
{ v: 62, n: 'dhw set temperature', s: 'wwsettemp', m: 0 },
|
{ v: 62, id: 'dhw set temperature', s: 'wwsettemp', m: 0, w: false },
|
||||||
{ v: 60, n: 'dhw selected temperature', s: 'wwseltemp', m: 0 },
|
{ v: 60, id: 'dhw selected temperature', s: 'wwseltemp', m: 0, w: true },
|
||||||
{ n: 'dhw selected lower temperature', s: 'wwseltemplow', m: 2 },
|
{ id: 'dhw selected lower temperature', s: 'wwseltemplow', m: 2 },
|
||||||
{ n: 'dhw selected temperature for off', s: 'wwseltempoff', m: 2 },
|
{ id: 'dhw selected temperature for off', s: 'wwseltempoff', m: 2 },
|
||||||
{ n: 'dhw single charge temperature', s: 'wwseltempsingle', m: 2 },
|
{ id: 'dhw single charge temperature', s: 'wwseltempsingle', m: 2 },
|
||||||
{ v: 'flow', n: 'dhw type', s: 'wwtype', m: 0 },
|
{ v: 'flow', id: 'dhw type', s: 'wwtype', m: 0, w: false },
|
||||||
{ v: 'hot', n: 'dhw comfort', s: 'wwcomfort', m: 0 },
|
{ v: 'hot', id: 'dhw comfort', s: 'wwcomfort', m: 0, w: false },
|
||||||
{ v: 40, n: 'dhw flow temperature offset', s: 'wwflowtempoffset', m: 0 },
|
{ v: 40, id: 'dhw flow temperature offset', s: 'wwflowtempoffset', m: 0, w: false },
|
||||||
{ v: 100, n: 'dhw max power', s: 'wwmaxpower', m: 0 },
|
{ v: 100, id: 'dhw max power', s: 'wwmaxpower', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw circulation pump available', s: 'wwcircpump', m: 0 },
|
{ v: false, id: 'dhw circulation pump available', s: 'wwcircpump', m: 0, w: false },
|
||||||
{ v: '3-way valve', n: 'dhw charging type', s: 'wwchargetype', m: 0 },
|
{ v: '3-way valve', id: 'dhw charging type', s: 'wwchargetype', m: 0, w: false },
|
||||||
{ v: -5, n: 'dhw hysteresis on temperature', s: 'wwhyston', m: 0 },
|
{ v: -5, id: 'dhw hysteresis on temperature', s: 'wwhyston', m: 0, w: false },
|
||||||
{ v: 0, n: 'dhw hysteresis off temperature', s: 'wwhystoff', m: 0 },
|
{ v: 0, id: 'dhw hysteresis off temperature', s: 'wwhystoff', m: 0, w: false },
|
||||||
{ v: 70, n: 'dhw disinfection temperature', s: 'wwdisinfectiontemp', m: 0 },
|
{ v: 70, id: 'dhw disinfection temperature', s: 'wwdisinfectiontemp', m: 0, w: false },
|
||||||
{ v: 'off', n: 'dhw circulation pump mode', s: 'wwcircmode', m: 0 },
|
{ v: 'off', id: 'dhw circulation pump mode', s: 'wwcircmode', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw circulation active', s: 'wwcirc', m: 0 },
|
{ v: false, id: 'dhw circulation active', s: 'wwcirc', m: 0, w: false },
|
||||||
{ v: 46.4, n: 'dhw current intern temperature', s: 'wwcurtemp', m: 0 },
|
{ v: 46.4, id: 'dhw current intern temperature', s: 'wwcurtemp', m: 0, w: false },
|
||||||
{ n: 'dhw current extern temperature', s: 'wwcurtemp2', m: 2 },
|
{ id: 'dhw current extern temperature', s: 'wwcurtemp2', m: 2 },
|
||||||
{ v: 0, n: 'dhw current tap water flow', s: 'wwcurflow', m: 0 },
|
{ v: 0, id: 'dhw current tap water flow', s: 'wwcurflow', m: 0, w: false },
|
||||||
{ v: 46.3, n: 'dhw storage intern temperature', s: 'wwstoragetemp1', m: 0 },
|
{ v: 46.3, id: 'dhw storage intern temperature', s: 'wwstoragetemp1', m: 0, w: false },
|
||||||
{ n: 'dhw storage extern temperature', s: 'wwstoragetemp2', m: 2 },
|
{ id: 'dhw storage extern temperature', s: 'wwstoragetemp2', m: 2 },
|
||||||
{ v: true, n: 'dhw activated', s: 'wwactivated', m: 0 },
|
{ v: true, id: 'dhw activated', s: 'wwactivated', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw one time charging', s: 'wwonetime', m: 0 },
|
{ v: false, id: 'dhw one time charging', s: 'wwonetime', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw disinfecting', s: 'wwdisinfecting', m: 0 },
|
{ v: false, id: 'dhw disinfecting', s: 'wwdisinfecting', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw charging', s: 'wwcharging', m: 0 },
|
{ v: false, id: 'dhw charging', s: 'wwcharging', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw recharging', s: 'wwrecharging', m: 0 },
|
{ v: false, id: 'dhw recharging', s: 'wwrecharging', m: 0, w: false },
|
||||||
{ v: true, n: 'dhw temperature ok', s: 'wwtempok', m: 0 },
|
{ v: true, id: 'dhw temperature ok', s: 'wwtempok', m: 0, w: false },
|
||||||
{ v: false, n: 'dhw active', s: 'wwactive', m: 0 },
|
{ v: false, id: 'dhw active', s: 'wwactive', m: 0, w: false },
|
||||||
{ v: true, n: 'dhw 3way valve active', s: 'ww3wayvalve', m: 0 },
|
{ v: true, id: 'dhw 3way valve active', s: 'ww3wayvalve', m: 0, w: false },
|
||||||
{ v: 0, n: 'dhw set pump power', s: 'wwsetpumppower', m: 0 },
|
{ v: 0, id: 'dhw set pump power', s: 'wwsetpumppower', m: 0, w: true },
|
||||||
{ n: 'dhw mixer temperature', s: 'wwmixertemp', m: 2 },
|
{ id: 'dhw mixer temperature', s: 'wwmixertemp', m: 2 },
|
||||||
{ n: 'dhw cylinder middle temperature (TS3)', s: 'wwcylmiddletemp', m: 2 },
|
{ id: 'dhw cylinder middle temperature (TS3)', s: 'wwcylmiddletemp', m: 2 },
|
||||||
{ v: 288768, n: 'dhw starts', s: 'wwstarts', m: 0 },
|
{ v: 288768, id: 'dhw starts', s: 'wwstarts', m: 0, w: false },
|
||||||
{ v: 102151, n: 'dhw active time', s: 'wwworkm', m: 0 },
|
{ v: 102151, id: 'dhw active time', s: 'wwworkm', m: 0, w: false },
|
||||||
]
|
]
|
||||||
|
|
||||||
const emsesp_deviceentities_4 = [
|
const emsesp_deviceentities_4 = [
|
||||||
{
|
{
|
||||||
v: 16,
|
v: 16,
|
||||||
n: 'hc2 selected room temperature',
|
id: 'hc2 selected room temperature',
|
||||||
s: 'hc2/seltemp',
|
s: 'hc2/seltemp',
|
||||||
m: 0,
|
m: 8,
|
||||||
w: true,
|
w: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 18.5,
|
v: 18.5,
|
||||||
n: 'hc2 current room temperature',
|
id: 'hc2 current room temperature',
|
||||||
s: 'hc2/curtemp',
|
s: 'hc2/curtemp',
|
||||||
m: 3,
|
m: 2,
|
||||||
w: false,
|
w: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
v: 'off',
|
v: 'off',
|
||||||
n: 'hc2 mode',
|
id: 'hc2 mode',
|
||||||
s: 'hc2/mode',
|
s: 'hc2/mode',
|
||||||
m: 3,
|
m: 2,
|
||||||
w: true,
|
w: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -870,9 +853,11 @@ rest_server.post(EMSESP_SETTINGS_ENDPOINT, (req, res) => {
|
|||||||
// res.status(200).json(settings); // no restart needed
|
// res.status(200).json(settings); // no restart needed
|
||||||
})
|
})
|
||||||
rest_server.get(EMSESP_CORE_DATA_ENDPOINT, (req, res) => {
|
rest_server.get(EMSESP_CORE_DATA_ENDPOINT, (req, res) => {
|
||||||
|
console.log('send back core data...')
|
||||||
res.json(emsesp_coredata)
|
res.json(emsesp_coredata)
|
||||||
})
|
})
|
||||||
rest_server.get(EMSESP_SENSOR_DATA_ENDPOINT, (req, res) => {
|
rest_server.get(EMSESP_SENSOR_DATA_ENDPOINT, (req, res) => {
|
||||||
|
console.log('send back sensor data...')
|
||||||
res.json(emsesp_sensordata)
|
res.json(emsesp_sensordata)
|
||||||
})
|
})
|
||||||
rest_server.get(EMSESP_DEVICES_ENDPOINT, (req, res) => {
|
rest_server.get(EMSESP_DEVICES_ENDPOINT, (req, res) => {
|
||||||
@@ -887,6 +872,7 @@ rest_server.get(EMSESP_STATUS_ENDPOINT, (req, res) => {
|
|||||||
})
|
})
|
||||||
rest_server.post(EMSESP_DEVICEDATA_ENDPOINT, (req, res) => {
|
rest_server.post(EMSESP_DEVICEDATA_ENDPOINT, (req, res) => {
|
||||||
const id = req.body.id
|
const id = req.body.id
|
||||||
|
console.log('send back device data for ' + id)
|
||||||
if (id === 1) {
|
if (id === 1) {
|
||||||
const encoded = msgpack.encode(emsesp_devicedata_1)
|
const encoded = msgpack.encode(emsesp_devicedata_1)
|
||||||
res.write(encoded, 'binary')
|
res.write(encoded, 'binary')
|
||||||
@@ -930,15 +916,15 @@ function updateMask(entity, de, dd) {
|
|||||||
objIndex = de.findIndex((obj) => obj.s == name)
|
objIndex = de.findIndex((obj) => obj.s == name)
|
||||||
if (objIndex !== -1) {
|
if (objIndex !== -1) {
|
||||||
de[objIndex].m = new_mask
|
de[objIndex].m = new_mask
|
||||||
const fullname = de[objIndex].n
|
const fullname = de[objIndex].id
|
||||||
objIndex = dd.data.findIndex((obj) => obj.n.slice(2) == fullname)
|
objIndex = dd.data.findIndex((obj) => obj.id.slice(2) == fullname)
|
||||||
if (objIndex !== -1) {
|
if (objIndex !== -1) {
|
||||||
// see if the mask has changed
|
// see if the mask has changed
|
||||||
const old_mask = parseInt(dd.data[objIndex].n.slice(0, 2), 16)
|
const old_mask = parseInt(dd.data[objIndex].id.slice(0, 2), 16)
|
||||||
if (old_mask !== new_mask) {
|
if (old_mask !== new_mask) {
|
||||||
const mask_hex = entity.slice(0, 2)
|
const mask_hex = entity.slice(0, 2)
|
||||||
console.log('Updating ' + dd.data[objIndex].n + ' -> ' + mask_hex + fullname)
|
console.log('Updating ' + dd.data[objIndex].id + ' -> ' + mask_hex + fullname)
|
||||||
dd.data[objIndex].n = mask_hex + fullname
|
dd.data[objIndex].id = mask_hex + fullname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -948,6 +934,7 @@ function updateMask(entity, de, dd) {
|
|||||||
|
|
||||||
rest_server.post(EMSESP_MASKED_ENTITIES_ENDPOINT, (req, res) => {
|
rest_server.post(EMSESP_MASKED_ENTITIES_ENDPOINT, (req, res) => {
|
||||||
const id = req.body.id
|
const id = req.body.id
|
||||||
|
console.log('customization id = ' + id)
|
||||||
console.log(req.body.entity_ids)
|
console.log(req.body.entity_ids)
|
||||||
for (const entity of req.body.entity_ids) {
|
for (const entity of req.body.entity_ids) {
|
||||||
if (id === 1) {
|
if (id === 1) {
|
||||||
@@ -986,7 +973,7 @@ rest_server.post(EMSESP_WRITE_VALUE_ENDPOINT, (req, res) => {
|
|||||||
rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => {
|
rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => {
|
||||||
const sensor = req.body
|
const sensor = req.body
|
||||||
console.log('Write sensor: ' + JSON.stringify(sensor))
|
console.log('Write sensor: ' + JSON.stringify(sensor))
|
||||||
objIndex = emsesp_sensordata.sensors.findIndex((obj) => obj.is == sensor.id_str)
|
objIndex = emsesp_sensordata.sensors.findIndex((obj) => obj.id == sensor.id)
|
||||||
emsesp_sensordata.sensors[objIndex].n = sensor.name
|
emsesp_sensordata.sensors[objIndex].n = sensor.name
|
||||||
emsesp_sensordata.sensors[objIndex].o = sensor.offset
|
emsesp_sensordata.sensors[objIndex].o = sensor.offset
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
@@ -995,12 +982,13 @@ rest_server.post(EMSESP_WRITE_SENSOR_ENDPOINT, (req, res) => {
|
|||||||
rest_server.post(EMSESP_WRITE_ANALOG_ENDPOINT, (req, res) => {
|
rest_server.post(EMSESP_WRITE_ANALOG_ENDPOINT, (req, res) => {
|
||||||
const analog = req.body
|
const analog = req.body
|
||||||
console.log('Write analog: ' + JSON.stringify(analog))
|
console.log('Write analog: ' + JSON.stringify(analog))
|
||||||
objIndex = emsesp_sensordata.analogs.findIndex((obj) => obj.i == analog.id)
|
objIndex = emsesp_sensordata.analogs.findIndex((obj) => obj.i == analog.i)
|
||||||
|
|
||||||
if (objIndex === -1) {
|
if (objIndex === -1) {
|
||||||
console.log('new analog')
|
console.log('new analog')
|
||||||
emsesp_sensordata.analogs.push({
|
emsesp_sensordata.analogs.push({
|
||||||
i: analog.id,
|
id: analog.i.toString(),
|
||||||
|
i: analog.i,
|
||||||
n: analog.name,
|
n: analog.name,
|
||||||
f: analog.factor,
|
f: analog.factor,
|
||||||
o: analog.offset,
|
o: analog.offset,
|
||||||
@@ -1009,9 +997,10 @@ rest_server.post(EMSESP_WRITE_ANALOG_ENDPOINT, (req, res) => {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (analog.type === -1) {
|
if (analog.type === -1) {
|
||||||
console.log('removing analog ' + analog.id)
|
console.log('removing analog ' + analog.i)
|
||||||
emsesp_sensordata.analogs[objIndex].t = -1
|
emsesp_sensordata.analogs[objIndex].t = -1
|
||||||
} else {
|
} else {
|
||||||
|
console.log('updating analog ' + analog.i)
|
||||||
emsesp_sensordata.analogs[objIndex].n = analog.name
|
emsesp_sensordata.analogs[objIndex].n = analog.name
|
||||||
emsesp_sensordata.analogs[objIndex].o = analog.offset
|
emsesp_sensordata.analogs[objIndex].o = analog.offset
|
||||||
emsesp_sensordata.analogs[objIndex].f = analog.factor
|
emsesp_sensordata.analogs[objIndex].f = analog.factor
|
||||||
|
|||||||
@@ -61,10 +61,7 @@ extra_scripts =
|
|||||||
pre:scripts/build_interface.py
|
pre:scripts/build_interface.py
|
||||||
scripts/rename_fw.py
|
scripts/rename_fw.py
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32
|
platform = espressif32@3.5.0
|
||||||
; platform_packages =
|
|
||||||
; toolchain-xtensa32@~2.80400.0
|
|
||||||
; framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git
|
|
||||||
board_build.partitions = esp32_partition_app1984k_spiffs64k.csv
|
board_build.partitions = esp32_partition_app1984k_spiffs64k.csv
|
||||||
build_flags = ${common.build_flags}
|
build_flags = ${common.build_flags}
|
||||||
build_unflags = ${common.unbuild_flags}
|
build_unflags = ${common.unbuild_flags}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ void AnalogSensor::reload() {
|
|||||||
// update existing sensors
|
// update existing sensors
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto & sensor : settings.analogCustomizations) { //search customlist
|
for (const auto & sensor : settings.analogCustomizations) { //search customlist
|
||||||
if (sensor_.id() == sensor.id) {
|
if (sensor_.gpio() == sensor.gpio) {
|
||||||
// for output sensors set value to new start-value
|
// for output sensors set value to new start-value
|
||||||
if ((sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT)
|
if ((sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT)
|
||||||
&& (sensor_.type() != sensor.type || sensor_.offset() != sensor.offset || sensor_.factor() != sensor.factor)) {
|
&& (sensor_.type() != sensor.type || sensor_.offset() != sensor.offset || sensor_.factor() != sensor.factor)) {
|
||||||
@@ -94,12 +94,12 @@ void AnalogSensor::reload() {
|
|||||||
for (const auto & sensor : settings.analogCustomizations) {
|
for (const auto & sensor : settings.analogCustomizations) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (const auto & sensor_ : sensors_) {
|
for (const auto & sensor_ : sensors_) {
|
||||||
if (sensor_.id() == sensor.id) {
|
if (sensor_.gpio() == sensor.gpio) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
sensors_.emplace_back(sensor.id, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type);
|
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type);
|
||||||
sensors_.back().ha_registered = false; // this will trigger recrate of the HA config
|
sensors_.back().ha_registered = false; // this will trigger recrate of the HA config
|
||||||
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
||||||
sensors_.back().set_value(sensor.offset);
|
sensors_.back().set_value(sensor.offset);
|
||||||
@@ -112,64 +112,64 @@ void AnalogSensor::reload() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// sort the list based on GPIO (id)
|
// sort the list based on GPIO (id)
|
||||||
std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.id() < b.id(); });
|
// std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.id() < b.id(); });
|
||||||
|
|
||||||
// activate each sensor
|
// activate each sensor
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
sensor.ha_registered = false; // force HA configs to be re-created
|
sensor.ha_registered = false; // force HA configs to be re-created
|
||||||
if (sensor.type() == AnalogType::ADC) {
|
if (sensor.type() == AnalogType::ADC) {
|
||||||
LOG_DEBUG(F("Adding analog ADC sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding analog ADC sensor on GPIO%d"), sensor.gpio());
|
||||||
// analogSetPinAttenuation does not work with analogReadMilliVolts
|
// analogSetPinAttenuation does not work with analogReadMilliVolts
|
||||||
sensor.analog_ = 0; // initialize
|
sensor.analog_ = 0; // initialize
|
||||||
sensor.last_reading_ = 0;
|
sensor.last_reading_ = 0;
|
||||||
} else if (sensor.type() == AnalogType::COUNTER) {
|
} else if (sensor.type() == AnalogType::COUNTER) {
|
||||||
LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.gpio());
|
||||||
pinMode(sensor.id(), INPUT_PULLUP);
|
pinMode(sensor.gpio(), INPUT_PULLUP);
|
||||||
if (sensor.id() == 25 || sensor.id() == 26) {
|
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
|
||||||
dacWrite(sensor.id(), 255);
|
dacWrite(sensor.gpio(), 255);
|
||||||
}
|
}
|
||||||
sensor.polltime_ = 0;
|
sensor.polltime_ = 0;
|
||||||
sensor.poll_ = digitalRead(sensor.id());
|
sensor.poll_ = digitalRead(sensor.gpio());
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
} else if (sensor.type() == AnalogType::TIMER || sensor.type() == AnalogType::RATE) {
|
} else if (sensor.type() == AnalogType::TIMER || sensor.type() == AnalogType::RATE) {
|
||||||
LOG_DEBUG(F("Adding analog Timer/Rate sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding analog Timer/Rate sensor on GPIO%d"), sensor.gpio());
|
||||||
pinMode(sensor.id(), INPUT_PULLUP);
|
pinMode(sensor.gpio(), INPUT_PULLUP);
|
||||||
sensor.polltime_ = uuid::get_uptime();
|
sensor.polltime_ = uuid::get_uptime();
|
||||||
sensor.last_polltime_ = uuid::get_uptime();
|
sensor.last_polltime_ = uuid::get_uptime();
|
||||||
sensor.poll_ = digitalRead(sensor.id());
|
sensor.poll_ = digitalRead(sensor.gpio());
|
||||||
sensor.set_offset(0);
|
sensor.set_offset(0);
|
||||||
sensor.set_value(0);
|
sensor.set_value(0);
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
} else if (sensor.type() == AnalogType::DIGITAL_IN) {
|
} else if (sensor.type() == AnalogType::DIGITAL_IN) {
|
||||||
LOG_DEBUG(F("Adding analog Read sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding analog Read sensor on GPIO%d"), sensor.gpio());
|
||||||
pinMode(sensor.id(), INPUT_PULLUP);
|
pinMode(sensor.gpio(), INPUT_PULLUP);
|
||||||
sensor.set_value(digitalRead(sensor.id())); // initial value
|
sensor.set_value(digitalRead(sensor.gpio())); // initial value
|
||||||
sensor.set_uom(0); // no uom, just for safe measures
|
sensor.set_uom(0); // no uom, just for safe measures
|
||||||
sensor.polltime_ = 0;
|
sensor.polltime_ = 0;
|
||||||
sensor.poll_ = digitalRead(sensor.id());
|
sensor.poll_ = digitalRead(sensor.gpio());
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
} else if (sensor.type() == AnalogType::DIGITAL_OUT) {
|
} else if (sensor.type() == AnalogType::DIGITAL_OUT) {
|
||||||
LOG_DEBUG(F("Adding analog Write sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding analog Write sensor on GPIO%d"), sensor.gpio());
|
||||||
pinMode(sensor.id(), OUTPUT);
|
pinMode(sensor.gpio(), OUTPUT);
|
||||||
if (sensor.id() == 25 || sensor.id() == 26) {
|
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
|
||||||
if (sensor.offset() > 255) {
|
if (sensor.offset() > 255) {
|
||||||
sensor.set_offset(255);
|
sensor.set_offset(255);
|
||||||
} else if (sensor.offset() < 0) {
|
} else if (sensor.offset() < 0) {
|
||||||
sensor.set_offset(0);
|
sensor.set_offset(0);
|
||||||
}
|
}
|
||||||
dacWrite(sensor.id(), sensor.offset());
|
dacWrite(sensor.gpio(), sensor.offset());
|
||||||
sensor.set_value(sensor.offset());
|
sensor.set_value(sensor.offset());
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(sensor.id(), sensor.offset() > 0 ? 1 : 0);
|
digitalWrite(sensor.gpio(), sensor.offset() > 0 ? 1 : 0);
|
||||||
sensor.set_value(digitalRead(sensor.id()));
|
sensor.set_value(digitalRead(sensor.gpio()));
|
||||||
}
|
}
|
||||||
sensor.set_uom(0); // no uom, just for safe measures
|
sensor.set_uom(0); // no uom, just for safe measures
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
} else if (sensor.type() >= AnalogType::PWM_0) {
|
} else if (sensor.type() >= AnalogType::PWM_0) {
|
||||||
LOG_DEBUG(F("Adding PWM output sensor on GPIO%d"), sensor.id());
|
LOG_DEBUG(F("Adding PWM output sensor on GPIO%d"), sensor.gpio());
|
||||||
uint channel = sensor.type() - AnalogType::PWM_0;
|
uint channel = sensor.type() - AnalogType::PWM_0;
|
||||||
ledcSetup(channel, sensor.factor(), 13);
|
ledcSetup(channel, sensor.factor(), 13);
|
||||||
ledcAttachPin(sensor.id(), channel);
|
ledcAttachPin(sensor.gpio(), channel);
|
||||||
if (sensor.offset() > 100) {
|
if (sensor.offset() > 100) {
|
||||||
sensor.set_offset(100);
|
sensor.set_offset(100);
|
||||||
} else if (sensor.offset() < 0) {
|
} else if (sensor.offset() < 0) {
|
||||||
@@ -193,8 +193,8 @@ void AnalogSensor::measure() {
|
|||||||
// go through the list of adc sensors
|
// go through the list of adc sensors
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
if (sensor.type() == AnalogType::ADC) {
|
if (sensor.type() == AnalogType::ADC) {
|
||||||
uint16_t a = analogReadMilliVolts(sensor.id()); // e.g. ADC1_CHANNEL_0_GPIO_NUM
|
uint16_t a = analogReadMilliVolts(sensor.gpio()); // e.g. ADC1_CHANNEL_0_GPIO_NUM
|
||||||
if (!sensor.analog_) { // init first time
|
if (!sensor.analog_) { // init first time
|
||||||
sensor.analog_ = a;
|
sensor.analog_ = a;
|
||||||
sensor.sum_ = a * 512;
|
sensor.sum_ = a * 512;
|
||||||
} else { // simple moving average filter
|
} else { // simple moving average filter
|
||||||
@@ -218,7 +218,7 @@ void AnalogSensor::measure() {
|
|||||||
if (sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::COUNTER || sensor.type() == AnalogType::TIMER
|
if (sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::COUNTER || sensor.type() == AnalogType::TIMER
|
||||||
|| sensor.type() == AnalogType::RATE) {
|
|| sensor.type() == AnalogType::RATE) {
|
||||||
auto old_value = sensor.value(); // remember current value before reading
|
auto old_value = sensor.value(); // remember current value before reading
|
||||||
auto current_reading = digitalRead(sensor.id());
|
auto current_reading = digitalRead(sensor.gpio());
|
||||||
if (sensor.poll_ != current_reading) { // check for pinchange
|
if (sensor.poll_ != current_reading) { // check for pinchange
|
||||||
sensor.polltime_ = uuid::get_uptime(); // remember time of pinchange
|
sensor.polltime_ = uuid::get_uptime(); // remember time of pinchange
|
||||||
sensor.poll_ = current_reading;
|
sensor.poll_ = current_reading;
|
||||||
@@ -258,17 +258,17 @@ void AnalogSensor::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update analog information name and offset
|
// update analog information name and offset
|
||||||
bool AnalogSensor::update(uint8_t id, const std::string & name, float offset, float factor, uint8_t uom, int8_t type) {
|
bool AnalogSensor::update(uint8_t gpio, const std::string & name, float offset, float factor, uint8_t uom, int8_t type) {
|
||||||
boolean found_sensor = false; // see if we can find the sensor in our customization list
|
boolean found_sensor = false; // see if we can find the sensor in our customization list
|
||||||
|
|
||||||
EMSESP::webCustomizationService.update(
|
EMSESP::webCustomizationService.update(
|
||||||
[&](WebCustomization & settings) {
|
[&](WebCustomization & settings) {
|
||||||
for (auto & AnalogCustomization : settings.analogCustomizations) {
|
for (auto & AnalogCustomization : settings.analogCustomizations) {
|
||||||
if (AnalogCustomization.id == id) {
|
if (AnalogCustomization.gpio == gpio) {
|
||||||
found_sensor = true; // found the record
|
found_sensor = true; // found the record
|
||||||
// see if it's marked for deletion
|
// see if it's marked for deletion
|
||||||
if (type == AnalogType::MARK_DELETED) {
|
if (type == AnalogType::MARK_DELETED) {
|
||||||
LOG_DEBUG(F("Removing analog sensor ID %d"), id);
|
LOG_DEBUG(F("Removing analog sensor GPIO %d"), gpio);
|
||||||
settings.analogCustomizations.remove(AnalogCustomization);
|
settings.analogCustomizations.remove(AnalogCustomization);
|
||||||
} else {
|
} else {
|
||||||
// update existing record
|
// update existing record
|
||||||
@@ -277,7 +277,7 @@ bool AnalogSensor::update(uint8_t id, const std::string & name, float offset, fl
|
|||||||
AnalogCustomization.factor = factor;
|
AnalogCustomization.factor = factor;
|
||||||
AnalogCustomization.uom = uom;
|
AnalogCustomization.uom = uom;
|
||||||
AnalogCustomization.type = type;
|
AnalogCustomization.type = type;
|
||||||
LOG_DEBUG(F("Customizing existing analog sensor ID %d"), id);
|
LOG_DEBUG(F("Customizing existing analog GPIO %d"), gpio);
|
||||||
}
|
}
|
||||||
return StateUpdateResult::CHANGED; // persist the change
|
return StateUpdateResult::CHANGED; // persist the change
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ bool AnalogSensor::update(uint8_t id, const std::string & name, float offset, fl
|
|||||||
|
|
||||||
// if the sensor exists and we're using HA, delete the old HA record
|
// if the sensor exists and we're using HA, delete the old HA record
|
||||||
if (found_sensor && Mqtt::ha_enabled()) {
|
if (found_sensor && Mqtt::ha_enabled()) {
|
||||||
remove_ha_topic(id); // id is the GPIO
|
remove_ha_topic(gpio); // the GPIO
|
||||||
}
|
}
|
||||||
|
|
||||||
// we didn't find it, it's new, so create and store it
|
// we didn't find it, it's new, so create and store it
|
||||||
@@ -296,14 +296,14 @@ bool AnalogSensor::update(uint8_t id, const std::string & name, float offset, fl
|
|||||||
EMSESP::webCustomizationService.update(
|
EMSESP::webCustomizationService.update(
|
||||||
[&](WebCustomization & settings) {
|
[&](WebCustomization & settings) {
|
||||||
auto newSensor = AnalogCustomization();
|
auto newSensor = AnalogCustomization();
|
||||||
newSensor.id = id;
|
newSensor.gpio = gpio;
|
||||||
newSensor.name = name;
|
newSensor.name = name;
|
||||||
newSensor.offset = offset;
|
newSensor.offset = offset;
|
||||||
newSensor.factor = factor;
|
newSensor.factor = factor;
|
||||||
newSensor.uom = uom;
|
newSensor.uom = uom;
|
||||||
newSensor.type = type;
|
newSensor.type = type;
|
||||||
settings.analogCustomizations.push_back(newSensor);
|
settings.analogCustomizations.push_back(newSensor);
|
||||||
LOG_DEBUG(F("Adding new customization for analog sensor ID %d"), id);
|
LOG_DEBUG(F("Adding new customization for analog sensor GPIO %d"), gpio);
|
||||||
return StateUpdateResult::CHANGED; // persist the change
|
return StateUpdateResult::CHANGED; // persist the change
|
||||||
},
|
},
|
||||||
"local");
|
"local");
|
||||||
@@ -339,15 +339,15 @@ void AnalogSensor::publish_sensor(const Sensor & sensor) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send empty config topic to remove the entry from HA
|
// send empty config topic to remove the entry from HA
|
||||||
void AnalogSensor::remove_ha_topic(const uint8_t id) const {
|
void AnalogSensor::remove_ha_topic(const uint8_t gpio) const {
|
||||||
if (!Mqtt::ha_enabled()) {
|
if (!Mqtt::ha_enabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
LOG_DEBUG(F("Removing HA config for analog sensor ID %d"), id);
|
LOG_DEBUG(F("Removing HA config for analog sensor GPIO %d"), gpio);
|
||||||
#endif
|
#endif
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%d/config", Mqtt::base().c_str(), id);
|
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%d/config", Mqtt::base().c_str(), gpio);
|
||||||
Mqtt::publish_ha(topic);
|
Mqtt::publish_ha(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
if (Mqtt::is_nested() || Mqtt::ha_enabled()) {
|
if (Mqtt::is_nested() || Mqtt::ha_enabled()) {
|
||||||
// nested
|
// nested
|
||||||
char s[10];
|
char s[10];
|
||||||
JsonObject dataSensor = doc.createNestedObject(Helpers::smallitoa(s, sensor.id()));
|
JsonObject dataSensor = doc.createNestedObject(Helpers::smallitoa(s, sensor.gpio()));
|
||||||
dataSensor["name"] = sensor.name();
|
dataSensor["name"] = sensor.name();
|
||||||
switch (sensor.type()) {
|
switch (sensor.type()) {
|
||||||
case AnalogType::COUNTER:
|
case AnalogType::COUNTER:
|
||||||
@@ -391,7 +391,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
// create HA config
|
// create HA config
|
||||||
if (Mqtt::ha_enabled() && (!sensor.ha_registered || force)) {
|
if (Mqtt::ha_enabled() && (!sensor.ha_registered || force)) {
|
||||||
LOG_DEBUG(F("Recreating HA config for analog sensor ID %d"), sensor.id());
|
LOG_DEBUG(F("Recreating HA config for analog sensor GPIO %d"), sensor.gpio());
|
||||||
|
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
|
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
|
||||||
|
|
||||||
@@ -400,13 +400,13 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
config["stat_t"] = stat_t;
|
config["stat_t"] = stat_t;
|
||||||
|
|
||||||
char str[50];
|
char str[50];
|
||||||
snprintf(str, sizeof(str), "{{value_json['%d'].value}}", sensor.id());
|
snprintf(str, sizeof(str), "{{value_json['%d'].value}}", sensor.gpio());
|
||||||
config["val_tpl"] = str;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "Analog Sensor %s", sensor.name().c_str());
|
snprintf(str, sizeof(str), "Analog Sensor %s", sensor.name().c_str());
|
||||||
config["name"] = str;
|
config["name"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "analogsensor_%d", sensor.id());
|
snprintf(str, sizeof(str), "analogsensor_%d", sensor.gpio());
|
||||||
config["uniq_id"] = str;
|
config["uniq_id"] = str;
|
||||||
|
|
||||||
JsonObject dev = config.createNestedObject("dev");
|
JsonObject dev = config.createNestedObject("dev");
|
||||||
@@ -414,7 +414,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
ids.add("ems-esp");
|
ids.add("ems-esp");
|
||||||
|
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%d/config", Mqtt::base().c_str(), sensor.id());
|
snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%d/config", Mqtt::base().c_str(), sensor.gpio());
|
||||||
|
|
||||||
Mqtt::publish_ha(topic, config.as<JsonObject>());
|
Mqtt::publish_ha(topic, config.as<JsonObject>());
|
||||||
|
|
||||||
@@ -437,7 +437,7 @@ void AnalogSensor::publish_values(const bool force) {
|
|||||||
bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) const {
|
bool AnalogSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) const {
|
||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (strcmp(cmd, sensor.name().c_str()) == 0) {
|
if (strcmp(cmd, sensor.name().c_str()) == 0) {
|
||||||
output["id"] = sensor.id();
|
output["gpio"] = sensor.gpio();
|
||||||
output["name"] = sensor.name();
|
output["name"] = sensor.name();
|
||||||
output["type"] = sensor.type();
|
output["type"] = sensor.type();
|
||||||
output["uom"] = sensor.uom();
|
output["uom"] = sensor.uom();
|
||||||
@@ -460,7 +460,7 @@ bool AnalogSensor::command_info(const char * value, const int8_t id, JsonObject
|
|||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (id == -1) { // show number and id
|
if (id == -1) { // show number and id
|
||||||
JsonObject dataSensor = output.createNestedObject(sensor.name());
|
JsonObject dataSensor = output.createNestedObject(sensor.name());
|
||||||
dataSensor["id"] = sensor.id();
|
dataSensor["gpio"] = sensor.gpio();
|
||||||
dataSensor["type"] = FL_(enum_sensortype)[sensor.type()];
|
dataSensor["type"] = FL_(enum_sensortype)[sensor.type()];
|
||||||
if (sensor.type() == AnalogType::ADC) {
|
if (sensor.type() == AnalogType::ADC) {
|
||||||
dataSensor["uom"] = EMSdevice::uom_to_string(sensor.uom());
|
dataSensor["uom"] = EMSdevice::uom_to_string(sensor.uom());
|
||||||
@@ -486,8 +486,8 @@ bool AnalogSensor::command_info(const char * value, const int8_t id, JsonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this creates the sensor, initializing everything
|
// this creates the sensor, initializing everything
|
||||||
AnalogSensor::Sensor::Sensor(const uint8_t id, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type)
|
AnalogSensor::Sensor::Sensor(const uint8_t gpio, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type)
|
||||||
: id_(id)
|
: gpio_(gpio)
|
||||||
, name_(name)
|
, name_(name)
|
||||||
, offset_(offset)
|
, offset_(offset)
|
||||||
, factor_(factor)
|
, factor_(factor)
|
||||||
@@ -500,20 +500,20 @@ AnalogSensor::Sensor::Sensor(const uint8_t id, const std::string & name, const f
|
|||||||
std::string AnalogSensor::Sensor::name() const {
|
std::string AnalogSensor::Sensor::name() const {
|
||||||
if (name_.empty()) {
|
if (name_.empty()) {
|
||||||
char name[50];
|
char name[50];
|
||||||
snprintf(name, sizeof(name), "Analog Sensor GPIO%d", id_);
|
snprintf(name, sizeof(name), "Analog Sensor GPIO%d", gpio_);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the counter value, id is gpio-no
|
// set the counter value, id is gpio-no
|
||||||
bool AnalogSensor::command_setvalue(const char * value, const int8_t id) {
|
bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
|
||||||
float val;
|
float val;
|
||||||
if (!Helpers::value2float(value, val)) {
|
if (!Helpers::value2float(value, val)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
if (sensor.id() == id) {
|
if (sensor.gpio() == gpio) {
|
||||||
if (sensor.type() == AnalogType::COUNTER) {
|
if (sensor.type() == AnalogType::COUNTER) {
|
||||||
if (val < 0 || value[0] == '+') { // sign corrects values
|
if (val < 0 || value[0] == '+') { // sign corrects values
|
||||||
sensor.set_offset(sensor.value() + val);
|
sensor.set_offset(sensor.value() + val);
|
||||||
@@ -529,18 +529,18 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t id) {
|
|||||||
return true;
|
return true;
|
||||||
} else if (sensor.type() == AnalogType::DIGITAL_OUT) {
|
} else if (sensor.type() == AnalogType::DIGITAL_OUT) {
|
||||||
uint8_t v = val;
|
uint8_t v = val;
|
||||||
if (sensor.id() == 25 || sensor.id() == 26) {
|
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
|
||||||
sensor.set_offset(v);
|
sensor.set_offset(v);
|
||||||
sensor.set_value(v);
|
sensor.set_value(v);
|
||||||
pinMode(sensor.id(), OUTPUT);
|
pinMode(sensor.gpio(), OUTPUT);
|
||||||
dacWrite(sensor.id(), sensor.offset());
|
dacWrite(sensor.gpio(), sensor.offset());
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
return true;
|
return true;
|
||||||
} else if (v == 0 || v == 1) {
|
} else if (v == 0 || v == 1) {
|
||||||
sensor.set_offset(v);
|
sensor.set_offset(v);
|
||||||
sensor.set_value(v);
|
sensor.set_value(v);
|
||||||
pinMode(sensor.id(), OUTPUT);
|
pinMode(sensor.gpio(), OUTPUT);
|
||||||
digitalWrite(sensor.id(), sensor.offset() > 0 ? 1 : 0);
|
digitalWrite(sensor.gpio(), sensor.offset() > 0 ? 1 : 0);
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class AnalogSensor {
|
|||||||
public:
|
public:
|
||||||
class Sensor {
|
class Sensor {
|
||||||
public:
|
public:
|
||||||
Sensor(const uint8_t id, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type);
|
Sensor(const uint8_t gpio, const std::string & name, const float offset, const float factor, const uint8_t uom, const int8_t type);
|
||||||
~Sensor() = default;
|
~Sensor() = default;
|
||||||
|
|
||||||
void set_offset(const float offset) {
|
void set_offset(const float offset) {
|
||||||
@@ -48,8 +48,8 @@ class AnalogSensor {
|
|||||||
name_ = name;
|
name_ = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t id() const {
|
uint8_t gpio() const {
|
||||||
return id_;
|
return gpio_;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value() const {
|
float value() const {
|
||||||
@@ -99,7 +99,7 @@ class AnalogSensor {
|
|||||||
uint32_t last_polltime_ = 0; // for timer
|
uint32_t last_polltime_ = 0; // for timer
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t id_;
|
uint8_t gpio_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
float offset_;
|
float offset_;
|
||||||
float factor_;
|
float factor_;
|
||||||
@@ -157,7 +157,7 @@ class AnalogSensor {
|
|||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update(uint8_t id, const std::string & name, float offset, float factor, uint8_t uom, int8_t type);
|
bool update(uint8_t gpio, const std::string & name, float offset, float factor, uint8_t uom, int8_t type);
|
||||||
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const;
|
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const;
|
||||||
|
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
@@ -171,7 +171,7 @@ class AnalogSensor {
|
|||||||
static uuid::log::Logger logger_;
|
static uuid::log::Logger logger_;
|
||||||
|
|
||||||
void remove_ha_topic(const uint8_t id) const;
|
void remove_ha_topic(const uint8_t id) const;
|
||||||
bool command_setvalue(const char * value, const int8_t id);
|
bool command_setvalue(const char * value, const int8_t gpio);
|
||||||
void measure();
|
void measure();
|
||||||
bool command_info(const char * value, const int8_t id, JsonObject & output) const;
|
bool command_info(const char * value, const int8_t id, JsonObject & output) const;
|
||||||
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ void DallasSensor::loop() {
|
|||||||
// check if we already have this sensor
|
// check if we already have this sensor
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
if (sensor.id() == get_id(addr)) {
|
if (sensor.internal_id() == get_id(addr)) {
|
||||||
t += sensor.offset();
|
t += sensor.offset();
|
||||||
if (t != sensor.temperature_c) {
|
if (t != sensor.temperature_c) {
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
@@ -171,7 +171,7 @@ void DallasSensor::loop() {
|
|||||||
sensors_.back().apply_customization();
|
sensors_.back().apply_customization();
|
||||||
publish_sensor(sensors_.back()); // call publish single
|
publish_sensor(sensors_.back()); // call publish single
|
||||||
// sort the sensors based on name
|
// sort the sensors based on name
|
||||||
std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.name() < b.name(); });
|
// std::sort(sensors_.begin(), sensors_.end(), [](const Sensor & a, const Sensor & b) { return a.name() < b.name(); });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sensorfails_++;
|
sensorfails_++;
|
||||||
@@ -180,12 +180,12 @@ void DallasSensor::loop() {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
sensorfails_++;
|
sensorfails_++;
|
||||||
LOG_ERROR(F("Unknown dallas sensor %s"), Sensor(addr).id_str().c_str());
|
LOG_ERROR(F("Unknown dallas sensor %s"), Sensor(addr).id().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sensorfails_++;
|
sensorfails_++;
|
||||||
LOG_ERROR(F("Invalid dallas sensor %s"), Sensor(addr).id_str().c_str());
|
LOG_ERROR(F("Invalid dallas sensor %s"), Sensor(addr).id().c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!parasite_) {
|
if (!parasite_) {
|
||||||
@@ -229,7 +229,7 @@ bool DallasSensor::temperature_convert_complete() {
|
|||||||
int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
|
int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
if (!bus_.reset()) {
|
if (!bus_.reset()) {
|
||||||
LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Sensor(addr).id_str().c_str());
|
LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Sensor(addr).id().c_str());
|
||||||
return EMS_VALUE_SHORT_NOTSET;
|
return EMS_VALUE_SHORT_NOTSET;
|
||||||
}
|
}
|
||||||
YIELD;
|
YIELD;
|
||||||
@@ -241,7 +241,7 @@ int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
|
|||||||
YIELD;
|
YIELD;
|
||||||
|
|
||||||
if (!bus_.reset()) {
|
if (!bus_.reset()) {
|
||||||
LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Sensor(addr).id_str().c_str());
|
LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Sensor(addr).id().c_str());
|
||||||
return EMS_VALUE_SHORT_NOTSET;
|
return EMS_VALUE_SHORT_NOTSET;
|
||||||
}
|
}
|
||||||
YIELD;
|
YIELD;
|
||||||
@@ -257,7 +257,7 @@ int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
|
|||||||
scratchpad[6],
|
scratchpad[6],
|
||||||
scratchpad[7],
|
scratchpad[7],
|
||||||
scratchpad[8],
|
scratchpad[8],
|
||||||
Sensor(addr).id_str().c_str());
|
Sensor(addr).id().c_str());
|
||||||
return EMS_VALUE_SHORT_NOTSET;
|
return EMS_VALUE_SHORT_NOTSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,15 +290,15 @@ int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update dallas information name and offset
|
// update dallas information name and offset
|
||||||
bool DallasSensor::update(const std::string & id_str, const std::string & name, int16_t offset) {
|
bool DallasSensor::update(const std::string & id, const std::string & name, int16_t offset) {
|
||||||
// find the sensor
|
// find the sensor
|
||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
if (sensor.id_str() == id_str) {
|
if (sensor.id() == id) {
|
||||||
// found a match, update the sensor object
|
// found a match, update the sensor object
|
||||||
|
|
||||||
// if HA is enabled then delete the old record
|
// if HA is enabled then delete the old record
|
||||||
if (Mqtt::ha_enabled()) {
|
if (Mqtt::ha_enabled()) {
|
||||||
remove_ha_topic(id_str);
|
remove_ha_topic(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor.set_name(name);
|
sensor.set_name(name);
|
||||||
@@ -310,21 +310,21 @@ bool DallasSensor::update(const std::string & id_str, const std::string & name,
|
|||||||
// look it up to see if it exists
|
// look it up to see if it exists
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto & SensorCustomization : settings.sensorCustomizations) {
|
for (auto & SensorCustomization : settings.sensorCustomizations) {
|
||||||
if (SensorCustomization.id_str == id_str) {
|
if (SensorCustomization.id == id) {
|
||||||
SensorCustomization.name = name;
|
SensorCustomization.name = name;
|
||||||
SensorCustomization.offset = offset;
|
SensorCustomization.offset = offset;
|
||||||
found = true;
|
found = true;
|
||||||
LOG_DEBUG(F("Customizing existing sensor ID %s"), id_str.c_str());
|
LOG_DEBUG(F("Customizing existing sensor ID %s"), id.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
SensorCustomization newSensor = SensorCustomization();
|
SensorCustomization newSensor = SensorCustomization();
|
||||||
newSensor.id_str = id_str;
|
newSensor.id = id;
|
||||||
newSensor.name = name;
|
newSensor.name = name;
|
||||||
newSensor.offset = offset;
|
newSensor.offset = offset;
|
||||||
settings.sensorCustomizations.push_back(newSensor);
|
settings.sensorCustomizations.push_back(newSensor);
|
||||||
LOG_DEBUG(F("Adding new customization for sensor ID %s"), id_str.c_str());
|
LOG_DEBUG(F("Adding new customization for sensor ID %s"), id.c_str());
|
||||||
}
|
}
|
||||||
sensor.ha_registered = false; // it's changed so we may need to recreate the HA config
|
sensor.ha_registered = false; // it's changed so we may need to recreate the HA config
|
||||||
return StateUpdateResult::CHANGED;
|
return StateUpdateResult::CHANGED;
|
||||||
@@ -361,7 +361,7 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
|
|||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (id == -1) { // show number and id
|
if (id == -1) { // show number and id
|
||||||
JsonObject dataSensor = output.createNestedObject(sensor.name());
|
JsonObject dataSensor = output.createNestedObject(sensor.name());
|
||||||
dataSensor["id_str"] = sensor.id_str();
|
dataSensor["id"] = sensor.id();
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||||
}
|
}
|
||||||
@@ -377,8 +377,8 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject
|
|||||||
bool DallasSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) {
|
bool DallasSensor::get_value_info(JsonObject & output, const char * cmd, const int8_t id) {
|
||||||
for (const auto & sensor : sensors_) {
|
for (const auto & sensor : sensors_) {
|
||||||
if (strcmp(cmd, sensor.name().c_str()) == 0) {
|
if (strcmp(cmd, sensor.name().c_str()) == 0) {
|
||||||
output["id_str"] = sensor.id_str();
|
output["id"] = sensor.id();
|
||||||
output["name"] = sensor.name();
|
output["name"] = sensor.name();
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
output["value"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
output["value"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||||
}
|
}
|
||||||
@@ -408,15 +408,15 @@ void DallasSensor::publish_sensor(const Sensor & sensor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send empty config topic to remove the entry from HA
|
// send empty config topic to remove the entry from HA
|
||||||
void DallasSensor::remove_ha_topic(const std::string & id_str) {
|
void DallasSensor::remove_ha_topic(const std::string & id) {
|
||||||
if (!Mqtt::ha_enabled()) {
|
if (!Mqtt::ha_enabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
LOG_DEBUG(F("Removing HA config for temperature sensor ID %s"), id_str.c_str());
|
LOG_DEBUG(F("Removing HA config for temperature sensor ID %s"), id.c_str());
|
||||||
#endif
|
#endif
|
||||||
// use '_' as HA doesn't like '-' in the topic name
|
// use '_' as HA doesn't like '-' in the topic name
|
||||||
std::string sensorid = id_str;
|
std::string sensorid = id;
|
||||||
std::replace(sensorid.begin(), sensorid.end(), '-', '_');
|
std::replace(sensorid.begin(), sensorid.end(), '-', '_');
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), sensorid.c_str());
|
snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), sensorid.c_str());
|
||||||
@@ -442,7 +442,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
for (auto & sensor : sensors_) {
|
for (auto & sensor : sensors_) {
|
||||||
bool has_value = Helpers::hasValue(sensor.temperature_c);
|
bool has_value = Helpers::hasValue(sensor.temperature_c);
|
||||||
if (Mqtt::is_nested() || Mqtt::ha_enabled()) {
|
if (Mqtt::is_nested() || Mqtt::ha_enabled()) {
|
||||||
JsonObject dataSensor = doc.createNestedObject(sensor.id_str());
|
JsonObject dataSensor = doc.createNestedObject(sensor.id());
|
||||||
dataSensor["name"] = sensor.name();
|
dataSensor["name"] = sensor.name();
|
||||||
if (has_value) {
|
if (has_value) {
|
||||||
dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
dataSensor["temp"] = Helpers::round2((float)(sensor.temperature_c), 10, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||||
@@ -455,7 +455,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
// to e.g. homeassistant/sensor/ems-esp/dallassensor_28-233D-9497-0C03/config
|
// to e.g. homeassistant/sensor/ems-esp/dallassensor_28-233D-9497-0C03/config
|
||||||
if (Mqtt::ha_enabled()) {
|
if (Mqtt::ha_enabled()) {
|
||||||
if (!sensor.ha_registered || force) {
|
if (!sensor.ha_registered || force) {
|
||||||
LOG_DEBUG(F("Recreating HA config for sensor ID %s"), sensor.id_str().c_str());
|
LOG_DEBUG(F("Recreating HA config for sensor ID %s"), sensor.id().c_str());
|
||||||
|
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
|
StaticJsonDocument<EMSESP_JSON_SIZE_MEDIUM> config;
|
||||||
config["dev_cla"] = FJSON("temperature");
|
config["dev_cla"] = FJSON("temperature");
|
||||||
@@ -467,13 +467,13 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
config["unit_of_meas"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
||||||
|
|
||||||
char str[50];
|
char str[50];
|
||||||
snprintf(str, sizeof(str), "{{value_json['%s'].temp}}", sensor.id_str().c_str());
|
snprintf(str, sizeof(str), "{{value_json['%s'].temp}}", sensor.id().c_str());
|
||||||
config["val_tpl"] = str;
|
config["val_tpl"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "Temperature Sensor %s", sensor.name().c_str());
|
snprintf(str, sizeof(str), "Temperature Sensor %s", sensor.name().c_str());
|
||||||
config["name"] = str;
|
config["name"] = str;
|
||||||
|
|
||||||
snprintf(str, sizeof(str), "dallasensor_%s", sensor.id_str().c_str());
|
snprintf(str, sizeof(str), "dallasensor_%s", sensor.id().c_str());
|
||||||
config["uniq_id"] = str;
|
config["uniq_id"] = str;
|
||||||
|
|
||||||
JsonObject dev = config.createNestedObject("dev");
|
JsonObject dev = config.createNestedObject("dev");
|
||||||
@@ -482,7 +482,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
// use '_' as HA doesn't like '-' in the topic name
|
// use '_' as HA doesn't like '-' in the topic name
|
||||||
std::string sensorid = sensor.id_str();
|
std::string sensorid = sensor.id();
|
||||||
std::replace(sensorid.begin(), sensorid.end(), '-', '_');
|
std::replace(sensorid.begin(), sensorid.end(), '-', '_');
|
||||||
|
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), sensorid.c_str());
|
snprintf(topic, sizeof(topic), "sensor/%s/dallassensor_%s/config", Mqtt::base().c_str(), sensorid.c_str());
|
||||||
@@ -500,18 +500,18 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
|
|
||||||
// skip crc from id
|
// skip crc from id
|
||||||
DallasSensor::Sensor::Sensor(const uint8_t addr[])
|
DallasSensor::Sensor::Sensor(const uint8_t addr[])
|
||||||
: id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16)
|
: internal_id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16)
|
||||||
| ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) {
|
| ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) {
|
||||||
// create ID string
|
// create ID string
|
||||||
char id[20];
|
char id_s[20];
|
||||||
snprintf(id,
|
snprintf(id_s,
|
||||||
sizeof(id),
|
sizeof(id_s),
|
||||||
"%02X-%04X-%04X-%04X",
|
"%02X-%04X-%04X-%04X",
|
||||||
(unsigned int)(id_ >> 48) & 0xFF,
|
(unsigned int)(internal_id_ >> 48) & 0xFF,
|
||||||
(unsigned int)(id_ >> 32) & 0xFFFF,
|
(unsigned int)(internal_id_ >> 32) & 0xFFFF,
|
||||||
(unsigned int)(id_ >> 16) & 0xFFFF,
|
(unsigned int)(internal_id_ >> 16) & 0xFFFF,
|
||||||
(unsigned int)(id_)&0xFFFF);
|
(unsigned int)(internal_id_)&0xFFFF);
|
||||||
id_str_ = std::string(id);
|
id_ = std::string(id_s);
|
||||||
name_ = std::string{}; // name (alias) is empty
|
name_ = std::string{}; // name (alias) is empty
|
||||||
offset_ = 0; // 0 degrees offset
|
offset_ = 0; // 0 degrees offset
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ uint64_t DallasSensor::get_id(const uint8_t addr[]) {
|
|||||||
// if empty, return the ID as a string
|
// if empty, return the ID as a string
|
||||||
std::string DallasSensor::Sensor::name() const {
|
std::string DallasSensor::Sensor::name() const {
|
||||||
if (name_.empty()) {
|
if (name_.empty()) {
|
||||||
return id_str_;
|
return id_;
|
||||||
}
|
}
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
@@ -538,9 +538,9 @@ bool DallasSensor::Sensor::apply_customization() {
|
|||||||
if (!sensors.empty()) {
|
if (!sensors.empty()) {
|
||||||
for (const auto & sensor : sensors) {
|
for (const auto & sensor : sensors) {
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
LOG_DEBUG(F("Loading customization for dallas sensor %s"), sensor.id_str.c_str());
|
LOG_DEBUG(F("Loading customization for dallas sensor %s"), sensor.id.c_str());
|
||||||
#endif
|
#endif
|
||||||
if (id_str_ == sensor.id_str) {
|
if (id_ == sensor.id) {
|
||||||
set_name(sensor.name);
|
set_name(sensor.name);
|
||||||
set_offset(sensor.offset);
|
set_offset(sensor.offset);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ class DallasSensor {
|
|||||||
Sensor(const uint8_t addr[]);
|
Sensor(const uint8_t addr[]);
|
||||||
~Sensor() = default;
|
~Sensor() = default;
|
||||||
|
|
||||||
uint64_t id() const {
|
uint64_t internal_id() const {
|
||||||
return id_;
|
return internal_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string id_str() const {
|
std::string id() const {
|
||||||
return id_str_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t offset() const {
|
int16_t offset() const {
|
||||||
@@ -67,8 +67,8 @@ class DallasSensor {
|
|||||||
bool ha_registered = false;
|
bool ha_registered = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t id_;
|
uint64_t internal_id_;
|
||||||
std::string id_str_;
|
std::string id_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
int16_t offset_;
|
int16_t offset_;
|
||||||
};
|
};
|
||||||
@@ -109,7 +109,7 @@ class DallasSensor {
|
|||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update(const std::string & id_str, const std::string & name, int16_t offset);
|
bool update(const std::string & id, const std::string & name, int16_t offset);
|
||||||
|
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
void test();
|
void test();
|
||||||
@@ -150,7 +150,7 @@ class DallasSensor {
|
|||||||
bool temperature_convert_complete();
|
bool temperature_convert_complete();
|
||||||
int16_t get_temperature_c(const uint8_t addr[]);
|
int16_t get_temperature_c(const uint8_t addr[]);
|
||||||
uint64_t get_id(const uint8_t addr[]);
|
uint64_t get_id(const uint8_t addr[]);
|
||||||
void remove_ha_topic(const std::string & id_str);
|
void remove_ha_topic(const std::string & id);
|
||||||
|
|
||||||
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
bool command_info(const char * value, const int8_t id, JsonObject & output);
|
||||||
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
bool command_commands(const char * value, const int8_t id, JsonObject & output);
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class Boiler : public EMSdevice {
|
|||||||
// Pool unit
|
// Pool unit
|
||||||
int8_t poolSetTemp_;
|
int8_t poolSetTemp_;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hybrid heatpump with telegram 0xBB is readable and writeable in boiler and thermostat
|
* Hybrid heatpump with telegram 0xBB is readable and writeable in boiler and thermostat
|
||||||
* thermostat always overwrites settings in boiler
|
* thermostat always overwrites settings in boiler
|
||||||
* enable settings here if no thermostat is used in system
|
* enable settings here if no thermostat is used in system
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
|||||||
heating_circuits_.push_back(new_hc);
|
heating_circuits_.push_back(new_hc);
|
||||||
|
|
||||||
// sort based on hc number so there's a nice order when displaying
|
// sort based on hc number so there's a nice order when displaying
|
||||||
// TODO temporarily commented out the HC sorting until I'm 100% sure the return object still references the newly created object
|
// NOTE temporarily commented out the HC sorting until I'm 100% sure the return object still references the newly created object
|
||||||
// not sure if new_hc and heating_circuits_.back() will still reference the new HC after its sorted - to check!
|
// not sure if new_hc and heating_circuits_.back() will still reference the new HC after its sorted - to check!
|
||||||
// std::sort(heating_circuits_.begin(), heating_circuits_.end());
|
// std::sort(heating_circuits_.begin(), heating_circuits_.end());
|
||||||
|
|
||||||
|
|||||||
@@ -656,119 +656,118 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
|||||||
output["label"] = to_string_short();
|
output["label"] = to_string_short();
|
||||||
JsonArray data = output.createNestedArray("data");
|
JsonArray data = output.createNestedArray("data");
|
||||||
|
|
||||||
// do two passes. First for all entities marked as favorites, then for all others. This sorts the list.
|
for (auto & dv : devicevalues_) {
|
||||||
for (int8_t fav = 1; fav >= 0; fav--) {
|
// check conditions:
|
||||||
for (auto & dv : devicevalues_) {
|
// 1. full_name cannot be empty
|
||||||
// check conditions:
|
// 2. it must have a valid value, if it is not a command like 'reset'
|
||||||
// 1. full_name cannot be empty
|
// 3. show favorites first
|
||||||
// 2. it must have a valid value, if it is not a command like 'reset'
|
if (!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.full_name && (dv.hasValue() || (dv.type == DeviceValueType::CMD))) {
|
||||||
// 3. show favorites first
|
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
|
||||||
bool show = (fav && dv.has_state(DeviceValueState::DV_FAVORITE)) || (!fav && !dv.has_state(DeviceValueState::DV_FAVORITE));
|
uint8_t fahrenheit = 0;
|
||||||
if (show && !dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.full_name && (dv.hasValue() || (dv.type == DeviceValueType::CMD))) {
|
|
||||||
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
|
|
||||||
uint8_t fahrenheit = 0;
|
|
||||||
|
|
||||||
// handle Booleans (true, false), use strings, no native true/false)
|
// handle Booleans (true, false), use strings, no native true/false)
|
||||||
if (dv.type == DeviceValueType::BOOL) {
|
if (dv.type == DeviceValueType::BOOL) {
|
||||||
bool value_b = (bool)*(uint8_t *)(dv.value_p);
|
bool value_b = (bool)*(uint8_t *)(dv.value_p);
|
||||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||||
obj["v"] = value_b ? 1 : 0;
|
obj["v"] = value_b ? 1 : 0;
|
||||||
} else {
|
|
||||||
char s[7];
|
|
||||||
obj["v"] = Helpers::render_boolean(s, value_b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle TEXT strings
|
|
||||||
else if (dv.type == DeviceValueType::STRING) {
|
|
||||||
obj["v"] = (char *)(dv.value_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle ENUMs
|
|
||||||
else if ((dv.type == DeviceValueType::ENUM) && (*(uint8_t *)(dv.value_p) < dv.options_size)) {
|
|
||||||
obj["v"] = dv.options[*(uint8_t *)(dv.value_p)];
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle numbers
|
|
||||||
else {
|
|
||||||
// If a divider is specified, do the division to 2 decimals places and send back as double/float
|
|
||||||
// otherwise force as an integer whole
|
|
||||||
// the nested if's is necessary due to the way the ArduinoJson templates are pre-processed by the compiler
|
|
||||||
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
|
|
||||||
fahrenheit = !EMSESP::system_.fahrenheit() ? 0 : (dv.uom == DeviceValueUOM::DEGREES) ? 2 : (dv.uom == DeviceValueUOM::DEGREES_R) ? 1 : 0;
|
|
||||||
|
|
||||||
if ((dv.type == DeviceValueType::INT) && Helpers::hasValue(*(int8_t *)(dv.value_p))) {
|
|
||||||
obj["v"] = Helpers::round2(*(int8_t *)(dv.value_p), divider, fahrenheit);
|
|
||||||
} else if ((dv.type == DeviceValueType::UINT) && Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
|
||||||
obj["v"] = Helpers::round2(*(uint8_t *)(dv.value_p), divider, fahrenheit);
|
|
||||||
} else if ((dv.type == DeviceValueType::SHORT) && Helpers::hasValue(*(int16_t *)(dv.value_p))) {
|
|
||||||
obj["v"] = Helpers::round2(*(int16_t *)(dv.value_p), divider, fahrenheit);
|
|
||||||
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
|
||||||
obj["v"] = Helpers::round2(*(uint16_t *)(dv.value_p), divider, fahrenheit);
|
|
||||||
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
|
||||||
obj["v"] = Helpers::round2(*(uint32_t *)(dv.value_p), divider, fahrenheit);
|
|
||||||
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
|
||||||
uint32_t time_value = *(uint32_t *)(dv.value_p);
|
|
||||||
obj["v"] = (divider > 0) ? time_value / divider : time_value; // sometimes we need to divide by 60
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the unit of measure (uom)
|
|
||||||
obj["u"] = fahrenheit ? (uint8_t)DeviceValueUOM::FAHRENHEIT : dv.uom;
|
|
||||||
|
|
||||||
auto mask = Helpers::hextoa((uint8_t)(dv.state >> 4), false); // create mask to a 2-char string
|
|
||||||
|
|
||||||
// add name, prefixing the tag if it exists
|
|
||||||
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
|
|
||||||
obj["n"] = mask + read_flash_string(dv.full_name);
|
|
||||||
} else if (dv.tag < DeviceValueTAG::TAG_HC1) {
|
|
||||||
obj["n"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
|
|
||||||
} else {
|
} else {
|
||||||
obj["n"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
|
char s[7];
|
||||||
|
obj["v"] = Helpers::render_boolean(s, value_b);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add commands and options
|
// handle TEXT strings
|
||||||
if (dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY)) {
|
else if (dv.type == DeviceValueType::STRING) {
|
||||||
// add the name of the Command function
|
obj["v"] = (char *)(dv.value_p);
|
||||||
if (dv.tag >= DeviceValueTAG::TAG_HC1) {
|
}
|
||||||
obj["c"] = tag_to_mqtt(dv.tag) + "/" + read_flash_string(dv.short_name);
|
|
||||||
} else {
|
// handle ENUMs
|
||||||
obj["c"] = dv.short_name;
|
else if ((dv.type == DeviceValueType::ENUM) && (*(uint8_t *)(dv.value_p) < dv.options_size)) {
|
||||||
}
|
obj["v"] = dv.options[*(uint8_t *)(dv.value_p)];
|
||||||
// add the Command options
|
}
|
||||||
if (dv.type == DeviceValueType::ENUM || (dv.type == DeviceValueType::CMD && dv.options_size > 1)) {
|
|
||||||
JsonArray l = obj.createNestedArray("l");
|
// handle numbers
|
||||||
for (uint8_t i = 0; i < dv.options_size; i++) {
|
else {
|
||||||
if (!read_flash_string(dv.options[i]).empty()) {
|
// If a divider is specified, do the division to 2 decimals places and send back as double/float
|
||||||
l.add(read_flash_string(dv.options[i]));
|
// otherwise force as an integer whole
|
||||||
}
|
// the nested if's is necessary due to the way the ArduinoJson templates are pre-processed by the compiler
|
||||||
}
|
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
|
||||||
} else if (dv.type == DeviceValueType::BOOL) {
|
fahrenheit = !EMSESP::system_.fahrenheit() ? 0 : (dv.uom == DeviceValueUOM::DEGREES) ? 2 : (dv.uom == DeviceValueUOM::DEGREES_R) ? 1 : 0;
|
||||||
JsonArray l = obj.createNestedArray("l");
|
|
||||||
char result[10];
|
if ((dv.type == DeviceValueType::INT) && Helpers::hasValue(*(int8_t *)(dv.value_p))) {
|
||||||
l.add(Helpers::render_boolean(result, false));
|
obj["v"] = Helpers::round2(*(int8_t *)(dv.value_p), divider, fahrenheit);
|
||||||
l.add(Helpers::render_boolean(result, true));
|
} else if ((dv.type == DeviceValueType::UINT) && Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
||||||
}
|
obj["v"] = Helpers::round2(*(uint8_t *)(dv.value_p), divider, fahrenheit);
|
||||||
// add command help template
|
} else if ((dv.type == DeviceValueType::SHORT) && Helpers::hasValue(*(int16_t *)(dv.value_p))) {
|
||||||
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
|
obj["v"] = Helpers::round2(*(int16_t *)(dv.value_p), divider, fahrenheit);
|
||||||
if (dv.options_size == 1) {
|
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
||||||
obj["h"] = dv.options[0];
|
obj["v"] = Helpers::round2(*(uint16_t *)(dv.value_p), divider, fahrenheit);
|
||||||
|
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||||
|
obj["v"] = Helpers::round2(*(uint32_t *)(dv.value_p), divider, fahrenheit);
|
||||||
|
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||||
|
uint32_t time_value = *(uint32_t *)(dv.value_p);
|
||||||
|
obj["v"] = (divider > 0) ? time_value / divider : time_value; // sometimes we need to divide by 60
|
||||||
|
} else {
|
||||||
|
// must have a value for sorting to work
|
||||||
|
obj["v"] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the unit of measure (uom)
|
||||||
|
obj["u"] = fahrenheit ? (uint8_t)DeviceValueUOM::FAHRENHEIT : dv.uom;
|
||||||
|
|
||||||
|
auto mask = Helpers::hextoa((uint8_t)(dv.state >> 4), false); // create mask to a 2-char string
|
||||||
|
|
||||||
|
// add name, prefixing the tag if it exists. This is the id used for the table sorting
|
||||||
|
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
|
||||||
|
obj["id"] = mask + read_flash_string(dv.full_name);
|
||||||
|
} else if (dv.tag < DeviceValueTAG::TAG_HC1) {
|
||||||
|
obj["id"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
|
||||||
|
} else {
|
||||||
|
obj["id"] = mask + tag_to_string(dv.tag) + " " + read_flash_string(dv.full_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add commands and options
|
||||||
|
if (dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY)) {
|
||||||
|
// add the name of the Command function
|
||||||
|
if (dv.tag >= DeviceValueTAG::TAG_HC1) {
|
||||||
|
obj["c"] = tag_to_mqtt(dv.tag) + "/" + read_flash_string(dv.short_name);
|
||||||
|
} else {
|
||||||
|
obj["c"] = dv.short_name;
|
||||||
|
}
|
||||||
|
// add the Command options
|
||||||
|
if (dv.type == DeviceValueType::ENUM || (dv.type == DeviceValueType::CMD && dv.options_size > 1)) {
|
||||||
|
JsonArray l = obj.createNestedArray("l");
|
||||||
|
for (uint8_t i = 0; i < dv.options_size; i++) {
|
||||||
|
if (!read_flash_string(dv.options[i]).empty()) {
|
||||||
|
l.add(read_flash_string(dv.options[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add steps to numeric values with divider/multiplier
|
} else if (dv.type == DeviceValueType::BOOL) {
|
||||||
else {
|
JsonArray l = obj.createNestedArray("l");
|
||||||
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
|
char result[10];
|
||||||
char s[10];
|
l.add(Helpers::render_boolean(result, false));
|
||||||
if (divider > 0) {
|
l.add(Helpers::render_boolean(result, true));
|
||||||
obj["s"] = Helpers::render_value(s, (float)1 / divider, 1);
|
}
|
||||||
} else if (divider < 0) {
|
// add command help template
|
||||||
obj["s"] = Helpers::render_value(s, (-1) * divider, 0);
|
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
|
||||||
}
|
if (dv.options_size == 1) {
|
||||||
int16_t dv_set_min, dv_set_max;
|
obj["h"] = dv.options[0];
|
||||||
if (dv.get_min_max(dv_set_min, dv_set_max)) {
|
}
|
||||||
obj["m"] = Helpers::render_value(s, dv_set_min, 0);
|
}
|
||||||
obj["x"] = Helpers::render_value(s, dv_set_max, 0);
|
// add steps to numeric values with divider/multiplier
|
||||||
}
|
else {
|
||||||
|
int8_t divider = (dv.options_size == 1) ? Helpers::atoint(read_flash_string(dv.options[0]).c_str()) : 0;
|
||||||
|
char s[10];
|
||||||
|
if (divider > 0) {
|
||||||
|
obj["s"] = Helpers::render_value(s, (float)1 / divider, 1);
|
||||||
|
} else if (divider < 0) {
|
||||||
|
obj["s"] = Helpers::render_value(s, (-1) * divider, 0);
|
||||||
|
}
|
||||||
|
int16_t dv_set_min, dv_set_max;
|
||||||
|
if (dv.get_min_max(dv_set_min, dv_set_max)) {
|
||||||
|
obj["m"] = Helpers::render_value(s, dv_set_min, 0);
|
||||||
|
obj["x"] = Helpers::render_value(s, dv_set_max, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -838,19 +837,22 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
|
|||||||
obj["v"] = (divider > 0) ? time_value / divider : time_value * factor; // sometimes we need to divide by 60
|
obj["v"] = (divider > 0) ? time_value / divider : time_value * factor; // sometimes we need to divide by 60
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// must always have v for sorting to work in web
|
||||||
|
obj["v"] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// add name, prefixing the tag if it exists
|
// add name, prefixing the tag if it exists as the id (key for table sorting)
|
||||||
if (dv.full_name) {
|
if (dv.full_name) {
|
||||||
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
|
if ((dv.tag == DeviceValueTAG::TAG_NONE) || tag_to_string(dv.tag).empty()) {
|
||||||
obj["n"] = dv.full_name;
|
obj["id"] = dv.full_name;
|
||||||
} else {
|
} else {
|
||||||
char name[50];
|
char name[50];
|
||||||
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), read_flash_string(dv.full_name).c_str());
|
snprintf(name, sizeof(name), "%s %s", tag_to_string(dv.tag).c_str(), read_flash_string(dv.full_name).c_str());
|
||||||
obj["n"] = name;
|
obj["id"] = name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
obj["n"] = "";
|
obj["id"] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// shortname
|
// shortname
|
||||||
|
|||||||
@@ -432,12 +432,12 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
|||||||
(fahrenheit == 0) ? 'C' : 'F',
|
(fahrenheit == 0) ? 'C' : 'F',
|
||||||
COLOR_RESET,
|
COLOR_RESET,
|
||||||
Helpers::render_value(s2, sensor.offset(), 10, fahrenheit),
|
Helpers::render_value(s2, sensor.offset(), 10, fahrenheit),
|
||||||
sensor.id_str().c_str());
|
sensor.id().c_str());
|
||||||
} else {
|
} else {
|
||||||
shell.printfln(F(" %s (offset %s, ID: %s)"),
|
shell.printfln(F(" %s (offset %s, ID: %s)"),
|
||||||
sensor.name().c_str(),
|
sensor.name().c_str(),
|
||||||
Helpers::render_value(s, sensor.offset(), 10, fahrenheit),
|
Helpers::render_value(s, sensor.offset(), 10, fahrenheit),
|
||||||
sensor.id_str().c_str());
|
sensor.id().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shell.println();
|
shell.println();
|
||||||
|
|||||||
@@ -1036,7 +1036,7 @@ bool System::command_customizations(const char * value, const int8_t id, JsonObj
|
|||||||
JsonArray sensorsJson = node.createNestedArray("sensors");
|
JsonArray sensorsJson = node.createNestedArray("sensors");
|
||||||
for (const auto & sensor : settings.sensorCustomizations) {
|
for (const auto & sensor : settings.sensorCustomizations) {
|
||||||
JsonObject sensorJson = sensorsJson.createNestedObject();
|
JsonObject sensorJson = sensorsJson.createNestedObject();
|
||||||
sensorJson["id_str"] = sensor.id_str; // key, is
|
sensorJson["id"] = sensor.id; // key
|
||||||
sensorJson["name"] = sensor.name; // n
|
sensorJson["name"] = sensor.name; // n
|
||||||
sensorJson["offset"] = sensor.offset; // o
|
sensorJson["offset"] = sensor.offset; // o
|
||||||
}
|
}
|
||||||
@@ -1044,7 +1044,7 @@ bool System::command_customizations(const char * value, const int8_t id, JsonObj
|
|||||||
JsonArray analogJson = node.createNestedArray("analogs");
|
JsonArray analogJson = node.createNestedArray("analogs");
|
||||||
for (const AnalogCustomization & sensor : settings.analogCustomizations) {
|
for (const AnalogCustomization & sensor : settings.analogCustomizations) {
|
||||||
JsonObject sensorJson = analogJson.createNestedObject();
|
JsonObject sensorJson = analogJson.createNestedObject();
|
||||||
sensorJson["gpio"] = sensor.id;
|
sensorJson["gpio"] = sensor.gpio;
|
||||||
sensorJson["name"] = sensor.name;
|
sensorJson["name"] = sensor.name;
|
||||||
if (EMSESP::system_.enum_format() == ENUM_FORMAT_INDEX) {
|
if (EMSESP::system_.enum_format() == ENUM_FORMAT_INDEX) {
|
||||||
sensorJson["type"] = sensor.type;
|
sensorJson["type"] = sensor.type;
|
||||||
|
|||||||
@@ -550,6 +550,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
|
|
||||||
if (command == "dallas") {
|
if (command == "dallas") {
|
||||||
shell.printfln(F("Testing adding Dallas sensor"));
|
shell.printfln(F("Testing adding Dallas sensor"));
|
||||||
|
emsesp::EMSESP::dallassensor_.test();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == "dallas_full") {
|
||||||
|
shell.printfln(F("Testing adding and changing Dallas sensor"));
|
||||||
Mqtt::ha_enabled(true);
|
Mqtt::ha_enabled(true);
|
||||||
Mqtt::nested_format(1);
|
Mqtt::nested_format(1);
|
||||||
// Mqtt::nested_format(0);
|
// Mqtt::nested_format(0);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define EMSESP_APP_VERSION "3.4.0b12"
|
#define EMSESP_APP_VERSION "3.4.0b12t4"
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void WebCustomization::read(WebCustomization & settings, JsonObject & root) {
|
|||||||
JsonArray sensorsJson = root.createNestedArray("sensors");
|
JsonArray sensorsJson = root.createNestedArray("sensors");
|
||||||
for (const SensorCustomization & sensor : settings.sensorCustomizations) {
|
for (const SensorCustomization & sensor : settings.sensorCustomizations) {
|
||||||
JsonObject sensorJson = sensorsJson.createNestedObject();
|
JsonObject sensorJson = sensorsJson.createNestedObject();
|
||||||
sensorJson["id_str"] = sensor.id_str; // is
|
sensorJson["id"] = sensor.id; // is
|
||||||
sensorJson["name"] = sensor.name; // n
|
sensorJson["name"] = sensor.name; // n
|
||||||
sensorJson["offset"] = sensor.offset; // o
|
sensorJson["offset"] = sensor.offset; // o
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ void WebCustomization::read(WebCustomization & settings, JsonObject & root) {
|
|||||||
JsonArray analogJson = root.createNestedArray("analogs");
|
JsonArray analogJson = root.createNestedArray("analogs");
|
||||||
for (const AnalogCustomization & sensor : settings.analogCustomizations) {
|
for (const AnalogCustomization & sensor : settings.analogCustomizations) {
|
||||||
JsonObject sensorJson = analogJson.createNestedObject();
|
JsonObject sensorJson = analogJson.createNestedObject();
|
||||||
sensorJson["id"] = sensor.id; // i
|
sensorJson["gpio"] = sensor.gpio; // g
|
||||||
sensorJson["name"] = sensor.name; // n
|
sensorJson["name"] = sensor.name; // n
|
||||||
sensorJson["offset"] = sensor.offset; // o
|
sensorJson["offset"] = sensor.offset; // o
|
||||||
sensorJson["factor"] = sensor.factor; // f
|
sensorJson["factor"] = sensor.factor; // f
|
||||||
@@ -101,7 +101,7 @@ StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization &
|
|||||||
for (const JsonObject sensorJson : root["sensors"].as<JsonArray>()) {
|
for (const JsonObject sensorJson : root["sensors"].as<JsonArray>()) {
|
||||||
// create each of the sensor, overwritting any previous settings
|
// create each of the sensor, overwritting any previous settings
|
||||||
auto sensor = SensorCustomization();
|
auto sensor = SensorCustomization();
|
||||||
sensor.id_str = sensorJson["id_str"].as<std::string>();
|
sensor.id = sensorJson["id"].as<std::string>();
|
||||||
sensor.name = sensorJson["name"].as<std::string>();
|
sensor.name = sensorJson["name"].as<std::string>();
|
||||||
sensor.offset = sensorJson["offset"];
|
sensor.offset = sensorJson["offset"];
|
||||||
settings.sensorCustomizations.push_back(sensor); // add to list
|
settings.sensorCustomizations.push_back(sensor); // add to list
|
||||||
@@ -114,7 +114,7 @@ StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization &
|
|||||||
for (const JsonObject analogJson : root["analogs"].as<JsonArray>()) {
|
for (const JsonObject analogJson : root["analogs"].as<JsonArray>()) {
|
||||||
// create each of the sensor, overwritting any previous settings
|
// create each of the sensor, overwritting any previous settings
|
||||||
auto sensor = AnalogCustomization();
|
auto sensor = AnalogCustomization();
|
||||||
sensor.id = analogJson["id"];
|
sensor.gpio = analogJson["gpio"];
|
||||||
sensor.name = analogJson["name"].as<std::string>();
|
sensor.name = analogJson["name"].as<std::string>();
|
||||||
sensor.offset = analogJson["offset"];
|
sensor.offset = analogJson["offset"];
|
||||||
sensor.factor = analogJson["factor"];
|
sensor.factor = analogJson["factor"];
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ namespace emsesp {
|
|||||||
// Customization for dallas sensor
|
// Customization for dallas sensor
|
||||||
class SensorCustomization {
|
class SensorCustomization {
|
||||||
public:
|
public:
|
||||||
std::string id_str;
|
std::string id;
|
||||||
std::string name;
|
std::string name;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnalogCustomization {
|
class AnalogCustomization {
|
||||||
public:
|
public:
|
||||||
uint8_t id;
|
uint8_t gpio;
|
||||||
std::string name;
|
std::string name;
|
||||||
float offset;
|
float offset;
|
||||||
float factor;
|
float factor;
|
||||||
@@ -51,7 +51,7 @@ class AnalogCustomization {
|
|||||||
|
|
||||||
// used for removing from a list
|
// used for removing from a list
|
||||||
bool operator==(const AnalogCustomization & a) const {
|
bool operator==(const AnalogCustomization & a) const {
|
||||||
return id == a.id;
|
return gpio == a.gpio;
|
||||||
}
|
}
|
||||||
bool operator!=(const AnalogCustomization & a) const {
|
bool operator!=(const AnalogCustomization & a) const {
|
||||||
return !operator==(a);
|
return !operator==(a);
|
||||||
|
|||||||
@@ -76,17 +76,18 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
|
|||||||
// list is already sorted by device type
|
// list is already sorted by device type
|
||||||
// Ignore Contoller
|
// Ignore Contoller
|
||||||
JsonArray devices = root.createNestedArray("devices");
|
JsonArray devices = root.createNestedArray("devices");
|
||||||
|
char buffer[3];
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice && (emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER || emsdevice->count_entities() > 0)) {
|
if (emsdevice && (emsdevice->device_type() != EMSdevice::DeviceType::CONTROLLER || emsdevice->count_entities() > 0)) {
|
||||||
JsonObject obj = devices.createNestedObject();
|
JsonObject obj = devices.createNestedObject();
|
||||||
obj["i"] = emsdevice->unique_id(); // a unique id
|
obj["id"] = Helpers::smallitoa(buffer, emsdevice->unique_id()); // a unique id as a string
|
||||||
obj["t"] = emsdevice->device_type_name(); // type
|
obj["t"] = emsdevice->device_type_name(); // type
|
||||||
obj["b"] = emsdevice->brand_to_string(); // brand
|
obj["b"] = emsdevice->brand_to_string(); // brand
|
||||||
obj["n"] = emsdevice->name(); // name
|
obj["n"] = emsdevice->name(); // name
|
||||||
obj["d"] = emsdevice->device_id(); // deviceid
|
obj["d"] = emsdevice->device_id(); // deviceid
|
||||||
obj["p"] = emsdevice->product_id(); // productid
|
obj["p"] = emsdevice->product_id(); // productid
|
||||||
obj["v"] = emsdevice->version(); // version
|
obj["v"] = emsdevice->version(); // version
|
||||||
obj["e"] = emsdevice->count_entities(); // number of entities (device values)
|
obj["e"] = emsdevice->count_entities(); // number of entities (device values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +111,8 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
|||||||
if (EMSESP::dallassensor_.have_sensors()) {
|
if (EMSESP::dallassensor_.have_sensors()) {
|
||||||
for (const auto & sensor : EMSESP::dallassensor_.sensors()) {
|
for (const auto & sensor : EMSESP::dallassensor_.sensors()) {
|
||||||
JsonObject obj = sensors.createNestedObject();
|
JsonObject obj = sensors.createNestedObject();
|
||||||
obj["is"] = sensor.id_str(); // id
|
obj["id"] = sensor.id(); // id as string
|
||||||
obj["n"] = sensor.name(); // name
|
obj["n"] = sensor.name(); // name
|
||||||
if (EMSESP::system_.fahrenheit()) {
|
if (EMSESP::system_.fahrenheit()) {
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
obj["t"] = (float)sensor.temperature_c * 0.18 + 32;
|
obj["t"] = (float)sensor.temperature_c * 0.18 + 32;
|
||||||
@@ -129,14 +130,16 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// analog sensors
|
// analog sensors
|
||||||
// assume list is already sorted by id
|
|
||||||
JsonArray analogs = root.createNestedArray("analogs");
|
JsonArray analogs = root.createNestedArray("analogs");
|
||||||
if (EMSESP::analog_enabled() && EMSESP::analogsensor_.have_sensors()) {
|
if (EMSESP::analog_enabled() && EMSESP::analogsensor_.have_sensors()) {
|
||||||
|
uint8_t count = 0;
|
||||||
|
char buffer[3];
|
||||||
for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
|
for (const auto & sensor : EMSESP::analogsensor_.sensors()) {
|
||||||
// don't send if it's marked for removal
|
// don't send if it's marked for removal
|
||||||
if (sensor.type() != AnalogSensor::AnalogType::MARK_DELETED) {
|
if (sensor.type() != AnalogSensor::AnalogType::MARK_DELETED) {
|
||||||
JsonObject obj = analogs.createNestedObject();
|
JsonObject obj = analogs.createNestedObject();
|
||||||
obj["i"] = sensor.id();
|
obj["id"] = Helpers::smallitoa(buffer, ++count); // needed for sorting table
|
||||||
|
obj["g"] = sensor.gpio();
|
||||||
obj["n"] = sensor.name();
|
obj["n"] = sensor.name();
|
||||||
obj["u"] = sensor.uom();
|
obj["u"] = sensor.uom();
|
||||||
obj["o"] = sensor.offset();
|
obj["o"] = sensor.offset();
|
||||||
@@ -145,6 +148,8 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
|
|||||||
|
|
||||||
if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) {
|
if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) {
|
||||||
obj["v"] = Helpers::round2(sensor.value(), 0); // is optional and is a float
|
obj["v"] = Helpers::round2(sensor.value(), 0); // is optional and is a float
|
||||||
|
} else {
|
||||||
|
obj["v"] = 0; // must have a value for web sorting to work
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +175,13 @@ void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant &
|
|||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
emsdevice->generate_values_web(output);
|
emsdevice->generate_values_web(output);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// #ifdef EMSESP_USE_SERIAL
|
||||||
|
// #ifdef EMSESP_DEBUG
|
||||||
|
// serializeJson(output, Serial);
|
||||||
|
// #endif
|
||||||
|
// #endif
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@@ -246,8 +258,8 @@ void WebDataService::write_sensor(AsyncWebServerRequest * request, JsonVariant &
|
|||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
JsonObject sensor = json;
|
JsonObject sensor = json;
|
||||||
|
|
||||||
std::string id_str = sensor["id_str"]; // this is the key
|
std::string id = sensor["id"]; // this is the key
|
||||||
std::string name = sensor["name"];
|
std::string name = sensor["name"];
|
||||||
|
|
||||||
// calculate offset. We'll convert it to an int and * 10
|
// calculate offset. We'll convert it to an int and * 10
|
||||||
float offset = sensor["offset"];
|
float offset = sensor["offset"];
|
||||||
@@ -255,7 +267,7 @@ void WebDataService::write_sensor(AsyncWebServerRequest * request, JsonVariant &
|
|||||||
if (EMSESP::system_.fahrenheit()) {
|
if (EMSESP::system_.fahrenheit()) {
|
||||||
offset10 = offset / 0.18;
|
offset10 = offset / 0.18;
|
||||||
}
|
}
|
||||||
ok = EMSESP::dallassensor_.update(id_str, name, offset10);
|
ok = EMSESP::dallassensor_.update(id, name, offset10);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 204);
|
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 204);
|
||||||
@@ -268,13 +280,13 @@ void WebDataService::write_analog(AsyncWebServerRequest * request, JsonVariant &
|
|||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
JsonObject analog = json;
|
JsonObject analog = json;
|
||||||
|
|
||||||
uint8_t id = analog["id"]; // this is the unique key
|
uint8_t gpio = analog["gpio"]; // this is the unique key, the GPIO
|
||||||
std::string name = analog["name"];
|
std::string name = analog["name"];
|
||||||
float factor = analog["factor"];
|
float factor = analog["factor"];
|
||||||
float offset = analog["offset"];
|
float offset = analog["offset"];
|
||||||
uint8_t uom = analog["uom"];
|
uint8_t uom = analog["uom"];
|
||||||
int8_t type = analog["type"];
|
int8_t type = analog["type"];
|
||||||
ok = EMSESP::analogsensor_.update(id, name, offset, factor, uom, type);
|
ok = EMSESP::analogsensor_.update(gpio, name, offset, factor, uom, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 204);
|
AsyncWebServerResponse * response = request->beginResponse(ok ? 200 : 204);
|
||||||
|
|||||||
@@ -129,34 +129,57 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
|
|||||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_MEDIUM_DYN);
|
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_MEDIUM_DYN);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
|
|
||||||
root["status"] = EMSESP::bus_status(); // 0, 1 or 2
|
root["status"] = EMSESP::bus_status(); // 0, 1 or 2
|
||||||
root["num_devices"] = EMSESP::count_devices(); // excluding Controller
|
root["tx_mode"] = EMSESP::txservice_.tx_mode();
|
||||||
root["num_sensors"] = EMSESP::dallassensor_.no_sensors();
|
root["uptime"] = EMSbus::bus_uptime();
|
||||||
root["num_analogs"] = EMSESP::analogsensor_.no_sensors();
|
root["num_devices"] = EMSESP::count_devices(); // excluding Controller
|
||||||
root["tx_mode"] = EMSESP::txservice_.tx_mode();
|
root["num_sensors"] = EMSESP::dallassensor_.no_sensors();
|
||||||
root["rx_received"] = EMSESP::rxservice_.telegram_count();
|
root["num_analogs"] = EMSESP::analogsensor_.no_sensors();
|
||||||
root["tx_reads"] = EMSESP::txservice_.telegram_read_count();
|
|
||||||
root["tx_writes"] = EMSESP::txservice_.telegram_write_count();
|
JsonArray statsJson = root.createNestedArray("stats");
|
||||||
root["rx_quality"] = EMSESP::rxservice_.quality();
|
JsonObject statJson;
|
||||||
root["tx_read_quality"] = EMSESP::txservice_.read_quality();
|
|
||||||
root["tx_write_quality"] = EMSESP::txservice_.write_quality();
|
statJson = statsJson.createNestedObject();
|
||||||
root["rx_fails"] = EMSESP::rxservice_.telegram_error_count();
|
statJson["id"] = "EMS Telegrams Received (Rx)";
|
||||||
root["tx_read_fails"] = EMSESP::txservice_.telegram_read_fail_count();
|
statJson["s"] = EMSESP::rxservice_.telegram_count();
|
||||||
root["tx_write_fails"] = EMSESP::txservice_.telegram_write_fail_count();
|
statJson["f"] = EMSESP::rxservice_.telegram_error_count();
|
||||||
root["sensor_fails"] = EMSESP::dallassensor_.fails();
|
statJson["q"] = EMSESP::rxservice_.quality();
|
||||||
root["sensor_reads"] = EMSESP::dallassensor_.reads();
|
|
||||||
root["sensor_quality"] = EMSESP::dallassensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::dallassensor_.fails()) / EMSESP::dallassensor_.reads());
|
statJson = statsJson.createNestedObject();
|
||||||
root["analog_fails"] = EMSESP::analogsensor_.fails();
|
statJson["id"] = "EMS Reads (Tx)";
|
||||||
root["analog_reads"] = EMSESP::analogsensor_.reads();
|
statJson["s"] = EMSESP::txservice_.telegram_read_count();
|
||||||
root["analog_quality"] = EMSESP::analogsensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::analogsensor_.fails()) / EMSESP::analogsensor_.reads());
|
statJson["f"] = EMSESP::txservice_.telegram_read_fail_count();
|
||||||
root["mqtt_fails"] = Mqtt::publish_fails();
|
statJson["q"] = EMSESP::txservice_.read_quality();
|
||||||
root["mqtt_count"] = Mqtt::publish_count();
|
|
||||||
root["mqtt_quality"] = Mqtt::publish_count() == 0 ? 100 : 100 - (Mqtt::publish_fails() * 100) / (Mqtt::publish_count() + Mqtt::publish_fails());
|
statJson = statsJson.createNestedObject();
|
||||||
root["api_calls"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
|
statJson["id"] = "EMS Writes (Tx)";
|
||||||
root["api_fails"] = WebAPIService::api_fails();
|
statJson["s"] = EMSESP::txservice_.telegram_write_count();
|
||||||
root["api_quality"] =
|
statJson["f"] = EMSESP::txservice_.telegram_write_fail_count();
|
||||||
WebAPIService::api_count() == 0 ? 100 : 100 - (WebAPIService::api_fails() * 100) / (WebAPIService::api_count() + WebAPIService::api_fails());
|
statJson["q"] = EMSESP::txservice_.write_quality();
|
||||||
root["uptime"] = EMSbus::bus_uptime();
|
|
||||||
|
statJson = statsJson.createNestedObject();
|
||||||
|
statJson["id"] = "Temperature Sensor Reads";
|
||||||
|
statJson["s"] = EMSESP::dallassensor_.reads();
|
||||||
|
statJson["f"] = EMSESP::dallassensor_.fails();
|
||||||
|
statJson["q"] = EMSESP::dallassensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::dallassensor_.fails()) / EMSESP::dallassensor_.reads());
|
||||||
|
|
||||||
|
statJson = statsJson.createNestedObject();
|
||||||
|
statJson["id"] = "Analog Sensor Reads";
|
||||||
|
statJson["s"] = EMSESP::analogsensor_.reads();
|
||||||
|
statJson["f"] = EMSESP::analogsensor_.fails();
|
||||||
|
statJson["q"] = EMSESP::analogsensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::analogsensor_.fails()) / EMSESP::analogsensor_.reads());
|
||||||
|
|
||||||
|
statJson = statsJson.createNestedObject();
|
||||||
|
statJson["id"] = "MQTT Publishes";
|
||||||
|
statJson["s"] = Mqtt::publish_count();
|
||||||
|
statJson["f"] = Mqtt::publish_fails();
|
||||||
|
statJson["q"] = Mqtt::publish_count() == 0 ? 100 : 100 - (Mqtt::publish_fails() * 100) / (Mqtt::publish_count() + Mqtt::publish_fails());
|
||||||
|
|
||||||
|
statJson = statsJson.createNestedObject();
|
||||||
|
statJson["id"] = "API Calls";
|
||||||
|
statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
|
||||||
|
statJson["f"] = WebAPIService::api_fails();
|
||||||
|
statJson["q"] = WebAPIService::api_count() == 0 ? 100 : 100 - (WebAPIService::api_fails() * 100) / (WebAPIService::api_count() + WebAPIService::api_fails());
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user